@svar-ui/kanban-provider 2.6.0

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,205 @@
1
+ //#region ../../node_modules/.pnpm/@svar-ui+lib-state@1.9.6/node_modules/@svar-ui/lib-state/dist/index.d.ts
2
+ interface IEventConfig {
3
+ intercept?: boolean;
4
+ tag?: number | string | symbol;
5
+ }
6
+ interface IEventBus<T> {
7
+ exec(name: keyof T, ev: T[keyof T]): Promise<T[keyof T]>;
8
+ setNext(next: IEventBus<T>): IEventBus<T>;
9
+ }
10
+ declare class EventBus<T, A extends keyof T> {
11
+ private _handlers;
12
+ protected _nextHandler: IEventBus<T>;
13
+ protected _tag: WeakMap<{
14
+ (v: T[A]): void | boolean | Promise<boolean>;
15
+ }, number | string | symbol>;
16
+ constructor();
17
+ on(name: A, handler: (v: T[A]) => void | boolean | Promise<boolean>, config?: IEventConfig): void;
18
+ intercept(name: A, handler: (v: T[A]) => void | boolean | Promise<boolean>, config?: IEventConfig): void;
19
+ detach(tag: number | string | symbol): void;
20
+ exec(name: A, ev: T[A]): Promise<T[A]>;
21
+ setNext(next: IEventBus<T>): IEventBus<T>;
22
+ }
23
+ //#endregion
24
+ //#region ../../node_modules/.pnpm/@svar-ui+lib-data-provider@1.7.2/node_modules/@svar-ui/lib-data-provider/dist/index.d.ts
25
+ type Action = {
26
+ ignoreID?: boolean;
27
+ debounce?: number;
28
+ handler: Handler;
29
+ };
30
+ type ActionMap<T> = { [P in keyof T]?: Action };
31
+ type DataObj = {
32
+ [key: string]: any;
33
+ };
34
+ type Handler = (data: DataObj, action: string, ev: any) => Promise<any>;
35
+ type HandlerConfig = {
36
+ resolve?: (v: boolean) => void;
37
+ reject?: (e: any) => void;
38
+ timer?: number;
39
+ kind?: number;
40
+ debounce?: number;
41
+ ignoreID?: boolean;
42
+ handler: Handler;
43
+ };
44
+ type RestDataProviderConfig = {
45
+ batchURL?: string;
46
+ };
47
+ type TID = string | number;
48
+ type ServerResponse = {
49
+ id?: TID;
50
+ };
51
+ declare class ActionQueue {
52
+ private _awaitAddingQueue;
53
+ private _queue;
54
+ private _idPool;
55
+ private _backId;
56
+ private _status;
57
+ private _waitPull;
58
+ constructor();
59
+ reset(ids?: boolean): void;
60
+ resolve(id: TID, type: number): TID;
61
+ getSync(): number;
62
+ waitSync(): Promise<void>;
63
+ getId(id: TID): TID | null;
64
+ waitId(id: TID): Promise<TID>;
65
+ add(action: string, data: DataObj, proc: HandlerConfig): Promise<boolean>;
66
+ tryExec(action: string, data: DataObj, proc: HandlerConfig, finish?: () => void): boolean;
67
+ exec(action: string, data: DataObj, proc: HandlerConfig, finish?: () => void): Promise<ServerResponse> | null;
68
+ correctID(obj: DataObj, ignore: TID): DataObj | symbol;
69
+ execQueue(): void;
70
+ private _finishQueue;
71
+ }
72
+ declare class Rest<T> extends EventBus<T, keyof T> {
73
+ private _queue;
74
+ private _customHeaders;
75
+ protected _url: string;
76
+ protected _batchUrl?: string;
77
+ private _batchQueue;
78
+ private _batchTimeout;
79
+ constructor(url?: string, config?: Partial<RestDataProviderConfig>);
80
+ getHandlers(): ActionMap<T>;
81
+ setHeaders(headers: Record<string, string>): void;
82
+ getQueue(): ActionQueue;
83
+ send(url: string, method: string, data?: object, customHeaders?: Record<string, string>): Promise<T>;
84
+ private sendBatchRequest;
85
+ protected toPayload(obj: object): string;
86
+ protected sendRequest<T>(url: string, method: string, data?: string | object, customHeaders?: Record<string, string>): Promise<T>;
87
+ }
88
+ //#endregion
89
+ //#region ../store/dist/index.d.mts
90
+ type CardID = string | number;
91
+ type ColumnID = string | number;
92
+ type KanbanCard = {
93
+ id: CardID;
94
+ [key: string]: any;
95
+ };
96
+ type ColumnConfig = {
97
+ id: ColumnID;
98
+ label: string;
99
+ css?: string;
100
+ metadata?: Record<string, any>;
101
+ cardLimit?: number | boolean;
102
+ addCard?: boolean;
103
+ collapsed?: boolean;
104
+ };
105
+ type SortCriterion = ((a: KanbanCard, b: KanbanCard) => number) | {
106
+ field: string;
107
+ dir?: "asc" | "desc";
108
+ } | null;
109
+ type FilterPredicate = (card: KanbanCard) => boolean;
110
+ type ExportConfig = {
111
+ url?: string | ((data: ExportConfig, records: KanbanCard[], helpers: ExportHelpers) => void);
112
+ format?: string;
113
+ fileName?: string;
114
+ skin?: string;
115
+ paper?: {
116
+ fitSize?: boolean;
117
+ size?: string | {
118
+ width: number;
119
+ height: number;
120
+ };
121
+ landscape?: boolean;
122
+ styles?: string | string[];
123
+ margins?: {
124
+ top?: number;
125
+ bottom?: number;
126
+ left?: number;
127
+ right?: number;
128
+ };
129
+ header?: string;
130
+ footer?: string;
131
+ scale?: number;
132
+ };
133
+ excel?: {
134
+ sheetNames?: string[];
135
+ dateFormat?: string;
136
+ indent?: "native" | "spaces";
137
+ };
138
+ data?: Record<string, any>;
139
+ };
140
+ type ExportHelpers = {
141
+ post: (url: string, data: Record<string, string>) => void;
142
+ serialize: (value: any) => string;
143
+ };
144
+ interface StoreActions {
145
+ ["add-card"]: {
146
+ card: Partial<KanbanCard>;
147
+ edit?: boolean;
148
+ id?: CardID;
149
+ after?: CardID;
150
+ };
151
+ ["update-card"]: {
152
+ id: CardID;
153
+ card: Partial<KanbanCard>;
154
+ };
155
+ ["move-card"]: {
156
+ id: CardID;
157
+ column?: ColumnID;
158
+ before?: CardID | null;
159
+ };
160
+ ["update-column"]: {
161
+ id: ColumnID;
162
+ column: Partial<ColumnConfig>;
163
+ };
164
+ ["duplicate-card"]: {
165
+ id: CardID;
166
+ card?: Partial<KanbanCard>;
167
+ edit?: boolean;
168
+ };
169
+ ["delete-card"]: {
170
+ id: CardID;
171
+ };
172
+ ["select-card"]: {
173
+ id: CardID | null;
174
+ };
175
+ ["filter-cards"]: {
176
+ filter?: FilterPredicate | null;
177
+ tag?: string;
178
+ };
179
+ ["sort-cards"]: {
180
+ sort?: SortCriterion;
181
+ };
182
+ ["request-data"]: {
183
+ id: ColumnID;
184
+ };
185
+ ["provide-data"]: {
186
+ id?: ColumnID;
187
+ cards: KanbanCard[];
188
+ };
189
+ ["export-data"]: ExportConfig;
190
+ ["undo"]: Record<string, never>;
191
+ ["redo"]: Record<string, never>;
192
+ } //#endregion
193
+ //#region src/kanban_store.d.ts
194
+ //#endregion
195
+ //#region src/RestDataProvider.d.ts
196
+ type TMethodsConfig = Pick<StoreActions, "add-card" | "update-card" | "delete-card" | "move-card" | "duplicate-card">;
197
+ declare class RestDataProvider extends Rest<TMethodsConfig> {
198
+ getHandlers(): ActionMap<TMethodsConfig>;
199
+ getData(): Promise<KanbanCard[]>;
200
+ parseCards(data: KanbanCard[]): KanbanCard[];
201
+ protected toPayload(obj: object): string;
202
+ formatDate(date: Date): string;
203
+ }
204
+ //#endregion
205
+ export { RestDataProvider };
package/dist/index.mjs ADDED
@@ -0,0 +1,326 @@
1
+ (/* @__PURE__ */ new Date()).valueOf();
2
+ function isTempID(v) {
3
+ return typeof v === "string" && v.length === 20 && parseInt(v.substr(7)) > 0xe8d4a51000;
4
+ }
5
+ var EventBus = class {
6
+ constructor() {
7
+ this._nextHandler = null;
8
+ this._handlers = {};
9
+ this._tag = /* @__PURE__ */ new WeakMap();
10
+ this.exec = this.exec.bind(this);
11
+ }
12
+ on(name, handler, config) {
13
+ let prev = this._handlers[name];
14
+ if (!prev) prev = this._handlers[name] = [handler];
15
+ else if (config && config.intercept) prev.unshift(handler);
16
+ else prev.push(handler);
17
+ if (config && config.tag) this._tag.set(handler, config.tag);
18
+ }
19
+ intercept(name, handler, config) {
20
+ this.on(name, handler, {
21
+ ...config,
22
+ intercept: true
23
+ });
24
+ }
25
+ detach(tag) {
26
+ for (const key in this._handlers) {
27
+ const stack = this._handlers[key];
28
+ for (let i = stack.length - 1; i >= 0; i--) if (this._tag.get(stack[i]) === tag) stack.splice(i, 1);
29
+ }
30
+ }
31
+ async exec(name, ev) {
32
+ const stack = this._handlers[name];
33
+ if (stack) for (let i = 0; i < stack.length; i++) {
34
+ const res = stack[i](ev);
35
+ if (res === false) return;
36
+ if (res && res.then) {
37
+ if (await res === false) return;
38
+ }
39
+ }
40
+ if (this._nextHandler) await this._nextHandler.exec(name, ev);
41
+ return ev;
42
+ }
43
+ setNext(next) {
44
+ return this._nextHandler = next;
45
+ }
46
+ };
47
+ //#endregion
48
+ //#region ../../node_modules/.pnpm/@svar-ui+lib-data-provider@1.7.2/node_modules/@svar-ui/lib-data-provider/dist/index.js
49
+ var cantSendYet = Symbol();
50
+ var ActionQueue = class {
51
+ constructor() {
52
+ this.reset(true);
53
+ }
54
+ reset(ids = false) {
55
+ this._awaitAddingQueue = [];
56
+ this._queue = {};
57
+ this._waitPull = {};
58
+ this._status = [];
59
+ if (ids) {
60
+ this._idPool = {};
61
+ this._backId = [];
62
+ }
63
+ }
64
+ resolve(id, type) {
65
+ const col = this._backId[type];
66
+ if (typeof col === "undefined") return id;
67
+ const tID = col[id];
68
+ return typeof tID === "undefined" ? id : tID;
69
+ }
70
+ getSync() {
71
+ const t = this._awaitAddingQueue;
72
+ if (!t.length) return 0;
73
+ for (let i = 0; i < t.length; i++) if (!t[i].sent) return 1;
74
+ return 2;
75
+ }
76
+ waitSync() {
77
+ return new Promise((resolve) => {
78
+ if (this.getSync() === 0) resolve();
79
+ else this._status.push(resolve);
80
+ });
81
+ }
82
+ getId(id) {
83
+ return this._idPool[id] || (isTempID(id) ? null : id);
84
+ }
85
+ waitId(id) {
86
+ return new Promise((resolve) => {
87
+ const sid = this.getId(id);
88
+ if (sid !== null) resolve(sid);
89
+ const warr = this._waitPull[id] || [];
90
+ warr.push(resolve);
91
+ this._waitPull[id] = warr;
92
+ });
93
+ }
94
+ add(action, data, proc) {
95
+ return new Promise((resolve, reject) => {
96
+ proc = {
97
+ ...proc,
98
+ resolve,
99
+ reject
100
+ };
101
+ if (proc.debounce) {
102
+ const qid = `${action}"/"${data.id}`;
103
+ const item = this._queue[qid];
104
+ if (item) {
105
+ proc.resolve = (v) => {
106
+ item.resolve(v);
107
+ resolve(v);
108
+ };
109
+ proc.reject = (e) => {
110
+ item.reject(e);
111
+ reject();
112
+ };
113
+ clearTimeout(item.timer);
114
+ }
115
+ this._queue[qid] = proc;
116
+ proc.timer = setTimeout(() => {
117
+ this.tryExec(action, data, proc);
118
+ }, proc.debounce);
119
+ return;
120
+ }
121
+ this.tryExec(action, data, proc);
122
+ });
123
+ }
124
+ tryExec(action, data, proc, finish) {
125
+ const ready = this.exec(action, data, proc, finish);
126
+ if (ready === null) {
127
+ if (!finish) this._awaitAddingQueue.push({
128
+ action,
129
+ data,
130
+ proc
131
+ });
132
+ return false;
133
+ }
134
+ ready.then((res) => {
135
+ const check = res && res.id && res.id != data.id && isTempID(data.id);
136
+ if (check) {
137
+ this._idPool[data.id] = res.id;
138
+ if (this._waitPull[data.id]) {
139
+ this._waitPull[data.id].forEach((v) => v(res.id));
140
+ delete this._waitPull[data.id];
141
+ }
142
+ if (proc.kind) {
143
+ let t = this._backId[proc.kind];
144
+ if (!t) t = this._backId[proc.kind] = {};
145
+ t[res.id] = data.id;
146
+ }
147
+ }
148
+ data.response = res;
149
+ proc.resolve(true);
150
+ if (finish) finish();
151
+ if (check) this.execQueue();
152
+ }, (e) => {
153
+ if (finish) finish();
154
+ proc.reject(e);
155
+ });
156
+ return true;
157
+ }
158
+ exec(action, data, proc, finish) {
159
+ const correctData = this.correctID(data, proc.ignoreID ? data.id : null);
160
+ if (correctData === cantSendYet) return null;
161
+ let res;
162
+ try {
163
+ res = proc.handler(correctData, action, data);
164
+ } catch (e) {
165
+ finish();
166
+ proc.reject(e);
167
+ }
168
+ return res;
169
+ }
170
+ correctID(obj, ignore) {
171
+ let copy = null;
172
+ for (const key in obj) {
173
+ const test = obj[key];
174
+ if (typeof test === "object") {
175
+ const after = this.correctID(test, ignore);
176
+ if (after !== test) {
177
+ if (after === cantSendYet) return cantSendYet;
178
+ if (copy === null) copy = { ...obj };
179
+ copy[key] = after;
180
+ }
181
+ } else if (isTempID(test)) {
182
+ const hasRealID = this._idPool[test];
183
+ if (hasRealID) {
184
+ if (copy === null) copy = { ...obj };
185
+ copy[key] = hasRealID;
186
+ } else if (!ignore) return cantSendYet;
187
+ }
188
+ }
189
+ return copy || obj;
190
+ }
191
+ execQueue() {
192
+ this._awaitAddingQueue.forEach((a) => {
193
+ if (!a.sent) {
194
+ const finish = () => this._finishQueue(a);
195
+ if (this.tryExec(a.action, a.data, a.proc, finish)) a.sent = true;
196
+ }
197
+ });
198
+ }
199
+ _finishQueue(a) {
200
+ this._awaitAddingQueue = this._awaitAddingQueue.filter((v) => v !== a);
201
+ if (!this._awaitAddingQueue.length && this._status.length) {
202
+ const temp = [...this._status];
203
+ this._status = [];
204
+ temp.forEach((resolve) => resolve());
205
+ }
206
+ }
207
+ };
208
+ var Rest = class extends EventBus {
209
+ constructor(url, config) {
210
+ super();
211
+ this._customHeaders = {};
212
+ this._batchQueue = [];
213
+ this._batchTimeout = null;
214
+ this._url = url;
215
+ this._batchUrl = config?.batchURL;
216
+ this._queue = new ActionQueue();
217
+ const handlers = this.getHandlers();
218
+ for (const x in handlers) this.on(x, (ev) => {
219
+ if (!ev.skipProvider) return this._queue.add(x, ev, handlers[x]);
220
+ });
221
+ }
222
+ getHandlers() {
223
+ return {};
224
+ }
225
+ setHeaders(headers) {
226
+ this._customHeaders = headers;
227
+ }
228
+ getQueue() {
229
+ return this._queue;
230
+ }
231
+ async send(url, method, data, customHeaders = {}) {
232
+ if (this._batchUrl && method !== "GET") return this.sendBatchRequest(url, method, data, customHeaders);
233
+ else return this.sendRequest(url, method, data, customHeaders);
234
+ }
235
+ async sendBatchRequest(url, method, data, customHeaders) {
236
+ return new Promise((resolve) => {
237
+ this._batchQueue.push({
238
+ url,
239
+ method,
240
+ data,
241
+ resolve
242
+ });
243
+ if (this._batchTimeout) clearTimeout(this._batchTimeout);
244
+ this._batchTimeout = setTimeout(async () => {
245
+ const currentQueue = [...this._batchQueue];
246
+ this._batchQueue = [];
247
+ if (currentQueue.length > 1) {
248
+ const batchData = currentQueue.map((req) => ({
249
+ url: req.url,
250
+ method: req.method,
251
+ data: { ...req.data }
252
+ }));
253
+ const results = await this.sendRequest(this._batchUrl, "POST", batchData);
254
+ currentQueue.forEach((q, i) => q.resolve(results[i]));
255
+ } else resolve(await this.sendRequest(url, method, data, customHeaders));
256
+ }, 10);
257
+ });
258
+ }
259
+ toPayload(obj) {
260
+ return JSON.stringify(obj);
261
+ }
262
+ async sendRequest(url, method, data, customHeaders = {}) {
263
+ const req = {
264
+ method,
265
+ headers: {
266
+ "Content-Type": "application/json",
267
+ ...customHeaders,
268
+ ...this._customHeaders
269
+ }
270
+ };
271
+ if (data) req.body = typeof data === "object" ? this.toPayload(data) : data;
272
+ const slash = !url || this._url.endsWith("/") || url[0] === "/" ? "" : "/";
273
+ return fetch(`${this._url}${slash}${url || ""}`, req).then((res) => res.json());
274
+ }
275
+ };
276
+ //#endregion
277
+ //#region src/RestDataProvider.ts
278
+ var RestDataProvider = class extends Rest {
279
+ getHandlers() {
280
+ return {
281
+ "add-card": {
282
+ ignoreID: true,
283
+ handler: async (data) => {
284
+ return this.send("cards", "POST", data.card);
285
+ }
286
+ },
287
+ "update-card": {
288
+ debounce: 500,
289
+ handler: async (data) => {
290
+ return this.send(`cards/${data.id}`, "PUT", data.card);
291
+ }
292
+ },
293
+ "move-card": { handler: async (data) => {
294
+ return this.send(`cards/${data.id}/move`, "PUT", data);
295
+ } },
296
+ "delete-card": { handler: async (data) => this.send(`cards/${data.id}`, "DELETE") },
297
+ "duplicate-card": {
298
+ ignoreID: true,
299
+ handler: async (data) => {
300
+ return this.send(`cards/${data.id}/duplicate`, "POST", data.card);
301
+ }
302
+ }
303
+ };
304
+ }
305
+ async getData() {
306
+ const cards = await this.send("cards", "GET");
307
+ return this.parseCards(cards);
308
+ }
309
+ parseCards(data) {
310
+ data.forEach((item) => {
311
+ if (item.deadline) item.deadline = new Date(item.deadline);
312
+ });
313
+ return data;
314
+ }
315
+ toPayload(obj) {
316
+ return JSON.stringify(obj, (_key, value) => {
317
+ if (value instanceof Date) return this.formatDate(value);
318
+ return value;
319
+ });
320
+ }
321
+ formatDate(date) {
322
+ return date.toISOString();
323
+ }
324
+ };
325
+ //#endregion
326
+ export { RestDataProvider };
package/license.txt ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 XB Software Sp. z o.o.
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/package.json ADDED
@@ -0,0 +1,35 @@
1
+ {
2
+ "name": "@svar-ui/kanban-provider",
3
+ "version": "2.6.0",
4
+ "description": "Data provider and REST proxy for the SVAR Kanban",
5
+ "license": "MIT",
6
+ "files": [
7
+ "dist",
8
+ "license.txt"
9
+ ],
10
+ "type": "module",
11
+ "exports": {
12
+ ".": "./dist/index.mjs",
13
+ "./package.json": "./package.json"
14
+ },
15
+ "publishConfig": {
16
+ "access": "public"
17
+ },
18
+ "devDependencies": {
19
+ "@svar-ui/lib-data-provider": "1.7.2",
20
+ "@typescript/native-preview": "7.0.0-dev.20260316.1",
21
+ "typescript": "^5.9.3",
22
+ "vite-plus": "0.1.16",
23
+ "@svar-ui/kanban-store": "2.6.0"
24
+ },
25
+ "inlinedDependencies": {
26
+ "@svar-ui/lib-data-provider": "1.7.2",
27
+ "@svar-ui/lib-state": "1.9.6"
28
+ },
29
+ "scripts": {
30
+ "build": "vp pack",
31
+ "dev": "vp pack --watch",
32
+ "test": "vp test",
33
+ "check": "vp check"
34
+ }
35
+ }