@mosaicoo/kanban 0.1.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/LICENSE +201 -0
- package/README.md +44 -0
- package/fesm2022/mosaicoo-kanban-adapters.mjs +417 -0
- package/fesm2022/mosaicoo-kanban-core.mjs +1483 -0
- package/fesm2022/mosaicoo-kanban-ui.mjs +2299 -0
- package/fesm2022/mosaicoo-kanban.mjs +13 -0
- package/package.json +60 -0
- package/styles/kanban-tokens.css +66 -0
- package/types/mosaicoo-kanban-adapters.d.ts +166 -0
- package/types/mosaicoo-kanban-core.d.ts +689 -0
- package/types/mosaicoo-kanban-ui.d.ts +538 -0
- package/types/mosaicoo-kanban.d.ts +2 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for describing the origin of the Work and
|
|
141
|
+
reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright 2026 Mosaicoo
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
200
|
+
implied. See the License for the specific language governing
|
|
201
|
+
permissions and limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
# @mosaicoo/kanban
|
|
2
|
+
|
|
3
|
+
> Flexible board engine and Angular UI for Kanban-style visual organization —
|
|
4
|
+
> configurable columns, swimlanes and dynamic grouping, powered by a headless,
|
|
5
|
+
> zero-dependency core.
|
|
6
|
+
|
|
7
|
+
**Status: pre-release (0.x).** The API is under active construction; see the
|
|
8
|
+
[roadmap](https://github.com/mosaicoo/mosaicoo-kanban/blob/main/docs/01-arquitetura.md).
|
|
9
|
+
|
|
10
|
+
## What it is
|
|
11
|
+
|
|
12
|
+
A professional board component that works as a classic Kanban out of the box,
|
|
13
|
+
yet is configurable enough to represent any stage/row/column/grouping-based
|
|
14
|
+
visual model — port lineups, sales pipelines, operational queues — **without
|
|
15
|
+
any business rule living in its core**.
|
|
16
|
+
|
|
17
|
+
- **`@mosaicoo/kanban/core`** — headless engine in pure TypeScript with
|
|
18
|
+
**zero dependencies** (no Angular, no DOM, no RxJS): models, immutable
|
|
19
|
+
state, commands, movement rules, grouping, sorting, events, undo/redo.
|
|
20
|
+
- **`@mosaicoo/kanban/ui`** — Angular standalone components: board, columns,
|
|
21
|
+
swimlanes, cards, drag and drop, accessibility.
|
|
22
|
+
- **`@mosaicoo/kanban/adapters`** — persistence/real-time contracts. The
|
|
23
|
+
library never persists anything on its own; the host provides the adapter.
|
|
24
|
+
|
|
25
|
+
## Design principles
|
|
26
|
+
|
|
27
|
+
1. **Progressive configuration** — a simple Kanban takes ~10 lines; advanced
|
|
28
|
+
features are opt-in.
|
|
29
|
+
2. **Serializable config** — the whole board definition is JSON: it can be
|
|
30
|
+
edited by a host configuration screen and stored in a database. Custom code
|
|
31
|
+
plugs in through a named registry, never inline functions.
|
|
32
|
+
3. **Domains are data** — classic Kanban, port lineup, real-estate pipeline
|
|
33
|
+
are config templates, not code.
|
|
34
|
+
4. **Theming by design tokens** — every visual detail reads `--mkb-*` custom
|
|
35
|
+
properties with a fallback chain, so it inherits the Mosaicoo Design System
|
|
36
|
+
automatically when embedded, and ships its own default theme elsewhere
|
|
37
|
+
(`import '@mosaicoo/kanban/styles/kanban-tokens.css'`).
|
|
38
|
+
5. **Instance hygiene** — no global state, no module stores: multiple boards
|
|
39
|
+
(or tenants, at the host's discretion) never leak into each other.
|
|
40
|
+
|
|
41
|
+
## License & repository
|
|
42
|
+
|
|
43
|
+
Developed by [Mosaicoo](https://github.com/mosaicoo). Source, docs (pt-BR) and
|
|
44
|
+
demos: [mosaicoo/mosaicoo-kanban](https://github.com/mosaicoo/mosaicoo-kanban).
|
|
@@ -0,0 +1,417 @@
|
|
|
1
|
+
import { createBoard } from '@mosaicoo/kanban/core';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Liga um board a um adapter (docs/01 §7):
|
|
5
|
+
*
|
|
6
|
+
* - FLUXO OTIMISTA: cada after:* vira um KanbanChange e entra numa FILA
|
|
7
|
+
* sequencial de persist (ordem garantida); rejeição → rollback automático
|
|
8
|
+
* via applyRemote (fora do histórico de undo) + onPersistError.
|
|
9
|
+
* - TEMPO REAL: se o adapter tem connect(), eventos remotos entram como
|
|
10
|
+
* applyRemote — não disparam persist (sem eco), não entram no undo local
|
|
11
|
+
* e não passam por regras/permissões (last-write-wins, o evento já
|
|
12
|
+
* aconteceu na origem).
|
|
13
|
+
*
|
|
14
|
+
* Retorna a função que desliga tudo (chamar antes de board.destroy()).
|
|
15
|
+
*/
|
|
16
|
+
function bindAdapter(board, adapter, options = {}) {
|
|
17
|
+
/** true enquanto aplicamos rollback/remoto: os after:* desse trecho são
|
|
18
|
+
* nossos, não do usuário — não devem voltar ao adapter. */
|
|
19
|
+
let applying = false;
|
|
20
|
+
let queue = Promise.resolve();
|
|
21
|
+
const applySilently = (command) => {
|
|
22
|
+
applying = true;
|
|
23
|
+
try {
|
|
24
|
+
board.applyRemote(command);
|
|
25
|
+
}
|
|
26
|
+
finally {
|
|
27
|
+
applying = false;
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
const rollback = (change) => {
|
|
31
|
+
switch (change.type) {
|
|
32
|
+
case 'move':
|
|
33
|
+
applySilently({
|
|
34
|
+
type: 'moveItem',
|
|
35
|
+
itemId: change.item.id,
|
|
36
|
+
to: { column: change.from.column, lane: change.from.lane },
|
|
37
|
+
});
|
|
38
|
+
break;
|
|
39
|
+
case 'add':
|
|
40
|
+
applySilently({ type: 'removeItem', itemId: change.item.id });
|
|
41
|
+
break;
|
|
42
|
+
case 'update': {
|
|
43
|
+
const previousValues = {};
|
|
44
|
+
for (const key of Object.keys(change.changes)) {
|
|
45
|
+
previousValues[key] = change.previous[key];
|
|
46
|
+
}
|
|
47
|
+
applySilently({
|
|
48
|
+
type: 'updateItem',
|
|
49
|
+
itemId: change.item.id,
|
|
50
|
+
changes: previousValues,
|
|
51
|
+
});
|
|
52
|
+
break;
|
|
53
|
+
}
|
|
54
|
+
case 'remove':
|
|
55
|
+
applySilently({ type: 'addItem', item: change.item });
|
|
56
|
+
break;
|
|
57
|
+
case 'move-group':
|
|
58
|
+
applySilently({
|
|
59
|
+
type: 'moveGroup',
|
|
60
|
+
axis: change.axis,
|
|
61
|
+
groupId: change.groupId,
|
|
62
|
+
index: change.from, // reverte para a posição original
|
|
63
|
+
});
|
|
64
|
+
break;
|
|
65
|
+
case 'move-entry':
|
|
66
|
+
applySilently({
|
|
67
|
+
type: 'moveEntry',
|
|
68
|
+
cardId: change.to.cardId,
|
|
69
|
+
field: change.to.field,
|
|
70
|
+
entryId: change.entry.id,
|
|
71
|
+
index: change.from.index,
|
|
72
|
+
toCardId: change.from.cardId,
|
|
73
|
+
toField: change.from.field,
|
|
74
|
+
});
|
|
75
|
+
break;
|
|
76
|
+
case 'update-entry':
|
|
77
|
+
if (change.op === 'add') {
|
|
78
|
+
applySilently({
|
|
79
|
+
type: 'removeEntry',
|
|
80
|
+
cardId: change.cardId,
|
|
81
|
+
field: change.field,
|
|
82
|
+
entryId: change.entry.id,
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
else if (change.op === 'remove') {
|
|
86
|
+
applySilently({
|
|
87
|
+
type: 'addEntry',
|
|
88
|
+
cardId: change.cardId,
|
|
89
|
+
field: change.field,
|
|
90
|
+
entry: change.entry,
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
else {
|
|
94
|
+
const previousValues = {};
|
|
95
|
+
for (const key of Object.keys(change.changes ?? {})) {
|
|
96
|
+
previousValues[key] = change.previous?.[key];
|
|
97
|
+
}
|
|
98
|
+
applySilently({
|
|
99
|
+
type: 'updateEntry',
|
|
100
|
+
cardId: change.cardId,
|
|
101
|
+
field: change.field,
|
|
102
|
+
entryId: change.entry.id,
|
|
103
|
+
changes: previousValues,
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
break;
|
|
107
|
+
}
|
|
108
|
+
};
|
|
109
|
+
const persist = (change) => {
|
|
110
|
+
if (applying)
|
|
111
|
+
return;
|
|
112
|
+
queue = queue
|
|
113
|
+
.then(() => adapter.persist(change))
|
|
114
|
+
.catch((error) => {
|
|
115
|
+
if (options.rollbackOnError !== false)
|
|
116
|
+
rollback(change);
|
|
117
|
+
options.onPersistError?.(error, change);
|
|
118
|
+
});
|
|
119
|
+
};
|
|
120
|
+
const snapshot = () => board.state.items;
|
|
121
|
+
const offs = [
|
|
122
|
+
board.on('after:move', (ev) => persist({ type: 'move', item: ev.item, from: ev.from, to: ev.to, items: snapshot() })),
|
|
123
|
+
board.on('after:add', (ev) => persist({ type: 'add', item: ev.item, items: snapshot() })),
|
|
124
|
+
board.on('after:update', (ev) => persist({
|
|
125
|
+
type: 'update',
|
|
126
|
+
item: ev.item,
|
|
127
|
+
previous: ev.previous,
|
|
128
|
+
changes: ev.changes,
|
|
129
|
+
items: snapshot(),
|
|
130
|
+
})),
|
|
131
|
+
board.on('after:remove', (ev) => persist({ type: 'remove', item: ev.item, items: snapshot() })),
|
|
132
|
+
board.on('after:group-move', (ev) => persist({
|
|
133
|
+
type: 'move-group',
|
|
134
|
+
axis: ev.axis,
|
|
135
|
+
groupId: ev.groupId,
|
|
136
|
+
from: ev.from,
|
|
137
|
+
to: ev.to,
|
|
138
|
+
order: ev.order,
|
|
139
|
+
items: snapshot(),
|
|
140
|
+
})),
|
|
141
|
+
board.on('after:entry-move', (ev) => persist({
|
|
142
|
+
type: 'move-entry',
|
|
143
|
+
entry: ev.entry,
|
|
144
|
+
from: ev.from,
|
|
145
|
+
to: ev.to,
|
|
146
|
+
items: snapshot(),
|
|
147
|
+
})),
|
|
148
|
+
board.on('after:entry-update', (ev) => persist({
|
|
149
|
+
type: 'update-entry',
|
|
150
|
+
op: ev.op,
|
|
151
|
+
cardId: ev.cardId,
|
|
152
|
+
field: ev.field,
|
|
153
|
+
entry: ev.entry,
|
|
154
|
+
previous: ev.previous,
|
|
155
|
+
changes: ev.changes,
|
|
156
|
+
items: snapshot(),
|
|
157
|
+
})),
|
|
158
|
+
];
|
|
159
|
+
const offConnect = adapter.connect?.((change) => {
|
|
160
|
+
switch (change.type) {
|
|
161
|
+
case 'move':
|
|
162
|
+
applySilently({
|
|
163
|
+
type: 'moveItem',
|
|
164
|
+
itemId: change.item.id,
|
|
165
|
+
to: { column: change.to.column, lane: change.to.lane },
|
|
166
|
+
});
|
|
167
|
+
break;
|
|
168
|
+
case 'add':
|
|
169
|
+
applySilently({ type: 'addItem', item: change.item });
|
|
170
|
+
break;
|
|
171
|
+
case 'update':
|
|
172
|
+
applySilently({
|
|
173
|
+
type: 'updateItem',
|
|
174
|
+
itemId: change.item.id,
|
|
175
|
+
changes: change.changes,
|
|
176
|
+
});
|
|
177
|
+
break;
|
|
178
|
+
case 'remove':
|
|
179
|
+
applySilently({ type: 'removeItem', itemId: change.item.id });
|
|
180
|
+
break;
|
|
181
|
+
case 'move-group':
|
|
182
|
+
applySilently({
|
|
183
|
+
type: 'moveGroup',
|
|
184
|
+
axis: change.axis,
|
|
185
|
+
groupId: change.groupId,
|
|
186
|
+
index: change.to,
|
|
187
|
+
});
|
|
188
|
+
break;
|
|
189
|
+
case 'move-entry':
|
|
190
|
+
applySilently({
|
|
191
|
+
type: 'moveEntry',
|
|
192
|
+
cardId: change.from.cardId,
|
|
193
|
+
field: change.from.field,
|
|
194
|
+
entryId: change.entry.id,
|
|
195
|
+
index: change.to.index,
|
|
196
|
+
toCardId: change.to.cardId,
|
|
197
|
+
toField: change.to.field,
|
|
198
|
+
});
|
|
199
|
+
break;
|
|
200
|
+
case 'update-entry':
|
|
201
|
+
if (change.op === 'add') {
|
|
202
|
+
applySilently({
|
|
203
|
+
type: 'addEntry',
|
|
204
|
+
cardId: change.cardId,
|
|
205
|
+
field: change.field,
|
|
206
|
+
entry: change.entry,
|
|
207
|
+
});
|
|
208
|
+
}
|
|
209
|
+
else if (change.op === 'remove') {
|
|
210
|
+
applySilently({
|
|
211
|
+
type: 'removeEntry',
|
|
212
|
+
cardId: change.cardId,
|
|
213
|
+
field: change.field,
|
|
214
|
+
entryId: change.entry.id,
|
|
215
|
+
});
|
|
216
|
+
}
|
|
217
|
+
else {
|
|
218
|
+
applySilently({
|
|
219
|
+
type: 'updateEntry',
|
|
220
|
+
cardId: change.cardId,
|
|
221
|
+
field: change.field,
|
|
222
|
+
entryId: change.entry.id,
|
|
223
|
+
changes: change.changes ?? {},
|
|
224
|
+
});
|
|
225
|
+
}
|
|
226
|
+
break;
|
|
227
|
+
}
|
|
228
|
+
});
|
|
229
|
+
return () => {
|
|
230
|
+
offs.forEach((off) => off());
|
|
231
|
+
offConnect?.();
|
|
232
|
+
};
|
|
233
|
+
}
|
|
234
|
+
/**
|
|
235
|
+
* Caminho feliz: carrega a config do adapter, cria o board (validação do
|
|
236
|
+
* createBoard incluída) e já liga a persistência/tempo real.
|
|
237
|
+
*/
|
|
238
|
+
async function loadBoard(adapter, options = {}) {
|
|
239
|
+
const config = await adapter.load();
|
|
240
|
+
const board = createBoard(config, { registry: options.registry, host: options.host });
|
|
241
|
+
bindAdapter(board, adapter, options);
|
|
242
|
+
return board;
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
/**
|
|
246
|
+
* Adapter em memória — referência para demos e testes. Guarda a config como
|
|
247
|
+
* fonte da verdade e aceita `emitRemote()` para simular um evento vindo do
|
|
248
|
+
* servidor (exercita o caminho de tempo real sem rede).
|
|
249
|
+
*/
|
|
250
|
+
class MemoryKanbanAdapter {
|
|
251
|
+
options;
|
|
252
|
+
config;
|
|
253
|
+
pushes = new Set();
|
|
254
|
+
constructor(seed, options = {}) {
|
|
255
|
+
this.options = options;
|
|
256
|
+
this.config = structuredClone(seed);
|
|
257
|
+
}
|
|
258
|
+
load() {
|
|
259
|
+
return Promise.resolve(structuredClone(this.config));
|
|
260
|
+
}
|
|
261
|
+
persist(change) {
|
|
262
|
+
if (this.options.failOn?.(change)) {
|
|
263
|
+
return Promise.reject(new Error(`persist rejeitado (${change.type})`));
|
|
264
|
+
}
|
|
265
|
+
this.config = { ...this.config, items: change.items.map((i) => ({ ...i })) };
|
|
266
|
+
return Promise.resolve();
|
|
267
|
+
}
|
|
268
|
+
connect(push) {
|
|
269
|
+
this.pushes.add(push);
|
|
270
|
+
return () => this.pushes.delete(push);
|
|
271
|
+
}
|
|
272
|
+
/** Simula um evento REMOTO: atualiza a fonte da verdade e avisa os
|
|
273
|
+
* conectados (como um servidor faria). */
|
|
274
|
+
emitRemote(change) {
|
|
275
|
+
this.config = { ...this.config, items: change.items.map((i) => ({ ...i })) };
|
|
276
|
+
for (const push of [...this.pushes])
|
|
277
|
+
push(change);
|
|
278
|
+
}
|
|
279
|
+
/** Itens atualmente persistidos (inspeção em testes). */
|
|
280
|
+
get items() {
|
|
281
|
+
return this.config.items ?? [];
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
/** Reordena os grupos de um eixo (array ou objeto) por uma lista de ids —
|
|
286
|
+
* usado para gravar a ordem de moveGroup na config persistida. */
|
|
287
|
+
function reorderAxis(axis, order) {
|
|
288
|
+
const groups = Array.isArray(axis) ? axis : axis.groups;
|
|
289
|
+
if (!groups)
|
|
290
|
+
return axis;
|
|
291
|
+
const idOf = (g) => (typeof g === 'string' ? g : g.id);
|
|
292
|
+
const sorted = [...groups].sort((a, b) => {
|
|
293
|
+
const ia = order.indexOf(idOf(a));
|
|
294
|
+
const ib = order.indexOf(idOf(b));
|
|
295
|
+
return (ia === -1 ? Infinity : ia) - (ib === -1 ? Infinity : ib);
|
|
296
|
+
});
|
|
297
|
+
return Array.isArray(axis) ? sorted : { ...axis, groups: sorted };
|
|
298
|
+
}
|
|
299
|
+
/**
|
|
300
|
+
* Adapter de localStorage — referência de persistência local (playground,
|
|
301
|
+
* protótipos). A CHAVE vem pronta do host (é ele que contextualiza tenant/
|
|
302
|
+
* usuário, docs/01 §8); a lib não inventa chave nenhuma.
|
|
303
|
+
*
|
|
304
|
+
* Tempo real de verdade entre ABAS: o evento nativo 'storage' só dispara nas
|
|
305
|
+
* outras abas — cada gravação local vira push remoto para as demais.
|
|
306
|
+
*/
|
|
307
|
+
class LocalStorageKanbanAdapter {
|
|
308
|
+
storageKey;
|
|
309
|
+
seed;
|
|
310
|
+
constructor(storageKey, seed) {
|
|
311
|
+
this.storageKey = storageKey;
|
|
312
|
+
this.seed = seed;
|
|
313
|
+
}
|
|
314
|
+
load() {
|
|
315
|
+
const stored = this.read();
|
|
316
|
+
return Promise.resolve(stored?.config ?? structuredClone(this.seed));
|
|
317
|
+
}
|
|
318
|
+
persist(change) {
|
|
319
|
+
let config = this.read()?.config ?? structuredClone(this.seed);
|
|
320
|
+
config = { ...config, items: change.items.map((i) => ({ ...i })) };
|
|
321
|
+
// grava a nova ordem dos grupos na config (reload reconstrói o eixo)
|
|
322
|
+
if (change.type === 'move-group') {
|
|
323
|
+
if (change.axis === 'columns') {
|
|
324
|
+
config = { ...config, columns: reorderAxis(config.columns, change.order) };
|
|
325
|
+
}
|
|
326
|
+
else if (config.lanes) {
|
|
327
|
+
config = { ...config, lanes: reorderAxis(config.lanes, change.order) };
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
const payload = { config, lastChange: change };
|
|
331
|
+
localStorage.setItem(this.storageKey, JSON.stringify(payload));
|
|
332
|
+
return Promise.resolve();
|
|
333
|
+
}
|
|
334
|
+
connect(push) {
|
|
335
|
+
if (typeof window === 'undefined')
|
|
336
|
+
return () => void 0;
|
|
337
|
+
const handler = (event) => {
|
|
338
|
+
if (event.key !== this.storageKey || !event.newValue)
|
|
339
|
+
return;
|
|
340
|
+
try {
|
|
341
|
+
const payload = JSON.parse(event.newValue);
|
|
342
|
+
if (payload.lastChange)
|
|
343
|
+
push(payload.lastChange);
|
|
344
|
+
}
|
|
345
|
+
catch {
|
|
346
|
+
// payload alheio/corrompido: ignora
|
|
347
|
+
}
|
|
348
|
+
};
|
|
349
|
+
window.addEventListener('storage', handler);
|
|
350
|
+
return () => window.removeEventListener('storage', handler);
|
|
351
|
+
}
|
|
352
|
+
/** Apaga o estado salvo (ex.: botão "resetar demo" do host). */
|
|
353
|
+
clear() {
|
|
354
|
+
localStorage.removeItem(this.storageKey);
|
|
355
|
+
}
|
|
356
|
+
read() {
|
|
357
|
+
const raw = localStorage.getItem(this.storageKey);
|
|
358
|
+
if (!raw)
|
|
359
|
+
return null;
|
|
360
|
+
try {
|
|
361
|
+
return JSON.parse(raw);
|
|
362
|
+
}
|
|
363
|
+
catch {
|
|
364
|
+
return null;
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
/**
|
|
370
|
+
* Adapter REST de referência — ESQUELETO documentado (docs/01 §7): dois
|
|
371
|
+
* endpoints, payloads JSON diretos. Casos reais tendem a envolver mapeamento
|
|
372
|
+
* de DTOs, autenticação e retry — faça um adapter próprio usando este como
|
|
373
|
+
* molde. Tempo real (connect) fica com o host: WebSocket/SSE são específicos
|
|
374
|
+
* demais para uma referência genérica; veja LocalStorageKanbanAdapter para o
|
|
375
|
+
* formato do push.
|
|
376
|
+
*/
|
|
377
|
+
class RestKanbanAdapter {
|
|
378
|
+
options;
|
|
379
|
+
constructor(options) {
|
|
380
|
+
this.options = options;
|
|
381
|
+
}
|
|
382
|
+
async load() {
|
|
383
|
+
const response = await this.doFetch(this.options.loadUrl, { method: 'GET' });
|
|
384
|
+
if (!response.ok)
|
|
385
|
+
throw new Error(`load falhou: HTTP ${response.status}`);
|
|
386
|
+
return (await response.json());
|
|
387
|
+
}
|
|
388
|
+
async persist(change) {
|
|
389
|
+
const response = await this.doFetch(this.options.persistUrl, {
|
|
390
|
+
method: 'POST',
|
|
391
|
+
body: JSON.stringify(change),
|
|
392
|
+
});
|
|
393
|
+
if (!response.ok)
|
|
394
|
+
throw new Error(`persist falhou: HTTP ${response.status}`);
|
|
395
|
+
}
|
|
396
|
+
doFetch(url, init) {
|
|
397
|
+
const fetchImpl = this.options.fetchImpl ?? fetch;
|
|
398
|
+
return fetchImpl(url, {
|
|
399
|
+
...init,
|
|
400
|
+
headers: { 'Content-Type': 'application/json', ...this.options.headers },
|
|
401
|
+
});
|
|
402
|
+
}
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
/*
|
|
406
|
+
* @mosaicoo/kanban/adapters — contratos de integração (persistência/tempo
|
|
407
|
+
* real), binder de fluxo otimista e adapters de referência.
|
|
408
|
+
*
|
|
409
|
+
* A lib NUNCA persiste nada por conta própria: todo dado entra e sai pelo
|
|
410
|
+
* adapter que o host fornece, já contextualizado (docs/01-arquitetura.md §7-8).
|
|
411
|
+
*/
|
|
412
|
+
|
|
413
|
+
/**
|
|
414
|
+
* Generated bundle index. Do not edit.
|
|
415
|
+
*/
|
|
416
|
+
|
|
417
|
+
export { LocalStorageKanbanAdapter, MemoryKanbanAdapter, RestKanbanAdapter, bindAdapter, loadBoard };
|