@svar-ui/kanban-store 2.6.0 → 2.7.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.
package/dist/index.d.mts CHANGED
@@ -1,12 +1,13 @@
1
1
  import { EventBus, Store, TDataConfig, TWritableCreator } from "@svar-ui/lib-state";
2
-
3
2
  //#region src/cards_store.d.ts
4
- declare class CardsStore {
3
+ export declare class CardsStore {
5
4
  private _cards;
6
5
  constructor(initial?: KanbanCard[]);
7
6
  getCards(): KanbanCard[];
8
7
  getById(id: CardID): KanbanCard | undefined;
9
8
  add(card: KanbanCard, after?: CardID): KanbanCard;
9
+ /** Inserts before the anchor, or appends when it is null or unknown. */
10
+ addBefore(card: KanbanCard, before: CardID | null): KanbanCard;
10
11
  update(id: CardID, patch: Partial<KanbanCard>): KanbanCard | undefined;
11
12
  upsert(card: KanbanCard): KanbanCard;
12
13
  remove(id: CardID): boolean;
@@ -15,59 +16,106 @@ declare class CardsStore {
15
16
  }
16
17
  //#endregion
17
18
  //#region src/types.d.ts
18
- type Brandmark = {
19
+ export type Brandmark = {
19
20
  text: string;
20
21
  link?: string;
21
22
  style: string;
22
23
  };
23
- type CardID = string | number;
24
- type ColumnID = string | number;
25
- type ColumnDataStatus = "unknown" | "loading" | "loaded";
26
- type ColumnDataState = {
24
+ export type CardID = string | number;
25
+ export type ColumnID = string | number;
26
+ export type SwimlaneID = string | number;
27
+ export type SwimlaneAccessor = ColumnAccessor;
28
+ export type SwimlaneConfig = {
29
+ id: SwimlaneID;
30
+ label: string;
31
+ collapsed?: boolean;
32
+ css?: string;
33
+ metadata?: Record<string, any>;
34
+ };
35
+ export type SwimlaneCellView = {
36
+ column: ColumnID;
37
+ cards: KanbanCard[];
38
+ };
39
+ export type SwimlaneView = SwimlaneConfig & {
40
+ collapsed: boolean;
41
+ count: number;
42
+ cells: SwimlaneCellView[];
43
+ };
44
+ export type ColumnDataStatus = "unknown" | "loading" | "loaded";
45
+ export type ColumnDataState = {
27
46
  status: ColumnDataStatus;
28
47
  };
29
- type KanbanCard = {
48
+ export type KanbanCard = {
30
49
  id: CardID;
31
50
  [key: string]: any;
32
51
  };
33
- type ColumnConfig = {
52
+ export type ColumnSummaryConfig<T = any> = {
53
+ id: string;
54
+ calculate: (cards: readonly KanbanCard[], column: ColumnConfig) => T;
55
+ format?: (value: T, column: ColumnConfig) => string;
56
+ css?: (value: T, column: ColumnConfig) => string;
57
+ };
58
+ export type ColumnSummaryResult<T = any> = {
59
+ id: string;
60
+ value: T;
61
+ text: string;
62
+ css?: string;
63
+ };
64
+ /** Column dimensions are outer-box CSS pixels. */
65
+ export type ColumnConfig = {
66
+ [key: string]: any;
67
+ summaries?: ColumnSummaryConfig[];
34
68
  id: ColumnID;
35
69
  label: string;
36
70
  css?: string;
37
71
  metadata?: Record<string, any>;
38
- cardLimit?: number | boolean;
72
+ width?: number;
73
+ cardWidth?: number;
74
+ cardHeight?: number;
39
75
  addCard?: boolean;
76
+ /** Shows the header menu button for an outer `ContextMenu target="column"` (default `false`). */
77
+ menu?: boolean;
40
78
  collapsed?: boolean;
41
79
  };
42
- type ColumnView = {
80
+ /**
81
+ * Projected column: custom `ColumnConfig` fields pass through unchanged;
82
+ * `summaries`, `dataStatus` and `cards` are computed and override same-named config fields.
83
+ */
84
+ export type ColumnView = Omit<ColumnConfig, "summaries"> & {
85
+ width?: number;
86
+ cardWidth?: number;
87
+ cardHeight?: number;
43
88
  id: ColumnID;
44
89
  label: string;
45
90
  css?: string;
46
91
  metadata?: Record<string, any>;
47
- cardLimit?: number | boolean;
48
92
  addCard: boolean;
93
+ menu: boolean;
49
94
  collapsed: boolean;
50
- overLimit: boolean;
95
+ summaries: ColumnSummaryResult[];
51
96
  dataStatus: ColumnDataStatus;
52
97
  cards: KanbanCard[];
53
98
  };
54
99
  type KanbanModel$1 = {
55
100
  columns: ColumnView[];
101
+ swimlanes: SwimlaneView[];
56
102
  };
57
- type ColumnAccessor = string | {
103
+ export type ColumnAccessor = string | {
58
104
  get: (card: KanbanCard) => ColumnID;
59
105
  set: (card: KanbanCard, value: ColumnID) => KanbanCard;
60
106
  };
61
- type SortCriterion = ((a: KanbanCard, b: KanbanCard) => number) | {
107
+ export type SortCriterion = ((a: KanbanCard, b: KanbanCard) => number) | {
62
108
  field: string;
63
109
  dir?: "asc" | "desc";
64
110
  } | null;
65
- type FilterPredicate = (card: KanbanCard) => boolean;
66
- type State = {
111
+ export type FilterPredicate = (card: KanbanCard) => boolean;
112
+ export type State = {
67
113
  renderMode: string;
68
114
  cards: CardsStore;
69
115
  columns: ColumnConfig[];
70
116
  columnAccessor: ColumnAccessor;
117
+ swimlanes: SwimlaneConfig[];
118
+ swimlaneAccessor: SwimlaneAccessor;
71
119
  filters: Map<string, FilterPredicate>;
72
120
  sort: SortCriterion;
73
121
  editorData: KanbanCard | null;
@@ -76,21 +124,21 @@ type State = {
76
124
  history: HistoryState;
77
125
  viewData: KanbanModel$1;
78
126
  };
79
- type IData = State;
80
- type StateInput = Partial<Omit<State, "cards" | "columns" | "filters"> & {
127
+ export type IData = State;
128
+ export type StateInput = Partial<Omit<State, "cards" | "columns" | "filters"> & {
81
129
  cards: KanbanCard[] | CardsStore;
82
130
  columns: ColumnConfig[];
83
131
  filters: Map<string, FilterPredicate>;
84
132
  }>;
85
- type KanbanStoreOptions = {
133
+ export type KanbanStoreOptions = {
86
134
  undo?: boolean;
87
135
  };
88
- type HistoryState = {
136
+ export type HistoryState = {
89
137
  undo: number;
90
138
  redo: number;
91
139
  };
92
- type HistoryActionName = "add-card" | "update-card" | "move-card" | "duplicate-card" | "delete-card";
93
- type ExportConfig = {
140
+ export type HistoryActionName = "add-card" | "update-card" | "move-card" | "duplicate-card" | "delete-card";
141
+ export type ExportConfig = {
94
142
  url?: string | ((data: ExportConfig, records: KanbanCard[], helpers: ExportHelpers) => void);
95
143
  format?: string;
96
144
  fileName?: string;
@@ -120,23 +168,47 @@ type ExportConfig = {
120
168
  };
121
169
  data?: Record<string, any>;
122
170
  };
123
- type ExportHelpers = {
171
+ export type ExportHelpers = {
124
172
  post: (url: string, data: Record<string, string>) => void;
125
173
  serialize: (value: any) => string;
126
174
  };
127
- interface IKanbanStore {
175
+ export interface IKanbanStore {
128
176
  getState(): State;
129
177
  setState(state: StateInput, ctx?: any): any;
130
- pushUndo<A extends HistoryActionName>(action: A, ev: StoreActions[A]): void;
131
- undo(): void;
132
- redo(): void;
133
178
  resetHistory(): void;
134
179
  }
135
- interface StoreActions {
180
+ export interface StoreActions {
181
+ ["add-column"]: {
182
+ column: Partial<ColumnConfig>;
183
+ id?: ColumnID;
184
+ before?: ColumnID | null;
185
+ };
186
+ ["delete-column"]: {
187
+ id: ColumnID;
188
+ };
189
+ ["move-column"]: {
190
+ id: ColumnID;
191
+ before?: ColumnID | null;
192
+ };
193
+ ["add-swimlane"]: {
194
+ swimlane: Partial<SwimlaneConfig>;
195
+ id?: SwimlaneID;
196
+ before?: SwimlaneID | null;
197
+ };
198
+ ["delete-swimlane"]: {
199
+ id: SwimlaneID;
200
+ };
201
+ ["move-swimlane"]: {
202
+ id: SwimlaneID;
203
+ before?: SwimlaneID | null;
204
+ };
136
205
  ["add-card"]: {
137
206
  card: Partial<KanbanCard>;
138
207
  edit?: boolean;
139
208
  id?: CardID;
209
+ /** Insert before this card; `null` appends. Wins over `after`. */
210
+ before?: CardID | null;
211
+ /** Convenience hint, normalized to `before` by the handler. */
140
212
  after?: CardID;
141
213
  };
142
214
  ["update-card"]: {
@@ -146,11 +218,17 @@ interface StoreActions {
146
218
  ["move-card"]: {
147
219
  id: CardID;
148
220
  column?: ColumnID;
221
+ swimlane?: SwimlaneID;
149
222
  before?: CardID | null;
150
223
  };
224
+ ["update-swimlane"]: {
225
+ id: SwimlaneID;
226
+ swimlane: Partial<SwimlaneConfig>;
227
+ };
151
228
  ["update-column"]: {
152
229
  id: ColumnID;
153
230
  column: Partial<ColumnConfig>;
231
+ skipProvider?: boolean;
154
232
  };
155
233
  ["duplicate-card"]: {
156
234
  id: CardID;
@@ -183,16 +261,15 @@ interface StoreActions {
183
261
  }
184
262
  //#endregion
185
263
  //#region src/kanban_store.d.ts
186
- declare class KanbanStore extends Store<IData> {
264
+ export declare class KanbanStore extends Store<IData> {
187
265
  in: EventBus<StoreActions, keyof StoreActions>;
188
266
  meta: Record<string, any>;
267
+ _autoColumns: boolean;
268
+ _autoSwimlanes: boolean;
189
269
  private _router;
190
270
  constructor(w: TWritableCreator, options?: KanbanStoreOptions);
191
271
  init(state: StateInput): void;
192
272
  getCards(): KanbanCard[];
193
- pushUndo<A extends HistoryActionName>(action: A, ev: StoreActions[A]): void;
194
- undo(): void;
195
- redo(): void;
196
273
  resetHistory(): void;
197
274
  getBrandmark(): Brandmark | null;
198
275
  setState(state: Partial<IData>, ctx?: TDataConfig): {
@@ -201,22 +278,28 @@ declare class KanbanStore extends Store<IData> {
201
278
  }
202
279
  //#endregion
203
280
  //#region src/model.d.ts
204
- declare class KanbanModel implements KanbanModel$1 {
281
+ export declare class KanbanModel implements KanbanModel$1 {
205
282
  columns: ColumnView[];
283
+ swimlanes: SwimlaneView[];
206
284
  constructor(data?: Partial<KanbanModel$1>);
207
285
  }
208
286
  //#endregion
209
287
  //#region src/locale/index.d.ts
210
- declare function locale(initialData: any): {
288
+ export declare function locale(initialData: any): {
211
289
  data: any;
212
290
  _(key: string): any;
213
291
  __(group: string, key: string): any;
214
292
  getGroup(group: string): (key: string) => any;
215
- extend(values: any): /*elided*/any;
293
+ extend(values: any): /*elided*/ any;
216
294
  };
217
295
  //#endregion
218
296
  //#region src/constants.d.ts
219
- declare function getMenuOptions(): {
297
+ export declare function getMenuOptions(): {
298
+ id: string;
299
+ text: string;
300
+ icon: string;
301
+ }[];
302
+ export declare function getColumnMenuOptions(): {
220
303
  id: string;
221
304
  text: string;
222
305
  icon: string;
@@ -226,6 +309,16 @@ type ToolbarButtonConfig = {
226
309
  undo?: boolean;
227
310
  sort?: boolean;
228
311
  };
229
- declare function getToolbarItems(config?: ToolbarButtonConfig): any[];
312
+ export declare function getToolbarItems(config?: ToolbarButtonConfig): any[];
313
+ //#endregion
314
+ //#region src/accessor.d.ts
315
+ export declare function readMembership(card: KanbanCard, accessor: ColumnAccessor): ColumnID;
316
+ export declare function writeMembership(card: KanbanCard, accessor: ColumnAccessor, value: ColumnID): KanbanCard;
317
+ //#endregion
318
+ //#region src/kanban_reactive.d.ts
319
+ export declare function collectGroups(cards: KanbanCard[], accessor: ColumnAccessor): {
320
+ id: ColumnID;
321
+ label: string;
322
+ }[];
230
323
  //#endregion
231
- export { Brandmark, CardID, CardsStore, ColumnAccessor, ColumnConfig, ColumnDataState, ColumnDataStatus, ColumnID, ColumnView, ExportConfig, ExportHelpers, FilterPredicate, HistoryActionName, HistoryState, IData, IKanbanStore, KanbanCard, KanbanModel, KanbanStore, KanbanStoreOptions, SortCriterion, State, StateInput, StoreActions, type ToolbarButtonConfig, getMenuOptions, getToolbarItems, locale };
324
+ export type { ToolbarButtonConfig };
package/dist/index.mjs CHANGED
@@ -21,6 +21,15 @@ var CardsStore = class {
21
21
  else this._cards.splice(index + 1, 0, next);
22
22
  return next;
23
23
  }
24
+ /** Inserts before the anchor, or appends when it is null or unknown. */
25
+ addBefore(card, before) {
26
+ this._assertHasId(card);
27
+ const next = { ...card };
28
+ const index = before === null ? -1 : this._cards.findIndex((item) => item.id === before);
29
+ if (index === -1) this._cards.push(next);
30
+ else this._cards.splice(index, 0, next);
31
+ return next;
32
+ }
24
33
  update(id, patch) {
25
34
  const index = this._cards.findIndex((card) => card.id === id);
26
35
  if (index === -1) return;
@@ -69,36 +78,120 @@ var CardsStore = class {
69
78
  //#region src/model.ts
70
79
  var KanbanModel = class {
71
80
  columns;
81
+ swimlanes;
72
82
  constructor(data = {}) {
73
- this.columns = data.columns || [];
83
+ this.columns = data.columns ?? [];
84
+ this.swimlanes = data.swimlanes ?? [];
74
85
  }
75
86
  };
76
87
 
88
+ //#endregion
89
+ //#region src/actions/add-column.ts
90
+ function add_column_default(store, ev) {
91
+ const { columns } = store.getState();
92
+ const id = ev.id ?? ev.column.id ?? tempID();
93
+ ev.id = id;
94
+ if (columns.some((group) => group.id === id)) return;
95
+ const next = columns.slice();
96
+ const index = next.findIndex((group) => group.id === ev.before);
97
+ const group = {
98
+ label: String(id),
99
+ ...ev.column,
100
+ id
101
+ };
102
+ next.splice(index < 0 ? next.length : index, 0, group);
103
+ ev.column = group;
104
+ store.setState({ columns: next });
105
+ store.resetHistory();
106
+ }
107
+
108
+ //#endregion
109
+ //#region src/actions/delete-column.ts
110
+ function delete_column_default(store, ev) {
111
+ const { columns } = store.getState();
112
+ const index = columns.findIndex((group) => group.id === ev.id);
113
+ if (index < 0) return;
114
+ const next = columns.slice();
115
+ next.splice(index, 1);
116
+ store.setState({ columns: next });
117
+ store.resetHistory();
118
+ }
119
+
120
+ //#endregion
121
+ //#region src/actions/move-column.ts
122
+ function move_column_default(store, ev) {
123
+ const { columns } = store.getState();
124
+ const index = columns.findIndex((group) => group.id === ev.id);
125
+ if (index < 0 || ev.id === ev.before) return;
126
+ const next = columns.slice();
127
+ const [group] = next.splice(index, 1);
128
+ const anchor = next.findIndex((item) => item.id === ev.before);
129
+ const at = anchor < 0 ? next.length : anchor;
130
+ if (at === index) return;
131
+ next.splice(at, 0, group);
132
+ store.setState({ columns: next });
133
+ store.resetHistory();
134
+ }
135
+
136
+ //#endregion
137
+ //#region src/accessor.ts
138
+ function readMembership(card, accessor) {
139
+ return typeof accessor === "string" ? card[accessor] : accessor.get(card);
140
+ }
141
+ function writeMembership(card, accessor, value) {
142
+ return typeof accessor === "string" ? {
143
+ ...card,
144
+ [accessor]: value
145
+ } : accessor.set({ ...card }, value);
146
+ }
147
+
77
148
  //#endregion
78
149
  //#region src/actions/add-card.ts
79
150
  function add_card_default(store, ev) {
80
- const { cards, columns, columnAccessor } = store.getState();
151
+ const state = store.getState();
152
+ const { cards, columns, columnAccessor } = state;
81
153
  let card = {
82
154
  ...ev.card,
83
155
  id: ev.id ?? ev.card.id ?? tempID()
84
156
  };
85
- const columnId = readColumn$1(card, columnAccessor);
86
- if (!columns.some((column) => column.id === columnId) && columns.length) card = writeColumn$2(card, columnAccessor, columns[0].id);
87
- const added = cards.add(card, ev.after);
157
+ const columnId = readMembership(card, columnAccessor);
158
+ if (!columns.some((column) => column.id === columnId) && columns.length) card = writeMembership(card, columnAccessor, columns[0].id);
159
+ if (state.swimlanes.length && !state.swimlanes.some((lane) => lane.id === readMembership(card, state.swimlaneAccessor))) card = writeMembership(card, state.swimlaneAccessor, state.swimlanes[0].id);
160
+ const before = resolveBefore(state, card, ev);
161
+ if (before === false) return false;
162
+ ev.before = before;
163
+ const added = cards.addBefore(card, before);
164
+ const payload = { ...added };
165
+ if (ev.card.id === void 0) delete payload.id;
166
+ ev.card = payload;
88
167
  ev.id = added.id;
89
168
  store.setState({
90
169
  cards,
91
170
  ...ev.edit ? { editorData: { ...added } } : {}
92
171
  });
93
172
  }
94
- function readColumn$1(card, accessor) {
95
- return typeof accessor === "string" ? card[accessor] : accessor.get(card);
96
- }
97
- function writeColumn$2(card, accessor, column) {
98
- return typeof accessor === "string" ? {
99
- ...card,
100
- [accessor]: column
101
- } : accessor.set(card, column);
173
+ /**
174
+ * Canonical insertion anchor in source order: explicit `before` wins, `after`
175
+ * becomes its successor in the destination column, otherwise append. Order is
176
+ * per column; swimlanes only filter it. Returns false for an anchor in another
177
+ * column.
178
+ */
179
+ function resolveBefore(state, card, ev) {
180
+ const { cards, columnAccessor } = state;
181
+ const column = readMembership(card, columnAccessor);
182
+ const sameColumn = (other) => readMembership(other, columnAccessor) === column;
183
+ if (ev.before !== void 0) {
184
+ if (ev.before === null) return null;
185
+ const anchor = cards.getById(ev.before);
186
+ return anchor && sameColumn(anchor) ? anchor.id : false;
187
+ }
188
+ if (ev.after === void 0) return null;
189
+ const source = cards.getCards();
190
+ const index = source.findIndex((item) => item.id === ev.after);
191
+ if (index === -1) return null;
192
+ if (!sameColumn(source[index])) return false;
193
+ for (let i = index + 1; i < source.length; i++) if (sameColumn(source[i])) return source[i].id;
194
+ return null;
102
195
  }
103
196
 
104
197
  //#endregion
@@ -111,36 +204,35 @@ function update_card_default(store, ev) {
111
204
  //#endregion
112
205
  //#region src/actions/move-card.ts
113
206
  function move_card_default(store, ev) {
114
- const { cards, columns, columnAccessor } = store.getState();
207
+ const { cards, columns, columnAccessor, swimlanes, swimlaneAccessor } = store.getState();
115
208
  const card = cards.getById(ev.id);
116
- if (!card) return;
117
- const currentColumn = readColumn(card, columnAccessor);
118
- const targetColumn = ev.column ?? currentColumn;
119
- if (ev.column !== void 0 && !columns.some((column) => column.id === targetColumn)) return;
120
- if (ev.before != null) {
121
- const beforeCard = cards.getById(ev.before);
122
- const beforeColumn = ev.before === ev.id ? targetColumn : beforeCard && readColumn(beforeCard, columnAccessor);
123
- if (!beforeCard || beforeColumn !== targetColumn) return;
124
- }
125
- if (targetColumn !== currentColumn) {
126
- const nextCard = writeColumn$1(card, columnAccessor, targetColumn);
127
- cards.update(ev.id, nextCard);
209
+ if (!card) return false;
210
+ const hasSwimlanes = swimlanes.length > 0;
211
+ const column = ev.column ?? readMembership(card, columnAccessor);
212
+ const lane = ev.swimlane ?? readMembership(card, swimlaneAccessor);
213
+ if (ev.column !== void 0 && !columns.some((c) => c.id === column)) return false;
214
+ if (ev.swimlane !== void 0 && !swimlanes.some((l) => l.id === lane)) return false;
215
+ if (ev.before != null && ev.before !== ev.id) {
216
+ const before = cards.getById(ev.before);
217
+ if (!before || readMembership(before, columnAccessor) !== column) return false;
128
218
  }
219
+ let next = card;
220
+ if (column !== readMembership(card, columnAccessor)) next = writeMembership(next, columnAccessor, column);
221
+ if (hasSwimlanes && lane !== readMembership(card, swimlaneAccessor)) next = writeMembership(next, swimlaneAccessor, lane);
222
+ if (readMembership(next, columnAccessor) !== column || hasSwimlanes && readMembership(next, swimlaneAccessor) !== lane) return false;
223
+ if (next !== card) cards.update(ev.id, {
224
+ ...next,
225
+ id: ev.id
226
+ });
129
227
  if (cards.move(ev.id, ev.before)) store.setState({ cards });
130
228
  }
131
- function readColumn(card, accessor) {
132
- return typeof accessor === "string" ? card[accessor] : accessor.get(card);
133
- }
134
- function writeColumn$1(card, accessor, column) {
135
- return typeof accessor === "string" ? { [accessor]: column } : accessor.set(card, column);
136
- }
137
229
 
138
230
  //#endregion
139
231
  //#region src/actions/duplicate-card.ts
140
232
  function duplicate_card_default(store, ev) {
141
233
  const { cards } = store.getState();
142
234
  const source = cards.getById(ev.id);
143
- if (!source) return;
235
+ if (!source) return false;
144
236
  const duplicate = {
145
237
  ...source,
146
238
  ...ev.card,
@@ -195,11 +287,13 @@ function filter_cards_default(store, ev = {}) {
195
287
  const hasFilter = Object.prototype.hasOwnProperty.call(ev, "filter");
196
288
  const hasTag = Object.prototype.hasOwnProperty.call(ev, "tag");
197
289
  const tag = ev.tag ?? "_default";
198
- if (!hasFilter) if (hasTag) filters.delete(tag);
199
- else filters.clear();
200
- else if (ev.filter == null) if (hasTag) filters.delete(tag);
201
- else filters.clear();
202
- else filters.set(tag, ev.filter);
290
+ if (!hasFilter) {
291
+ if (hasTag) filters.delete(tag);
292
+ else filters.clear();
293
+ } else if (ev.filter == null) {
294
+ if (hasTag) filters.delete(tag);
295
+ else filters.clear();
296
+ } else filters.set(tag, ev.filter);
203
297
  store.setState({ filters });
204
298
  }
205
299
 
@@ -214,10 +308,10 @@ function sort_cards_default(store, ev = {}) {
214
308
  //#region src/actions/provide-data.ts
215
309
  function provide_data_default(store, ev) {
216
310
  const { cards, columns, columnAccessor, columnData } = store.getState();
217
- if (ev.id) {
311
+ if (ev.id !== void 0) {
218
312
  if (!columns.some((column) => column.id === ev.id)) return;
219
313
  ev.cards.forEach((card) => {
220
- cards.upsert(writeColumn(card, columnAccessor, ev.id));
314
+ cards.upsert(writeMembership(card, columnAccessor, ev.id));
221
315
  });
222
316
  const next = new Map(columnData);
223
317
  next.set(ev.id, { status: "loaded" });
@@ -232,16 +326,13 @@ function provide_data_default(store, ev) {
232
326
  store.setState({ cards });
233
327
  }
234
328
  }
235
- function writeColumn(card, accessor, column) {
236
- return typeof accessor === "string" ? {
237
- ...card,
238
- [accessor]: column
239
- } : accessor.set(card, column);
240
- }
241
329
 
242
330
  //#endregion
243
331
  //#region src/actions/index.ts
244
332
  function init(inBus, store) {
333
+ inBus.on("add-column", (params) => add_column_default(store, params));
334
+ inBus.on("delete-column", (params) => delete_column_default(store, params));
335
+ inBus.on("move-column", (params) => move_column_default(store, params));
245
336
  inBus.on("add-card", (params) => add_card_default(store, params));
246
337
  inBus.on("update-card", (params) => update_card_default(store, params));
247
338
  inBus.on("move-card", (params) => move_card_default(store, params));
@@ -256,12 +347,40 @@ function init(inBus, store) {
256
347
 
257
348
  //#endregion
258
349
  //#region src/kanban_reactive.ts
350
+ const laneFilter = (_) => null;
351
+ const projectSwimlanes = (_, __) => [];
259
352
  function reactive(store) {
353
+ let fallbackColumn = false;
260
354
  return [{
355
+ in: [
356
+ "cards",
357
+ "columnAccessor",
358
+ "swimlaneAccessor"
359
+ ],
360
+ out: ["columns", "swimlanes"],
361
+ exec: (ctx) => {
362
+ const { cards, columnAccessor, swimlaneAccessor } = store.getState();
363
+ const next = {};
364
+ fallbackColumn = false;
365
+ if (store._autoColumns) {
366
+ next.columns = collectGroups(cards.getCards(), columnAccessor);
367
+ if (!next.columns.length) {
368
+ fallbackColumn = true;
369
+ next.columns = [{
370
+ id: "",
371
+ label: ""
372
+ }];
373
+ }
374
+ }
375
+ store.setState(next, ctx);
376
+ }
377
+ }, {
261
378
  in: [
262
379
  "cards",
263
380
  "columns",
264
381
  "columnAccessor",
382
+ "swimlanes",
383
+ "swimlaneAccessor",
265
384
  "filters",
266
385
  "sort",
267
386
  "dynamicData",
@@ -269,31 +388,48 @@ function reactive(store) {
269
388
  ],
270
389
  out: ["viewData"],
271
390
  exec: () => {
272
- store.setState({ viewData: projectKanbanModel(store.getState()) });
391
+ store.setState({ viewData: projectKanbanModel(store.getState(), fallbackColumn) });
273
392
  }
274
393
  }];
275
394
  }
276
- function projectKanbanModel(state) {
395
+ function collectGroups(cards, accessor) {
396
+ const ids = /* @__PURE__ */ new Set();
397
+ for (const card of cards) {
398
+ const id = readMembership(card, accessor);
399
+ if (typeof id === "string" || typeof id === "number") ids.add(id);
400
+ }
401
+ return Array.from(ids, (id) => ({
402
+ id,
403
+ label: String(id)
404
+ }));
405
+ }
406
+ function projectKanbanModel(state, fallbackColumn = false) {
277
407
  const { cards, columns, columnAccessor, filters, sort, dynamicData, columnData } = state;
278
408
  const getColumn = getColumnReader(columnAccessor);
409
+ const inLane = laneFilter(state);
279
410
  const buckets = /* @__PURE__ */ new Map();
280
411
  const knownColumns = new Set(columns.map((column) => column.id));
281
412
  columns.forEach((column) => {
282
413
  buckets.set(column.id, []);
283
414
  });
284
415
  cards.getCards().forEach((card) => {
285
- const columnId = getColumn(card);
286
- if (knownColumns.has(columnId)) buckets.get(columnId).push(card);
416
+ const columnId = fallbackColumn ? "" : getColumn(card);
417
+ if (knownColumns.has(columnId) && (!inLane || inLane(card))) buckets.get(columnId).push(card);
287
418
  });
288
419
  const predicates = Array.from(filters.values());
289
420
  const compare = getComparator(sort);
290
- return new KanbanModel({ columns: columns.map((column) => {
421
+ const columnViews = columns.map((column) => {
291
422
  let columnCards = buckets.get(column.id) || [];
292
423
  if (predicates.length) columnCards = columnCards.filter((card) => predicates.every((predicate) => predicate(card)));
293
424
  else columnCards = columnCards.slice();
294
425
  if (compare) columnCards.sort(compare);
295
426
  return toColumnView(column, columnCards, getColumnStatus(dynamicData, columnData, column.id));
296
- }) });
427
+ });
428
+ const laneViews = inLane ? projectSwimlanes(state, columnViews) : [];
429
+ return new KanbanModel({
430
+ columns: columnViews,
431
+ swimlanes: laneViews
432
+ });
297
433
  }
298
434
  function getColumnReader(accessor) {
299
435
  return typeof accessor === "string" ? (card) => card[accessor] : accessor.get;
@@ -317,26 +453,51 @@ function getColumnStatus(dynamicData, columnData, id) {
317
453
  return dynamicData ? columnData.get(id)?.status ?? "unknown" : "loaded";
318
454
  }
319
455
  function toColumnView(column, cards, dataStatus) {
456
+ const { summaries: _summaries, width, cardWidth, cardHeight, ...custom } = column;
320
457
  const view = {
458
+ ...custom,
321
459
  id: column.id,
322
460
  label: column.label,
323
461
  collapsed: column.collapsed ?? false,
324
462
  addCard: column.addCard !== false,
325
- overLimit: typeof column.cardLimit === "number" && cards.length > column.cardLimit,
463
+ menu: column.menu === true,
464
+ summaries: calculateSummaries(column, cards),
326
465
  dataStatus,
327
466
  cards
328
467
  };
329
- if (column.css !== void 0) view.css = column.css;
330
- if (column.metadata !== void 0) view.metadata = column.metadata;
331
- if (column.cardLimit !== void 0) view.cardLimit = column.cardLimit;
468
+ if (width) view.width = width;
332
469
  return view;
333
470
  }
471
+ function calculateSummaries(column, cards) {
472
+ const results = [];
473
+ if (!cards.length) return results;
474
+ for (const summary of column.summaries ?? []) try {
475
+ const value = summary.calculate(cards, column);
476
+ if (value === null || value === void 0) continue;
477
+ const formatted = summary.format ? summary.format(value, column) : value;
478
+ if (formatted === null || formatted === void 0) continue;
479
+ const text = String(formatted);
480
+ if (text.trim() === "") continue;
481
+ const css = summary.css?.(value, column);
482
+ results.push({
483
+ id: summary.id,
484
+ value,
485
+ text,
486
+ ...css ? { css } : {}
487
+ });
488
+ } catch (error) {
489
+ console.error(`Kanban summary "${summary.id}" failed for column "${column.id}"`, error);
490
+ }
491
+ return results;
492
+ }
334
493
 
335
494
  //#endregion
336
495
  //#region src/kanban_store.ts
337
496
  var KanbanStore = class extends Store {
338
497
  in;
339
498
  meta;
499
+ _autoColumns = false;
500
+ _autoSwimlanes = false;
340
501
  _router;
341
502
  constructor(w, options) {
342
503
  super({
@@ -345,13 +506,16 @@ var KanbanStore = class extends Store {
345
506
  });
346
507
  this.meta = {};
347
508
  this._router = new DataRouter(super.setState.bind(this), reactive(this), {
348
- columns: (v) => [...v],
509
+ columns: (v) => [...v ?? []],
510
+ swimlanes: (v) => v?.map((lane) => ({ ...lane })) ?? [],
349
511
  cards: (v) => new CardsStore(v)
350
512
  });
351
513
  super.setState({
352
514
  cards: new CardsStore([]),
353
515
  columns: [],
354
516
  columnAccessor: "column",
517
+ swimlanes: [],
518
+ swimlaneAccessor: "swimlane",
355
519
  filters: /* @__PURE__ */ new Map(),
356
520
  sort: null,
357
521
  editorData: null,
@@ -363,26 +527,18 @@ var KanbanStore = class extends Store {
363
527
  },
364
528
  viewData: new KanbanModel({ columns: [] })
365
529
  });
366
- init(this.in = new EventBus(), this);
530
+ const inBus = this.in = new EventBus();
531
+ init(inBus, this);
367
532
  }
368
533
  init(state) {
534
+ this._autoColumns = state.columns === void 0;
535
+ this._autoSwimlanes = state.swimlanes === void 0;
369
536
  this._router.init(state);
370
537
  }
371
538
  getCards() {
372
539
  return this.getState().cards.getCards();
373
540
  }
374
- pushUndo(action, ev) {
375
- this._history.pushUndo(action, ev);
376
- }
377
- undo() {
378
- this._history.undo();
379
- }
380
- redo() {
381
- this._history.redo();
382
- }
383
- resetHistory() {
384
- this._history.reset();
385
- }
541
+ resetHistory() {}
386
542
  getBrandmark() {
387
543
  return null;
388
544
  }
@@ -442,6 +598,13 @@ function getMenuOptions() {
442
598
  }
443
599
  ];
444
600
  }
601
+ function getColumnMenuOptions() {
602
+ return [{
603
+ id: "add-card",
604
+ text: "Add card",
605
+ icon: "wxi-plus"
606
+ }];
607
+ }
445
608
  function getToolbarItems(config) {
446
609
  const items = [];
447
610
  if (config?.add) {
@@ -509,4 +672,4 @@ function getToolbarItems(config) {
509
672
  }
510
673
 
511
674
  //#endregion
512
- export { CardsStore, KanbanModel, KanbanStore, getMenuOptions, getToolbarItems, locale };
675
+ export { CardsStore, KanbanModel, KanbanStore, collectGroups, getColumnMenuOptions, getMenuOptions, getToolbarItems, locale, readMembership, writeMembership };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@svar-ui/kanban-store",
3
- "version": "2.6.0",
3
+ "version": "2.7.0",
4
4
  "description": "State and models for SVAR Kanban",
5
5
  "homepage": "https://svar.dev",
6
6
  "license": "MIT",
@@ -21,14 +21,14 @@
21
21
  "access": "public"
22
22
  },
23
23
  "dependencies": {
24
- "@svar-ui/lib-dom": "0.13.1",
24
+ "@svar-ui/lib-dom": "0.14.0",
25
25
  "@svar-ui/lib-state": "1.9.7"
26
26
  },
27
27
  "devDependencies": {
28
28
  "@svar-ui/lib-state": "1.9.7",
29
29
  "@typescript/native-preview": "7.0.0-dev.20260316.1",
30
30
  "typescript": "^5.9.3",
31
- "vite-plus": "0.1.16"
31
+ "vite-plus": "1.1.0"
32
32
  },
33
33
  "scripts": {
34
34
  "build": "vp pack",