@progress/kendo-react-data-tools 17.1.0-develop.6 → 17.1.0-develop.7
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/clipboard/common.d.ts +17 -3
- package/clipboard/common.js +7 -6
- package/clipboard/common.mjs +97 -80
- package/data-source/use-odata-data-source.js +1 -1
- package/data-source/use-odata-data-source.mjs +22 -17
- package/data-source/use-remote-data-source.js +1 -1
- package/data-source/use-remote-data-source.mjs +89 -89
- package/dist/cdn/js/kendo-react-datatools.js +1 -1
- package/package-metadata.js +1 -1
- package/package-metadata.mjs +2 -2
- package/package.json +10 -10
package/clipboard/common.d.ts
CHANGED
|
@@ -47,6 +47,11 @@ export interface ClipboardDataEvent {
|
|
|
47
47
|
* Sets the row delimiter used when manipulating the clipboard data Defaults to `\r\n`.
|
|
48
48
|
*/
|
|
49
49
|
newLineDelimiter?: string;
|
|
50
|
+
/**
|
|
51
|
+
* Prefixes copied values starting with `=`, `+`, `-`, `@`, tab, or carriage return
|
|
52
|
+
* with an apostrophe to prevent spreadsheet formula injection. Defaults to `true`.
|
|
53
|
+
*/
|
|
54
|
+
preventFormulaInjection?: boolean;
|
|
50
55
|
/**
|
|
51
56
|
* This is the item that is clicked if the action is raised from the contextMenu.
|
|
52
57
|
*/
|
|
@@ -89,6 +94,10 @@ export interface PopulateClipboardArgs {
|
|
|
89
94
|
* Previous copied items.
|
|
90
95
|
*/
|
|
91
96
|
previousCopiedItems?: ClipboardItem[];
|
|
97
|
+
/**
|
|
98
|
+
* Clipboard text generated for the previous copied items.
|
|
99
|
+
*/
|
|
100
|
+
previousCopiedText?: string;
|
|
92
101
|
}
|
|
93
102
|
/**
|
|
94
103
|
* Represents the object that is returned form the `populateClipboardData` function.
|
|
@@ -141,6 +150,11 @@ export interface ClipboardSettings {
|
|
|
141
150
|
* Defaults to `'\r\n'`.
|
|
142
151
|
*/
|
|
143
152
|
newLineDelimiter?: string;
|
|
153
|
+
/**
|
|
154
|
+
* Prefixes copied values starting with `=`, `+`, `-`, `@`, tab, or carriage return
|
|
155
|
+
* with an apostrophe to prevent spreadsheet formula injection. Defaults to `true`.
|
|
156
|
+
*/
|
|
157
|
+
preventFormulaInjection?: boolean;
|
|
144
158
|
}
|
|
145
159
|
/**
|
|
146
160
|
* @hidden
|
|
@@ -149,7 +163,7 @@ export declare const getItemsToUpdateOnPaste: (args: PopulateClipboardArgs, sele
|
|
|
149
163
|
/**
|
|
150
164
|
* @hidden
|
|
151
165
|
*/
|
|
152
|
-
export declare const getPreviouslyCopiedItemsData: (previousCopiedItems?: ClipboardItem[]) =>
|
|
166
|
+
export declare const getPreviouslyCopiedItemsData: (previousCopiedItems?: ClipboardItem[]) => string[][];
|
|
153
167
|
/**
|
|
154
168
|
* @hidden
|
|
155
169
|
*/
|
|
@@ -157,7 +171,7 @@ export declare const getClipboardItemsToPaste: (args: PopulateClipboardArgs, cli
|
|
|
157
171
|
/**
|
|
158
172
|
* @hidden
|
|
159
173
|
*/
|
|
160
|
-
export declare const getItemsToPaste: (args: PopulateClipboardArgs, clipboardText: string) =>
|
|
174
|
+
export declare const getItemsToPaste: (args: PopulateClipboardArgs, clipboardText: string) => string[][];
|
|
161
175
|
/**
|
|
162
176
|
* @hidden
|
|
163
177
|
*/
|
|
@@ -165,7 +179,7 @@ export declare const getPastedItems: (args: PopulateClipboardArgs, clipboardText
|
|
|
165
179
|
/**
|
|
166
180
|
* @hidden
|
|
167
181
|
*/
|
|
168
|
-
export declare const itemToString: (item: any, cols: string[]) => string | null;
|
|
182
|
+
export declare const itemToString: (item: any, cols: string[], event?: Pick<ClipboardDataEvent, 'cellDelimiter' | 'newLineDelimiter' | 'preventFormulaInjection'>) => string | null;
|
|
169
183
|
/**
|
|
170
184
|
* @hidden
|
|
171
185
|
*/
|
package/clipboard/common.js
CHANGED
|
@@ -5,9 +5,10 @@
|
|
|
5
5
|
* Licensed under commercial license. See LICENSE.md in the package root for more information
|
|
6
6
|
*-------------------------------------------------------------------------------------------
|
|
7
7
|
*/
|
|
8
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
8
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const D=require("@progress/kendo-react-common");var T=(t=>(t.copy="copy",t.cut="cut",t.paste="paste",t))(T||{});const b=(t,e,n,s)=>{const i=D.getter(s),c=t.data.findIndex(r=>i(r)===i(e[0].dataItem))||0,a=e.length<2?n:e.length;return t.data.filter((r,d)=>d>=c&&d<c+a)||[]},w=t=>(t==null?void 0:t.map(n=>n.fields.map(s=>String(n.dataItem[s]))))||[],x=(t,e)=>{var p,u;const{event:n}=t,s=(p=n.cellDelimiter)!=null?p:" ",i=(u=n.newLineDelimiter)!=null?u:`\r
|
|
9
|
+
`,c=[];let a=[],l="",r=!1,d=!0;for(let o=0;o<e.length;o++){const m=e[o];if(r)m==='"'&&e[o+1]==='"'?(l+='"',o++):m==='"'?r=!1:l+=m;else if(m==='"'&&d)r=!0,d=!1;else if(s&&e.startsWith(s,o))a.push(l),l="",d=!0,o+=s.length-1;else{const f=i&&e.startsWith(i,o)?i:m===`
|
|
10
|
+
`?`
|
|
11
|
+
`:null;f?(a.push(l),c.push(a),a=[],l="",d=!0,o+=f.length-1):(l+=m,d=!1)}}return a.push(l),c.push(a),c},S=(t,e)=>{var n,s,i;return((n=t.event.nativeEvent)==null?void 0:n.type)==="paste"&&(!((s=t.previousCopiedItems)!=null&&s.length)||t.previousCopiedText===void 0||((i=t.event.nativeEvent.clipboardData)==null?void 0:i.getData("text"))!==t.previousCopiedText)?x(t,e):w(t.previousCopiedItems)},L=(t,e)=>{var m,f,C;const{event:n}=t,s=n.dataItem,i=(f=(m=t.dataItemKey)!=null?m:n.dataItemKey)!=null?f:"",c=D.getter(i),a=s&&!s.selected&&n.field?[{dataItem:n.dataItem,fields:[n.field]}]:h(t),l=a.length?a[0].fields[0]:(C=n.columns[0].field)!=null?C:"",r=n.columns.map(I=>{var g;return(g=I.field)!=null?g:""}),d=r.indexOf(l),p=S(t,e),u=b(t,a,p.length,i);return p.slice(0,u.length).map((I,g)=>{const $=d+I.length,y=r.slice(d,$),P={[i]:c(u[g])};return y.forEach((G,H)=>P[G]=I[H]),{dataItem:P,fields:y}})},j=(t,e)=>{var c,a;const n=(c=e==null?void 0:e.cellDelimiter)!=null?c:" ",s=(a=e==null?void 0:e.newLineDelimiter)!=null?a:`\r
|
|
12
|
+
`,i=(e==null?void 0:e.preventFormulaInjection)!==!1&&/^[=+\-@\t\r]/.test(t)?`'${t}`:t;return n&&i.includes(n)||s&&i.includes(s)||/[\r\n"]/.test(i)?`"${i.replace(/"/g,'""')}"`:i},E=(t,e,n)=>{var s;return e.length?e.map(i=>j(String(t[i]),n)).join((s=n==null?void 0:n.cellDelimiter)!=null?s:" "):null},F=(t,e,n)=>{var a,l;const s=(a=n.cellDelimiter)!=null?a:" ",i=(l=n.newLineDelimiter)!=null?l:`\r
|
|
13
|
+
`;return`${e.map(r=>j(r,n)).join(s)}${i}${t}`},h=t=>{var r,d;const{event:e,selectedState:n,data:s}=t,i=(d=(r=t.dataItemKey)!=null?r:e.dataItemKey)!=null?d:"",c=D.getter(i),a={},l=[];return Object.entries(n).forEach(([p,u])=>{a[p]=D.isArray(u)?u.map(o=>e.columns[o]).filter(o=>!o.declarationIndex||o.declarationIndex>=0):e.columns.filter(o=>!o.declarationIndex||o.declarationIndex>=0)}),s==null||s.map(p=>{const u=c(p)||"";return a[u]&&l.push({dataItem:p,fields:a[u].map(o=>{var m;return(m=o.field)!=null?m:""})}),p}),l},K=(t,e)=>{var i,c;const n=(i=e.newLineDelimiter)!=null?i:`\r
|
|
14
|
+
`,s=t.map((a,l)=>{var d;let r=(d=E(a.dataItem,a.fields,e))!=null?d:"";return e.copyHeaders&&l===0&&(r=F(r,a.fields,e)),r?[r]:[]}).join(n);return(c=navigator.clipboard)==null||c.writeText(s),s},O=(t,e)=>{let n="";if(t.type==="paste"){const s=t.nativeEvent?t.nativeEvent.clipboardData:"";n=s?s.getData("text").trim():""}else n=K(e,t);return n},R=t=>{const{event:e}=t,n=h(t)||[],s=O(e,n)||"",i=e.type==="paste"?L(t,s)||[]:[];return{copiedItems:n,pastedItems:i,clipboardData:s}};exports.ClipboardActionType=T;exports.addHeaders=F;exports.getClipboardData=O;exports.getClipboardItemsToPaste=x;exports.getClipboardText=K;exports.getItemsToPaste=S;exports.getItemsToUpdateOnPaste=b;exports.getPastedItems=L;exports.getPreviouslyCopiedItemsData=w;exports.getSelectedItems=h;exports.itemToString=E;exports.populateClipboardData=R;
|
package/clipboard/common.mjs
CHANGED
|
@@ -5,95 +5,112 @@
|
|
|
5
5
|
* Licensed under commercial license. See LICENSE.md in the package root for more information
|
|
6
6
|
*-------------------------------------------------------------------------------------------
|
|
7
7
|
*/
|
|
8
|
-
import { getter as
|
|
9
|
-
var
|
|
10
|
-
const E = (t,
|
|
11
|
-
const
|
|
12
|
-
return t.data.filter((
|
|
13
|
-
},
|
|
14
|
-
var
|
|
15
|
-
const { event:
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
8
|
+
import { getter as h, isArray as T } from "@progress/kendo-react-common";
|
|
9
|
+
var b = /* @__PURE__ */ ((t) => (t.copy = "copy", t.cut = "cut", t.paste = "paste", t))(b || {});
|
|
10
|
+
const E = (t, e, n, s) => {
|
|
11
|
+
const i = h(s), c = t.data.findIndex((r) => i(r) === i(e[0].dataItem)) || 0, l = e.length < 2 ? n : e.length;
|
|
12
|
+
return t.data.filter((r, d) => d >= c && d < c + l) || [];
|
|
13
|
+
}, F = (t) => (t == null ? void 0 : t.map((n) => n.fields.map((s) => String(n.dataItem[s])))) || [], K = (t, e) => {
|
|
14
|
+
var p, u;
|
|
15
|
+
const { event: n } = t, s = (p = n.cellDelimiter) != null ? p : " ", i = (u = n.newLineDelimiter) != null ? u : `\r
|
|
16
|
+
`, c = [];
|
|
17
|
+
let l = [], o = "", r = !1, d = !0;
|
|
18
|
+
for (let a = 0; a < e.length; a++) {
|
|
19
|
+
const m = e[a];
|
|
20
|
+
if (r)
|
|
21
|
+
m === '"' && e[a + 1] === '"' ? (o += '"', a++) : m === '"' ? r = !1 : o += m;
|
|
22
|
+
else if (m === '"' && d)
|
|
23
|
+
r = !0, d = !1;
|
|
24
|
+
else if (s && e.startsWith(s, a))
|
|
25
|
+
l.push(o), o = "", d = !0, a += s.length - 1;
|
|
26
|
+
else {
|
|
27
|
+
const f = i && e.startsWith(i, a) ? i : m === `
|
|
28
|
+
` ? `
|
|
29
|
+
` : null;
|
|
30
|
+
f ? (l.push(o), c.push(l), l = [], o = "", d = !0, a += f.length - 1) : (o += m, d = !1);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
return l.push(o), c.push(l), c;
|
|
34
|
+
}, j = (t, e) => {
|
|
35
|
+
var n, s, i;
|
|
36
|
+
return ((n = t.event.nativeEvent) == null ? void 0 : n.type) === "paste" && (!((s = t.previousCopiedItems) != null && s.length) || t.previousCopiedText === void 0 || ((i = t.event.nativeEvent.clipboardData) == null ? void 0 : i.getData("text")) !== t.previousCopiedText) ? K(t, e) : F(t.previousCopiedItems);
|
|
37
|
+
}, $ = (t, e) => {
|
|
38
|
+
var m, f, g;
|
|
39
|
+
const { event: n } = t, s = n.dataItem, i = (f = (m = t.dataItemKey) != null ? m : n.dataItemKey) != null ? f : "", c = h(i), l = s && !s.selected && n.field ? [{ dataItem: n.dataItem, fields: [n.field] }] : C(t), o = l.length ? l[0].fields[0] : (g = n.columns[0].field) != null ? g : "", r = n.columns.map((I) => {
|
|
40
|
+
var D;
|
|
41
|
+
return (D = I.field) != null ? D : "";
|
|
42
|
+
}), d = r.indexOf(o), p = j(t, e), u = E(t, l, p.length, i);
|
|
43
|
+
return p.slice(0, u.length).map((I, D) => {
|
|
44
|
+
const S = d + I.length, w = r.slice(d, S), x = { [i]: c(u[D]) };
|
|
45
|
+
return w.forEach((L, P) => x[L] = I[P]), {
|
|
46
|
+
dataItem: x,
|
|
47
|
+
fields: w
|
|
34
48
|
};
|
|
35
49
|
});
|
|
36
|
-
},
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
return n.
|
|
41
|
-
}, O = (t,
|
|
42
|
-
var
|
|
43
|
-
|
|
50
|
+
}, y = (t, e) => {
|
|
51
|
+
var c, l;
|
|
52
|
+
const n = (c = e == null ? void 0 : e.cellDelimiter) != null ? c : " ", s = (l = e == null ? void 0 : e.newLineDelimiter) != null ? l : `\r
|
|
53
|
+
`, i = (e == null ? void 0 : e.preventFormulaInjection) !== !1 && /^[=+\-@\t\r]/.test(t) ? `'${t}` : t;
|
|
54
|
+
return n && i.includes(n) || s && i.includes(s) || /[\r\n"]/.test(i) ? `"${i.replace(/"/g, '""')}"` : i;
|
|
55
|
+
}, O = (t, e, n) => {
|
|
56
|
+
var s;
|
|
57
|
+
return e.length ? e.map((i) => y(String(t[i]), n)).join((s = n == null ? void 0 : n.cellDelimiter) != null ? s : " ") : null;
|
|
58
|
+
}, G = (t, e, n) => {
|
|
59
|
+
var l, o;
|
|
60
|
+
const s = (l = n.cellDelimiter) != null ? l : " ", i = (o = n.newLineDelimiter) != null ? o : `\r
|
|
44
61
|
`;
|
|
45
|
-
return `${n.join(
|
|
46
|
-
},
|
|
47
|
-
var
|
|
48
|
-
const { event:
|
|
49
|
-
return Object.entries(
|
|
50
|
-
|
|
51
|
-
}),
|
|
52
|
-
const
|
|
53
|
-
return
|
|
54
|
-
dataItem:
|
|
55
|
-
fields:
|
|
56
|
-
var
|
|
57
|
-
return (
|
|
62
|
+
return `${e.map((r) => y(r, n)).join(s)}${i}${t}`;
|
|
63
|
+
}, C = (t) => {
|
|
64
|
+
var r, d;
|
|
65
|
+
const { event: e, selectedState: n, data: s } = t, i = (d = (r = t.dataItemKey) != null ? r : e.dataItemKey) != null ? d : "", c = h(i), l = {}, o = [];
|
|
66
|
+
return Object.entries(n).forEach(([p, u]) => {
|
|
67
|
+
l[p] = T(u) ? u.map((a) => e.columns[a]).filter((a) => !a.declarationIndex || a.declarationIndex >= 0) : e.columns.filter((a) => !a.declarationIndex || a.declarationIndex >= 0);
|
|
68
|
+
}), s == null || s.map((p) => {
|
|
69
|
+
const u = c(p) || "";
|
|
70
|
+
return l[u] && o.push({
|
|
71
|
+
dataItem: p,
|
|
72
|
+
fields: l[u].map((a) => {
|
|
73
|
+
var m;
|
|
74
|
+
return (m = a.field) != null ? m : "";
|
|
58
75
|
})
|
|
59
|
-
}),
|
|
60
|
-
}),
|
|
61
|
-
},
|
|
62
|
-
var
|
|
63
|
-
const
|
|
64
|
-
`,
|
|
65
|
-
var
|
|
66
|
-
let
|
|
67
|
-
return
|
|
68
|
-
}).join(
|
|
69
|
-
return (c = navigator.clipboard) == null || c.writeText(
|
|
70
|
-
},
|
|
71
|
-
let
|
|
76
|
+
}), p;
|
|
77
|
+
}), o;
|
|
78
|
+
}, H = (t, e) => {
|
|
79
|
+
var i, c;
|
|
80
|
+
const n = (i = e.newLineDelimiter) != null ? i : `\r
|
|
81
|
+
`, s = t.map((l, o) => {
|
|
82
|
+
var d;
|
|
83
|
+
let r = (d = O(l.dataItem, l.fields, e)) != null ? d : "";
|
|
84
|
+
return e.copyHeaders && o === 0 && (r = G(r, l.fields, e)), r ? [r] : [];
|
|
85
|
+
}).join(n);
|
|
86
|
+
return (c = navigator.clipboard) == null || c.writeText(s), s;
|
|
87
|
+
}, R = (t, e) => {
|
|
88
|
+
let n = "";
|
|
72
89
|
if (t.type === "paste") {
|
|
73
|
-
const
|
|
74
|
-
|
|
90
|
+
const s = t.nativeEvent ? t.nativeEvent.clipboardData : "";
|
|
91
|
+
n = s ? s.getData("text").trim() : "";
|
|
75
92
|
} else
|
|
76
|
-
|
|
77
|
-
return
|
|
78
|
-
},
|
|
79
|
-
const { event:
|
|
93
|
+
n = H(e, t);
|
|
94
|
+
return n;
|
|
95
|
+
}, W = (t) => {
|
|
96
|
+
const { event: e } = t, n = C(t) || [], s = R(e, n) || "", i = e.type === "paste" ? $(t, s) || [] : [];
|
|
80
97
|
return {
|
|
81
|
-
copiedItems:
|
|
82
|
-
pastedItems:
|
|
83
|
-
clipboardData:
|
|
98
|
+
copiedItems: n,
|
|
99
|
+
pastedItems: i,
|
|
100
|
+
clipboardData: s
|
|
84
101
|
};
|
|
85
102
|
};
|
|
86
103
|
export {
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
104
|
+
b as ClipboardActionType,
|
|
105
|
+
G as addHeaders,
|
|
106
|
+
R as getClipboardData,
|
|
107
|
+
K as getClipboardItemsToPaste,
|
|
108
|
+
H as getClipboardText,
|
|
109
|
+
j as getItemsToPaste,
|
|
93
110
|
E as getItemsToUpdateOnPaste,
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
111
|
+
$ as getPastedItems,
|
|
112
|
+
F as getPreviouslyCopiedItemsData,
|
|
113
|
+
C as getSelectedItems,
|
|
114
|
+
O as itemToString,
|
|
115
|
+
W as populateClipboardData
|
|
99
116
|
};
|
|
@@ -6,4 +6,4 @@
|
|
|
6
6
|
*-------------------------------------------------------------------------------------------
|
|
7
7
|
*/
|
|
8
8
|
"use client";
|
|
9
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
9
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const s=require("./use-remote-data-source.js"),r=require("@progress/kendo-react-common"),c=require("@progress/kendo-data-query"),u=require("../package-metadata.js"),n=e=>e.forEach(t=>{if(t.filters)n(t.filters);else if(!/^[A-Za-z_]\w*(?:[./][A-Za-z_]\w*)*$/.test(t.field))throw new Error(`Invalid OData field: ${t.field}`)}),i={create:{contentType:"application/json",method:"POST"},read:{parameterMap:e=>(n([...e.sort||[],...e.group||[],...e.filter?[e.filter]:[]]),`$count=true&$format=json&${c.toODataString(e)}`),method:"GET"},update:{contentType:"application/json",method:"PUT"},delete:{method:"DELETE"}},o=e=>{const t=r.clone(e);for(const a in t)a.startsWith("@odata")&&delete t[a];return t},l={data:e=>{if(Array.isArray(e))return e.map(a=>o(a));const t=o(e);return"value"in t?t.value:[t]},total:e=>e["@odata.count"]},d=e=>{r.validatePackage(u.packageMetadata,{component:"useODataDataSource"});const t=r.deepMerge({},i,e.transport),a=r.deepMerge({},l,e.schema);return s.useRemoteDataSource({serverGrouping:!1,...e,transport:t,schema:a})};exports.useODataDataSource=d;
|
|
@@ -6,17 +6,22 @@
|
|
|
6
6
|
*-------------------------------------------------------------------------------------------
|
|
7
7
|
*/
|
|
8
8
|
"use client";
|
|
9
|
-
import { useRemoteDataSource as
|
|
10
|
-
import { validatePackage as c, deepMerge as
|
|
9
|
+
import { useRemoteDataSource as s } from "./use-remote-data-source.mjs";
|
|
10
|
+
import { validatePackage as c, deepMerge as a, clone as i } from "@progress/kendo-react-common";
|
|
11
11
|
import { toODataString as u } from "@progress/kendo-data-query";
|
|
12
|
-
import { packageMetadata as
|
|
13
|
-
const
|
|
12
|
+
import { packageMetadata as l } from "../package-metadata.mjs";
|
|
13
|
+
const n = (t) => t.forEach((e) => {
|
|
14
|
+
if (e.filters)
|
|
15
|
+
n(e.filters);
|
|
16
|
+
else if (!/^[A-Za-z_]\w*(?:[./][A-Za-z_]\w*)*$/.test(e.field))
|
|
17
|
+
throw new Error(`Invalid OData field: ${e.field}`);
|
|
18
|
+
}), f = {
|
|
14
19
|
create: {
|
|
15
20
|
contentType: "application/json",
|
|
16
21
|
method: "POST"
|
|
17
22
|
},
|
|
18
23
|
read: {
|
|
19
|
-
parameterMap: (t) => `$count=true&$format=json&${u(t)}
|
|
24
|
+
parameterMap: (t) => (n([...t.sort || [], ...t.group || [], ...t.filter ? [t.filter] : []]), `$count=true&$format=json&${u(t)}`),
|
|
20
25
|
method: "GET"
|
|
21
26
|
},
|
|
22
27
|
update: {
|
|
@@ -27,32 +32,32 @@ const i = {
|
|
|
27
32
|
method: "DELETE"
|
|
28
33
|
}
|
|
29
34
|
}, o = (t) => {
|
|
30
|
-
const e =
|
|
31
|
-
for (const
|
|
32
|
-
|
|
35
|
+
const e = i(t);
|
|
36
|
+
for (const r in e)
|
|
37
|
+
r.startsWith("@odata") && delete e[r];
|
|
33
38
|
return e;
|
|
34
39
|
}, p = {
|
|
35
40
|
data: (t) => {
|
|
36
41
|
if (Array.isArray(t))
|
|
37
|
-
return t.map((
|
|
42
|
+
return t.map((r) => o(r));
|
|
38
43
|
const e = o(t);
|
|
39
44
|
return "value" in e ? e.value : [e];
|
|
40
45
|
},
|
|
41
46
|
total: (t) => t["@odata.count"]
|
|
42
|
-
},
|
|
43
|
-
c(
|
|
44
|
-
const e =
|
|
47
|
+
}, T = (t) => {
|
|
48
|
+
c(l, { component: "useODataDataSource" });
|
|
49
|
+
const e = a(
|
|
45
50
|
{},
|
|
46
|
-
|
|
51
|
+
f,
|
|
47
52
|
t.transport
|
|
48
|
-
),
|
|
49
|
-
return
|
|
53
|
+
), r = a({}, p, t.schema);
|
|
54
|
+
return s({
|
|
50
55
|
serverGrouping: !1,
|
|
51
56
|
...t,
|
|
52
57
|
transport: e,
|
|
53
|
-
schema:
|
|
58
|
+
schema: r
|
|
54
59
|
});
|
|
55
60
|
};
|
|
56
61
|
export {
|
|
57
|
-
|
|
62
|
+
T as useODataDataSource
|
|
58
63
|
};
|
|
@@ -6,4 +6,4 @@
|
|
|
6
6
|
*-------------------------------------------------------------------------------------------
|
|
7
7
|
*/
|
|
8
8
|
"use client";
|
|
9
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const I=require("@progress/kendo-react-common"),we=require("./use-data-source.js"),me=require("../package-metadata.js"),he={data:v=>v,total:v=>v.length},Me={create:{method:"POST",contentType:"application/json"},read:{method:"GET"},update:{method:"PUT",contentType:"application/json"},delete:{method:"DELETE"}},B=(v,F)=>{const j=typeof v=="function"?v(F):v;return new URL(j)},H=(v,F,j)=>typeof v=="function"?v(F):j||v?{...j,...v}:void 0,K=(v,F)=>{typeof F=="object"?Object.keys(F).forEach(j=>{v.searchParams.append(j,F[j])}):typeof F=="string"&&(v.search=F)},Q=async({url:v,method:F,contentType:j,body:V,onError:L,onSuccess:W})=>{var M;const N=await fetch(v,{method:F,headers:j?{"Content-Type":j}:{},...V?{body:JSON.stringify(V)}:{}});return N.ok?W((M=N.headers.get("Content-Type"))!=null&&M.includes("application/json")?await N.json():await N.text()):L==null?void 0:L(await N.json())},Se=v=>{I.validatePackage(me.packageMetadata,{component:"useRemoteDataSource"});const{defaultTotal:F,serverFiltering:j=!0,serverSorting:V=!0,serverPaging:L=!0,serverGrouping:W=!0,...N}=v,M=I.deepMerge({},he,v.schema),t=I.deepMerge({},Me,v.transport),se=typeof M.data=="function"?M.data:M.data?I.getter(M.data):a=>a,ue=typeof M.total=="function"?M.total:M.total?I.getter(M.total):a=>a,r=typeof M.errors=="function"?a=>M.errors(a):M.errors?I.getter(M.errors):a=>{},k=I.getter(String(M.model.id)),q=I.useImmediateInheritState(new Map,v.reads),b=I.useImmediateInheritState(new Map,v.creates),R=I.useImmediateInheritState(new Map,v.updates),x=I.useImmediateInheritState(new Map,v.deletes),f=I.useImmediateInheritState(new Map),D=I.useImmediateInheritState(new Map),ne=a=>{q.value=a},X=a=>{b.value=a},oe=a=>{R.value=a},re=a=>{x.value=a},z=a=>{f.value=a},Y=a=>{D.value=a},C=we.useDataSource({sortable:!V,pageable:!L,filterable:!j,groupable:!W,get data(){return Array.from(new Map([...b.value,...q.value,...R.value]).values()).filter(a=>!x.value.has(k(a)))},...N,schema:M}),ce=a=>{const e=new Map;C.setData(a),a.forEach(n=>{const o=k(n);e.set(o,n)}),ne(e)},O=a=>{const{error:e,data:n}=a;if(!e)return;let o=null;n&&(o=k(n)),D.value.has(o)||D.value.set(o,[]);const s=D.value.get(o)||[];s.push(e),D.value.set(o,s),Y(new Map(D.value))},le=a=>{const{error:e}=a;D.value.forEach((n,o)=>{const s=n.filter(p=>p!==e);s.length===0?D.value.delete(o):D.value.set(o,s)}),Y(new Map(D.value))},de=a=>{const{data:e}=a,n=k(e);D.value.delete(n),Y(new Map(D.value))},ie=()=>{D.value.clear(),Y(new Map(D.value))},ve=a=>{const{data:e}=a,n=k(e);b.value.set(n,e),X(new Map(b.value));const o=new Set(Object.keys(e).filter(s=>{var p;return s!==((p=M.model)==null?void 0:p.id)}));f.value.set(n,o),z(new Map(f.value))},pe=a=>{const{data:e,field:n}=a,o=k(e);if(b.value.has(o)){const d=b.value.get(o);b.value.set(o,{...d,...e}),X(new Map(b.value));const c=f.value.get(o)||new Set;n?c.add(n):Object.keys(e).forEach(g=>{var m;g!==((m=M.model)==null?void 0:m.id)&&c.add(g)}),f.value.set(o,c),z(new Map(f.value));return}const s=R.value.has(o)?R.value.get(o):q.value.has(o)?q.value.get(o):{};R.value.set(o,{...s,...e}),oe(new Map(R.value));const p=f.value.get(o)||new Set;n?p.add(n):Object.keys(e).forEach(d=>{var c;d!==((c=M.model)==null?void 0:c.id)&&p.add(d)}),f.value.set(o,p),z(new Map(f.value))},fe=a=>{const{data:e}=a,n=k(e);if(b.value.has(n)){b.value.delete(n),X(new Map(b.value)),f.value.delete(n),z(new Map(f.value));return}x.value.set(n,e),re(new Map(x.value))},Z=a=>{const{data:e}=a,n=k(e);b.value.delete(n),X(new Map(b.value)),f.value.delete(n),z(new Map(f.value))},$=a=>{const{data:e,field:n}=a,o=k(e);if(R.value.has(o))if(n){const s=f.value.get(o);s&&(s.delete(n),s.size===0?(R.value.delete(o),f.value.delete(o)):f.value.set(o,s),oe(new Map(R.value)),z(new Map(f.value)))}else R.value.delete(o),oe(new Map(R.value)),f.value.delete(o),z(new Map(f.value))},E=a=>{const{data:e}=a,n=k(e);x.value.delete(n),re(new Map(x.value)),f.value.delete(n),z(new Map(f.value))},ee=a=>{const{data:e}=a,n=k(e);q.value.set(n,e),ne(new Map(q.value))},te=a=>{const{data:e}=a,n=k(e);q.value.set(n,e),ne(new Map(q.value))},ae=a=>{const{data:e}=a,n=k(e);q.value.delete(n),ne(new Map(q.value))},ye={get reads(){return q.value},get creates(){return b.value},get updates(){return R.value},get deletes(){return x.value},get dirty(){return f.value},get errors(){return D.value},addError:O,removeError:le,removeErrors:de,removeAllErrors:ie,read:async a=>{var y,_,h,w,J,U,G;if(!(t!=null&&t.read))throw new Error("transport.read is not defined");const e=(y=a==null?void 0:a.filter)!=null?y:C.filter,n=(_=a==null?void 0:a.skip)!=null?_:C.skip,o=(h=a==null?void 0:a.take)!=null?h:C.take,s=(w=a==null?void 0:a.sort)!=null?w:C.sort,p=(J=a==null?void 0:a.group)!=null?J:C.group;if(typeof t.read=="function"){const S=await t.read({...j&&e!==void 0&&{filter:e},...L&&n!==void 0&&{skip:n},...L&&o!==void 0&&{take:o},...V&&s!==void 0&&{sort:s},...W&&p!==void 0&&{group:p}});return ce(S),S}const d={...j&&e!==void 0&&{filter:e},...L&&n!==void 0&&{skip:n},...L&&o!==void 0&&{take:o},...V&&s!==void 0&&{sort:s},...W&&p!==void 0&&{group:p}},c=B(t.read.url),g=t.read.onError,m=t.read.onResponse,P=t.read.onSuccess,T=H(t.read.data),l=((G=(U=t.read).parameterMap)==null?void 0:G.call(U,{...d,...T}))||{...d,...T};K(c,l);try{const S=await Q({url:c,method:t.read.method,contentType:t.read.contentType,body:T,onError:async u=>{var A;const i=(A=await(g==null?void 0:g(u)))!=null?A:r==null?void 0:r(u);return i&&O({error:i}),[]},onSuccess:async u=>{var A;const i=(A=await(m==null?void 0:m(u)))!=null?A:se(u);return C.setTotal(await ue(u)),ce(i),await(P==null?void 0:P(i)),i}});return S!=null?S:[]}catch(S){return console.error(S),[]}},create:ve,update:pe,delete:fe,sync:async()=>{await Promise.all(Array.from(b.value).map(async([a,e])=>{var n,o,s,p;if(t!=null&&t.create)if(typeof t.create=="function")try{const d=await t.create({data:e});ee({data:d||e}),Z({data:e})}catch(d){const c=r==null?void 0:r(d);c&&O({error:c,data:e})}else{const d=B(t.create.url,e),c=H(t.create.data,e,I.clone(e)),g=(p=(s=(o=(n=t.create).parameterMap)==null?void 0:o.call(n,c))!=null?s:c)!=null?p:{},m=t.create.onError,P=t.create.onResponse,T=t.create.onSuccess;K(d,g);try{await Q({url:d,method:t.create.method,contentType:t.create.contentType,body:c,onError:async l=>{var _;const y=(_=await(m==null?void 0:m(l)))!=null?_:r==null?void 0:r(l);y&&O({error:y,data:e})},onSuccess:async l=>{const y=P?await P(l):l;ee({data:y||e}),Z({data:e}),await(T==null?void 0:T(y||e))}})}catch(l){console.error(l)}}})),await Promise.all(Array.from(R.value).map(async([a,e])=>{var n,o,s,p;if(t!=null&&t.update)if(typeof t.update=="function")try{const d=await t.update({data:e});te({data:d||e}),$({data:e})}catch(d){const c=r==null?void 0:r(d);c&&O({error:c,data:e})}else{const d=B(t.update.url,e),c=H(t.update.data,e,e),g=(p=(s=(o=(n=t.update).parameterMap)==null?void 0:o.call(n,c))!=null?s:c)!=null?p:{},m=t.update.onError,P=t.update.onResponse,T=t.update.onSuccess;K(d,g);try{await Q({url:d,method:t.update.method,contentType:t.update.contentType,body:c,onError:async l=>{var _;const y=(_=await(m==null?void 0:m(l)))!=null?_:r==null?void 0:r(l);y&&O({error:y,data:e})},onSuccess:async l=>{const y=P?await P(l):l;return te({data:y||e}),$({data:e}),await(T==null?void 0:T(y||e)),y}})}catch(l){console.error(l)}}})),await Promise.all(Array.from(x.value).map(async([a,e])=>{var n,o,s,p;if(t!=null&&t.delete)if(typeof t.delete=="function")try{await t.delete({data:e}),ae({data:e}),E({data:e})}catch(d){const c=r==null?void 0:r(d);c&&O({error:c,data:e})}else{const d=B(t.delete.url,e),c=H(t.delete.data,e,e),g=(p=(s=(o=(n=t.delete).parameterMap)==null?void 0:o.call(n,c))!=null?s:c)!=null?p:{},m=t.delete.onError,P=t.delete.onResponse,T=t.delete.onSuccess;K(d,g);try{await Q({url:d,method:t.delete.method,contentType:t.delete.contentType,body:c,onError:async l=>{var _;const y=(_=await(m==null?void 0:m(l)))!=null?_:r==null?void 0:r(l);y&&O({error:y,data:e})},onSuccess:async l=>{const y=P?await P(l):l;return ae({data:Object.keys(y).length!==0?y:e}),E({data:e}),await(T==null?void 0:T(l||e)),l}})}catch(l){console.error(l)}}}))},syncItem:async a=>{var o,s,p,d,c,g,m,P,T,l,y,_;const{data:e}=a,n=k(e);if(b.value.has(n)){if(!(t!=null&&t.create))return;if(typeof t.create=="function")try{const h=await t.create({data:e});ee({data:h||e}),Z({data:e})}catch(h){const w=r==null?void 0:r(h);w&&O({error:w,data:e})}else{const h=B(t.create.url,e),w=H(t.create.data,e,I.clone(e)),J=(d=(p=(s=(o=t.create).parameterMap)==null?void 0:s.call(o,w))!=null?p:w)!=null?d:{},U=t.create.onError,G=t.create.onResponse,S=t.create.onSuccess;K(h,J);try{await Q({url:h,method:t.create.method,contentType:t.create.contentType,body:w,onError:async u=>{var A;const i=(A=await(U==null?void 0:U(u)))!=null?A:r==null?void 0:r(u);i&&O({error:i,data:e})},onSuccess:async u=>{const i=G?await G(u):u;return ee({data:i||e}),Z({data:e}),await(S==null?void 0:S(i||e)),i}})}catch(u){console.error(u)}}}if(R.value.has(n)){if(!(t!=null&&t.update))return;if(typeof t.update=="function")try{const h=await t.update({data:e});te({data:h||e}),$({data:e})}catch(h){const w=r==null?void 0:r(h);w&&O({error:w,data:e})}else{const h=B(t.update.url,e),w=H(t.update.data,e,e),J=(P=(m=(g=(c=t.update).parameterMap)==null?void 0:g.call(c,w))!=null?m:w)!=null?P:{},U=t.update.onError,G=t.update.onResponse,S=t.update.onSuccess;K(h,J);try{await Q({url:h,method:t.update.method,contentType:t.update.contentType,body:w,onError:async u=>{var A;const i=(A=await(U==null?void 0:U(u)))!=null?A:r==null?void 0:r(u);i&&O({error:i,data:e})},onSuccess:async u=>{const i=G?await G(u):u;return te({data:i||e}),$({data:e}),await(S==null?void 0:S(i||e)),i}})}catch(u){console.error(u)}}}if(x.value.has(n)){if(!(t!=null&&t.delete))return;if(typeof t.delete=="function")try{await t.delete({data:e}),ae({data:e}),E({data:e})}catch(h){const w=r==null?void 0:r(h);w&&O({error:w,data:e})}else{const h=B(t.delete.url,e),w=H(t.delete.data,e,e),J=(_=(y=(l=(T=t.delete).parameterMap)==null?void 0:l.call(T,w))!=null?y:w)!=null?_:{},U=t.delete.onError,G=t.delete.onResponse,S=t.delete.onSuccess;K(h,J);try{await Q({url:h,method:t.delete.method,contentType:t.delete.contentType,body:w,onError:async u=>{var A;const i=(A=await(U==null?void 0:U(u)))!=null?A:r==null?void 0:r(u);i&&O({error:i,data:e})},onSuccess:async u=>{const i=G?await G(u):u;return ae({data:i||e}),E({data:e}),await(S==null?void 0:S(i||e)),u}})}catch(u){console.error(u)}}}},removeCreate:Z,removeUpdate:$,removeDelete:E,pushCreate:ee,pushUpdate:te,pushDelete:ae,discard:()=>{b.value.clear(),X(new Map(b.value)),R.value.clear(),oe(new Map(R.value)),x.value.clear(),re(new Map(x.value)),f.value.clear(),z(new Map(f.value)),D.value.clear(),Y(new Map(D.value))}};return Object.defineProperties({},{...Object.getOwnPropertyDescriptors(C),...Object.fromEntries(Object.entries(ye).map(([a,e])=>[a,{value:e,writable:!0,enumerable:!0,configurable:!0}]))})};exports.useRemoteDataSource=Se;
|
|
9
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const I=require("@progress/kendo-react-common"),we=require("./use-data-source.js"),me=require("../package-metadata.js"),he={data:p=>p,total:p=>p.length},Me={create:{method:"POST",contentType:"application/json"},read:{method:"GET"},update:{method:"PUT",contentType:"application/json"},delete:{method:"DELETE"}},B=(p,F)=>{const j=typeof p=="function"?p(F):p;return new URL(j)},H=(p,F,j)=>typeof p=="function"?p(F):j||p?{...j,...p}:void 0,K=(p,F)=>{typeof F=="object"?Object.keys(F).forEach(j=>{p.searchParams.append(j,F[j])}):typeof F=="string"&&(p.search=F)},Q=async({url:p,method:F,contentType:j,body:V,onError:L,onSuccess:W})=>{var M;const N=await fetch(p,{method:F,headers:j?{"Content-Type":j}:{},...V?{body:JSON.stringify(V)}:{}});return N.ok?W((M=N.headers.get("Content-Type"))!=null&&M.includes("application/json")?await N.json():await N.text()):L==null?void 0:L(await N.json())},Se=p=>{I.validatePackage(me.packageMetadata,{component:"useRemoteDataSource"});const{defaultTotal:F,serverFiltering:j=!0,serverSorting:V=!0,serverPaging:L=!0,serverGrouping:W=!0,...N}=p,M=I.deepMerge({},he,p.schema),t=I.deepMerge({},Me,p.transport),se=typeof M.data=="function"?M.data:M.data?I.getter(M.data):a=>a,ue=typeof M.total=="function"?M.total:M.total?I.getter(M.total):a=>a,r=typeof M.errors=="function"?a=>M.errors(a):M.errors?I.getter(M.errors):a=>{},k=I.getter(String(M.model.id)),q=I.useImmediateInheritState(new Map,p.reads),b=I.useImmediateInheritState(new Map,p.creates),R=I.useImmediateInheritState(new Map,p.updates),x=I.useImmediateInheritState(new Map,p.deletes),f=I.useImmediateInheritState(new Map),D=I.useImmediateInheritState(new Map),ne=a=>{q.value=a},X=a=>{b.value=a},oe=a=>{R.value=a},re=a=>{x.value=a},z=a=>{f.value=a},Y=a=>{D.value=a},C=we.useDataSource({sortable:!V,pageable:!L,filterable:!j,groupable:!W,get data(){return Array.from(new Map([...b.value,...q.value,...R.value]).values()).filter(a=>!x.value.has(k(a)))},...N,schema:M}),ce=a=>{const e=new Map;C.setData(a),a.forEach(n=>{const o=k(n);e.set(o,n)}),ne(e)},O=a=>{const{error:e,data:n}=a;if(!e)return;let o=null;n&&(o=k(n)),D.value.has(o)||D.value.set(o,[]);const s=D.value.get(o)||[];s.push(e),D.value.set(o,s),Y(new Map(D.value))},le=a=>{const{error:e}=a;D.value.forEach((n,o)=>{const s=n.filter(v=>v!==e);s.length===0?D.value.delete(o):D.value.set(o,s)}),Y(new Map(D.value))},de=a=>{const{data:e}=a,n=k(e);D.value.delete(n),Y(new Map(D.value))},ie=()=>{D.value.clear(),Y(new Map(D.value))},pe=a=>{const{data:e}=a,n=k(e);b.value.set(n,e),X(new Map(b.value));const o=new Set(Object.keys(e).filter(s=>{var v;return s!==((v=M.model)==null?void 0:v.id)}));f.value.set(n,o),z(new Map(f.value))},ve=a=>{const{data:e,field:n}=a,o=k(e);if(b.value.has(o)){const d=b.value.get(o);b.value.set(o,{...d,...e}),X(new Map(b.value));const c=f.value.get(o)||new Set;n?c.add(n):Object.keys(e).forEach(g=>{var m;g!==((m=M.model)==null?void 0:m.id)&&c.add(g)}),f.value.set(o,c),z(new Map(f.value));return}const s=R.value.has(o)?R.value.get(o):q.value.has(o)?q.value.get(o):{};R.value.set(o,{...s,...e}),oe(new Map(R.value));const v=f.value.get(o)||new Set;n?v.add(n):Object.keys(e).forEach(d=>{var c;d!==((c=M.model)==null?void 0:c.id)&&v.add(d)}),f.value.set(o,v),z(new Map(f.value))},fe=a=>{const{data:e}=a,n=k(e);if(b.value.has(n)){b.value.delete(n),X(new Map(b.value)),f.value.delete(n),z(new Map(f.value));return}x.value.set(n,e),re(new Map(x.value))},Z=a=>{const{data:e}=a,n=k(e);b.value.delete(n),X(new Map(b.value)),f.value.delete(n),z(new Map(f.value))},$=a=>{const{data:e,field:n}=a,o=k(e);if(R.value.has(o))if(n){const s=f.value.get(o);s&&(s.delete(n),s.size===0?(R.value.delete(o),f.value.delete(o)):f.value.set(o,s),oe(new Map(R.value)),z(new Map(f.value)))}else R.value.delete(o),oe(new Map(R.value)),f.value.delete(o),z(new Map(f.value))},E=a=>{const{data:e}=a,n=k(e);x.value.delete(n),re(new Map(x.value)),f.value.delete(n),z(new Map(f.value))},ee=a=>{const{data:e}=a,n=k(e);q.value.set(n,e),ne(new Map(q.value))},te=a=>{const{data:e}=a,n=k(e);q.value.set(n,e),ne(new Map(q.value))},ae=a=>{const{data:e}=a,n=k(e);q.value.delete(n),ne(new Map(q.value))},ye={get reads(){return q.value},get creates(){return b.value},get updates(){return R.value},get deletes(){return x.value},get dirty(){return f.value},get errors(){return D.value},addError:O,removeError:le,removeErrors:de,removeAllErrors:ie,read:async a=>{var y,_,h,w,J,U,G;if(!(t!=null&&t.read))throw new Error("transport.read is not defined");const e=(y=a==null?void 0:a.filter)!=null?y:C.filter,n=(_=a==null?void 0:a.skip)!=null?_:C.skip,o=(h=a==null?void 0:a.take)!=null?h:C.take,s=(w=a==null?void 0:a.sort)!=null?w:C.sort,v=(J=a==null?void 0:a.group)!=null?J:C.group;if(typeof t.read=="function"){const S=await t.read({...j&&e!==void 0&&{filter:e},...L&&n!==void 0&&{skip:n},...L&&o!==void 0&&{take:o},...V&&s!==void 0&&{sort:s},...W&&v!==void 0&&{group:v}});return ce(S),S}const d={...j&&e!==void 0&&{filter:e},...L&&n!==void 0&&{skip:n},...L&&o!==void 0&&{take:o},...V&&s!==void 0&&{sort:s},...W&&v!==void 0&&{group:v}},c=B(t.read.url),g=t.read.onError,m=t.read.onResponse,P=t.read.onSuccess,T=H(t.read.data),l=((G=(U=t.read).parameterMap)==null?void 0:G.call(U,{...d,...T}))||{...d,...T};K(c,l);try{const S=await Q({url:c,method:t.read.method,contentType:t.read.contentType,body:T,onError:async u=>{var A;const i=(A=await(g==null?void 0:g(u)))!=null?A:r==null?void 0:r(u);return i&&O({error:i}),[]},onSuccess:async u=>{var A;const i=(A=await(m==null?void 0:m(u)))!=null?A:se(u);return C.setTotal(await ue(u)),ce(i),await(P==null?void 0:P(i)),i}});return S!=null?S:[]}catch(S){return console.error(S),[]}},create:pe,update:ve,delete:fe,sync:async()=>{await Promise.all(Array.from(b.value).map(async([a,e])=>{var n,o,s,v;if(t!=null&&t.create)if(typeof t.create=="function")try{const d=await t.create({data:e});ee({data:d||e}),Z({data:e})}catch(d){const c=r==null?void 0:r(d);c&&O({error:c,data:e})}else{const d=B(t.create.url,e),c=H(t.create.data,e,I.clone(e)),g=(v=(s=(o=(n=t.create).parameterMap)==null?void 0:o.call(n,c))!=null?s:typeof t.create.data=="function"?c:t.create.data)!=null?v:{},m=t.create.onError,P=t.create.onResponse,T=t.create.onSuccess;K(d,g);try{await Q({url:d,method:t.create.method,contentType:t.create.contentType,body:c,onError:async l=>{var _;const y=(_=await(m==null?void 0:m(l)))!=null?_:r==null?void 0:r(l);y&&O({error:y,data:e})},onSuccess:async l=>{const y=P?await P(l):l;ee({data:y||e}),Z({data:e}),await(T==null?void 0:T(y||e))}})}catch(l){console.error(l)}}})),await Promise.all(Array.from(R.value).map(async([a,e])=>{var n,o,s,v;if(t!=null&&t.update)if(typeof t.update=="function")try{const d=await t.update({data:e});te({data:d||e}),$({data:e})}catch(d){const c=r==null?void 0:r(d);c&&O({error:c,data:e})}else{const d=B(t.update.url,e),c=H(t.update.data,e,e),g=(v=(s=(o=(n=t.update).parameterMap)==null?void 0:o.call(n,c))!=null?s:typeof t.update.data=="function"?c:t.update.data)!=null?v:{},m=t.update.onError,P=t.update.onResponse,T=t.update.onSuccess;K(d,g);try{await Q({url:d,method:t.update.method,contentType:t.update.contentType,body:c,onError:async l=>{var _;const y=(_=await(m==null?void 0:m(l)))!=null?_:r==null?void 0:r(l);y&&O({error:y,data:e})},onSuccess:async l=>{const y=P?await P(l):l;return te({data:y||e}),$({data:e}),await(T==null?void 0:T(y||e)),y}})}catch(l){console.error(l)}}})),await Promise.all(Array.from(x.value).map(async([a,e])=>{var n,o,s,v;if(t!=null&&t.delete)if(typeof t.delete=="function")try{await t.delete({data:e}),ae({data:e}),E({data:e})}catch(d){const c=r==null?void 0:r(d);c&&O({error:c,data:e})}else{const d=B(t.delete.url,e),c=H(t.delete.data,e,e),g=(v=(s=(o=(n=t.delete).parameterMap)==null?void 0:o.call(n,c))!=null?s:typeof t.delete.data=="function"?c:t.delete.data)!=null?v:{},m=t.delete.onError,P=t.delete.onResponse,T=t.delete.onSuccess;K(d,g);try{await Q({url:d,method:t.delete.method,contentType:t.delete.contentType,body:c,onError:async l=>{var _;const y=(_=await(m==null?void 0:m(l)))!=null?_:r==null?void 0:r(l);y&&O({error:y,data:e})},onSuccess:async l=>{const y=P?await P(l):l;return ae({data:Object.keys(y).length!==0?y:e}),E({data:e}),await(T==null?void 0:T(l||e)),l}})}catch(l){console.error(l)}}}))},syncItem:async a=>{var o,s,v,d,c,g,m,P,T,l,y,_;const{data:e}=a,n=k(e);if(b.value.has(n)){if(!(t!=null&&t.create))return;if(typeof t.create=="function")try{const h=await t.create({data:e});ee({data:h||e}),Z({data:e})}catch(h){const w=r==null?void 0:r(h);w&&O({error:w,data:e})}else{const h=B(t.create.url,e),w=H(t.create.data,e,I.clone(e)),J=(d=(v=(s=(o=t.create).parameterMap)==null?void 0:s.call(o,w))!=null?v:typeof t.create.data=="function"?w:t.create.data)!=null?d:{},U=t.create.onError,G=t.create.onResponse,S=t.create.onSuccess;K(h,J);try{await Q({url:h,method:t.create.method,contentType:t.create.contentType,body:w,onError:async u=>{var A;const i=(A=await(U==null?void 0:U(u)))!=null?A:r==null?void 0:r(u);i&&O({error:i,data:e})},onSuccess:async u=>{const i=G?await G(u):u;return ee({data:i||e}),Z({data:e}),await(S==null?void 0:S(i||e)),i}})}catch(u){console.error(u)}}}if(R.value.has(n)){if(!(t!=null&&t.update))return;if(typeof t.update=="function")try{const h=await t.update({data:e});te({data:h||e}),$({data:e})}catch(h){const w=r==null?void 0:r(h);w&&O({error:w,data:e})}else{const h=B(t.update.url,e),w=H(t.update.data,e,e),J=(P=(m=(g=(c=t.update).parameterMap)==null?void 0:g.call(c,w))!=null?m:typeof t.update.data=="function"?w:t.update.data)!=null?P:{},U=t.update.onError,G=t.update.onResponse,S=t.update.onSuccess;K(h,J);try{await Q({url:h,method:t.update.method,contentType:t.update.contentType,body:w,onError:async u=>{var A;const i=(A=await(U==null?void 0:U(u)))!=null?A:r==null?void 0:r(u);i&&O({error:i,data:e})},onSuccess:async u=>{const i=G?await G(u):u;return te({data:i||e}),$({data:e}),await(S==null?void 0:S(i||e)),i}})}catch(u){console.error(u)}}}if(x.value.has(n)){if(!(t!=null&&t.delete))return;if(typeof t.delete=="function")try{await t.delete({data:e}),ae({data:e}),E({data:e})}catch(h){const w=r==null?void 0:r(h);w&&O({error:w,data:e})}else{const h=B(t.delete.url,e),w=H(t.delete.data,e,e),J=(_=(y=(l=(T=t.delete).parameterMap)==null?void 0:l.call(T,w))!=null?y:typeof t.delete.data=="function"?w:t.delete.data)!=null?_:{},U=t.delete.onError,G=t.delete.onResponse,S=t.delete.onSuccess;K(h,J);try{await Q({url:h,method:t.delete.method,contentType:t.delete.contentType,body:w,onError:async u=>{var A;const i=(A=await(U==null?void 0:U(u)))!=null?A:r==null?void 0:r(u);i&&O({error:i,data:e})},onSuccess:async u=>{const i=G?await G(u):u;return ae({data:i||e}),E({data:e}),await(S==null?void 0:S(i||e)),u}})}catch(u){console.error(u)}}}},removeCreate:Z,removeUpdate:$,removeDelete:E,pushCreate:ee,pushUpdate:te,pushDelete:ae,discard:()=>{b.value.clear(),X(new Map(b.value)),R.value.clear(),oe(new Map(R.value)),x.value.clear(),re(new Map(x.value)),f.value.clear(),z(new Map(f.value)),D.value.clear(),Y(new Map(D.value))}};return Object.defineProperties({},{...Object.getOwnPropertyDescriptors(C),...Object.fromEntries(Object.entries(ye).map(([a,e])=>[a,{value:e,writable:!0,enumerable:!0,configurable:!0}]))})};exports.useRemoteDataSource=Se;
|