@svar-ui/svelte-kanban 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.
- package/dist/components/Avatar.svelte +87 -0
- package/dist/components/Avatar.svelte.d.ts +17 -0
- package/dist/components/Card.svelte +346 -0
- package/dist/components/Card.svelte.d.ts +9 -0
- package/dist/components/CardList.svelte +343 -0
- package/dist/components/CardList.svelte.d.ts +21 -0
- package/dist/components/CardWrapper.svelte +49 -0
- package/dist/components/CardWrapper.svelte.d.ts +15 -0
- package/dist/components/Column.svelte +230 -0
- package/dist/components/Column.svelte.d.ts +24 -0
- package/dist/components/ContextMenu.svelte +111 -0
- package/dist/components/ContextMenu.svelte.d.ts +18 -0
- package/dist/components/DragGhost.svelte +57 -0
- package/dist/components/DragGhost.svelte.d.ts +14 -0
- package/dist/components/Editor.svelte +108 -0
- package/dist/components/Editor.svelte.d.ts +10 -0
- package/dist/components/ExportLayout.svelte +52 -0
- package/dist/components/ExportLayout.svelte.d.ts +15 -0
- package/dist/components/Kanban.svelte +100 -0
- package/dist/components/Kanban.svelte.d.ts +186 -0
- package/dist/components/Layout.svelte +362 -0
- package/dist/components/Layout.svelte.d.ts +19 -0
- package/dist/components/Toolbar.svelte +97 -0
- package/dist/components/Toolbar.svelte.d.ts +12 -0
- package/dist/components/useCardOverlay.svelte.d.ts +24 -0
- package/dist/components/useCardOverlay.svelte.js +60 -0
- package/dist/components/useDrag.svelte.d.ts +22 -0
- package/dist/components/useDrag.svelte.js +16 -0
- package/dist/context.d.ts +3 -0
- package/dist/context.js +3 -0
- package/dist/defaults.d.ts +8 -0
- package/dist/defaults.js +85 -0
- package/dist/directives/dblclick.d.ts +13 -0
- package/dist/directives/dblclick.js +26 -0
- package/dist/directives/drag.d.ts +11 -0
- package/dist/directives/drag.js +183 -0
- package/dist/env.d.ts +9 -0
- package/dist/export/Card.svelte +5 -0
- package/dist/export/Card.svelte.d.ts +11 -0
- package/dist/export/Kanban.svelte +30 -0
- package/dist/export/Kanban.svelte.d.ts +16 -0
- package/dist/export.d.ts +3 -0
- package/dist/export.js +15 -0
- package/dist/index.d.ts +15 -0
- package/dist/index.js +15 -0
- package/dist/themes/Print.svelte +126 -0
- package/dist/themes/Print.svelte.d.ts +13 -0
- package/dist/themes/PrintBW.svelte +153 -0
- package/dist/themes/PrintBW.svelte.d.ts +13 -0
- package/dist/themes/Willow.svelte +45 -0
- package/dist/themes/Willow.svelte.d.ts +7 -0
- package/dist/themes/WillowDark.svelte +49 -0
- package/dist/themes/WillowDark.svelte.d.ts +7 -0
- package/dist/types.d.ts +86 -0
- package/dist/types.js +1 -0
- package/license.txt +21 -0
- package/package.json +59 -0
- package/readme.md +100 -0
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
<script lang="ts">import { getContext, setContext } from "svelte";
|
|
2
|
+
import { ContextMenu } from "@svar-ui/svelte-menu";
|
|
3
|
+
import { getID, locale } from "@svar-ui/lib-dom";
|
|
4
|
+
import { en } from "@svar-ui/kanban-locales";
|
|
5
|
+
import { en as coreEn } from "@svar-ui/core-locales";
|
|
6
|
+
import { getMenuOptions } from "@svar-ui/kanban-store";
|
|
7
|
+
import { KANBAN_API_CONTEXT } from "../context.js";
|
|
8
|
+
let { options = [], api = null, resolver = null, filter = null, at = "point", children, onclick, css } = $props();
|
|
9
|
+
// when mounted inside <Kanban> the api context is available;
|
|
10
|
+
// when wrapping <Kanban> from the outside, caller must pass `api`
|
|
11
|
+
const ctxApi = getContext(KANBAN_API_CONTEXT);
|
|
12
|
+
function parseId(id) {
|
|
13
|
+
if (typeof id === "string" && id.startsWith(":")) {
|
|
14
|
+
const element = document.createElement("div");
|
|
15
|
+
element.setAttribute("data-id", id);
|
|
16
|
+
return getID(element);
|
|
17
|
+
}
|
|
18
|
+
return typeof id === "string" || typeof id === "number" ? id : null;
|
|
19
|
+
}
|
|
20
|
+
function getCardById(id) {
|
|
21
|
+
const cardId = parseId(id);
|
|
22
|
+
if (cardId == null) return undefined;
|
|
23
|
+
if (api) return api.getCards().find((c) => c.id === cardId);
|
|
24
|
+
return ctxApi?.getState().cards.getById(cardId);
|
|
25
|
+
}
|
|
26
|
+
function exec(action, payload) {
|
|
27
|
+
(api ?? ctxApi)?.exec(action, payload);
|
|
28
|
+
}
|
|
29
|
+
let activeId = null;
|
|
30
|
+
let l = getContext("wx-i18n");
|
|
31
|
+
if (!l) {
|
|
32
|
+
l = locale({
|
|
33
|
+
...en,
|
|
34
|
+
...coreEn
|
|
35
|
+
});
|
|
36
|
+
setContext("wx-i18n", l);
|
|
37
|
+
}
|
|
38
|
+
const _ = l.getGroup("kanban");
|
|
39
|
+
function applyLocale(opts) {
|
|
40
|
+
return opts.map((op) => {
|
|
41
|
+
op = { ...op };
|
|
42
|
+
if (op.text) op.text = _(op.text);
|
|
43
|
+
if (op.subtext) op.subtext = _(op.subtext);
|
|
44
|
+
if (op.data) op.data = applyLocale(op.data);
|
|
45
|
+
return op;
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
function getOptions() {
|
|
49
|
+
const base = options.length ? options : getMenuOptions();
|
|
50
|
+
return applyLocale(base);
|
|
51
|
+
}
|
|
52
|
+
function itemResolver(rawId, ev) {
|
|
53
|
+
if (rawId == null) return null;
|
|
54
|
+
const card = getCardById(rawId);
|
|
55
|
+
if (!card) return null;
|
|
56
|
+
if (resolver) {
|
|
57
|
+
const result = resolver(card, ev);
|
|
58
|
+
if (!result) return null;
|
|
59
|
+
}
|
|
60
|
+
activeId = card.id;
|
|
61
|
+
return card;
|
|
62
|
+
}
|
|
63
|
+
function menuAction(ev) {
|
|
64
|
+
const action = ev?.action;
|
|
65
|
+
if (!action) return;
|
|
66
|
+
const id = typeof activeId === "object" ? activeId.id : activeId;
|
|
67
|
+
if (action.id === "edit-card") {
|
|
68
|
+
exec("select-card", { id });
|
|
69
|
+
} else if (action.id === "duplicate-card") {
|
|
70
|
+
exec("duplicate-card", { id });
|
|
71
|
+
} else if (action.id === "delete-card") {
|
|
72
|
+
exec("delete-card", { id });
|
|
73
|
+
}
|
|
74
|
+
onclick?.(ev);
|
|
75
|
+
}
|
|
76
|
+
function filterMenu(item, card) {
|
|
77
|
+
return filter ? filter(item, card) : true;
|
|
78
|
+
}
|
|
79
|
+
const cOptions = $derived(getOptions());
|
|
80
|
+
let menu = $state();
|
|
81
|
+
export function show(ev, obj) {
|
|
82
|
+
menu.show(ev, obj);
|
|
83
|
+
}
|
|
84
|
+
</script>
|
|
85
|
+
|
|
86
|
+
<ContextMenu
|
|
87
|
+
filter={filterMenu}
|
|
88
|
+
options={cOptions}
|
|
89
|
+
dataKey="id"
|
|
90
|
+
resolver={itemResolver}
|
|
91
|
+
onclick={menuAction}
|
|
92
|
+
{css}
|
|
93
|
+
{at}
|
|
94
|
+
bind:this={menu}
|
|
95
|
+
/>
|
|
96
|
+
{#if children}
|
|
97
|
+
<!-- svelte-ignore a11y_no_static_element_interactions -->
|
|
98
|
+
<span oncontextmenu={menu?.show} data-menu-ignore="true">
|
|
99
|
+
{@render children?.()}
|
|
100
|
+
</span>
|
|
101
|
+
{/if}
|
|
102
|
+
|
|
103
|
+
<style>
|
|
104
|
+
:global(.wx-menu .wx-option.wx-disabled) {
|
|
105
|
+
pointer-events: none;
|
|
106
|
+
}
|
|
107
|
+
:global(.wx-menu .wx-option.wx-disabled .wx-value),
|
|
108
|
+
:global(.wx-menu .wx-option.wx-disabled .wx-icon) {
|
|
109
|
+
color: var(--wx-color-font-disabled);
|
|
110
|
+
}
|
|
111
|
+
</style>
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { Snippet } from "svelte";
|
|
2
|
+
import { ContextMenu } from "@svar-ui/svelte-menu";
|
|
3
|
+
import type { KanbanCard, KanbanInstanceApi } from "../types.js";
|
|
4
|
+
type Props = {
|
|
5
|
+
options?: any[];
|
|
6
|
+
api?: KanbanInstanceApi | null;
|
|
7
|
+
resolver?: ((card: KanbanCard, ev: MouseEvent) => any) | null;
|
|
8
|
+
filter?: ((item: any, card: KanbanCard) => boolean) | null;
|
|
9
|
+
at?: string;
|
|
10
|
+
children?: Snippet;
|
|
11
|
+
onclick?: (e: any) => void;
|
|
12
|
+
css?: string;
|
|
13
|
+
};
|
|
14
|
+
declare const ContextMenu: import("svelte").Component<Props, {
|
|
15
|
+
show: (ev: any, obj?: any) => void;
|
|
16
|
+
}, "">;
|
|
17
|
+
type ContextMenu = ReturnType<typeof ContextMenu>;
|
|
18
|
+
export default ContextMenu;
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
<script lang="ts">import { getContext } from "svelte";
|
|
2
|
+
import CardWrapper from "./CardWrapper.svelte";
|
|
3
|
+
import { KANBAN_API_CONTEXT, DND_CONTEXT } from "../context.js";
|
|
4
|
+
let { root, cardContent, cardShape } = $props();
|
|
5
|
+
const dnd = getContext(DND_CONTEXT);
|
|
6
|
+
const store = getContext(KANBAN_API_CONTEXT);
|
|
7
|
+
const draggedCard = $derived.by(() => {
|
|
8
|
+
if (!dnd?.active || dnd.cardId == null) return null;
|
|
9
|
+
return store.getState().cards.getById(dnd.cardId) ?? null;
|
|
10
|
+
});
|
|
11
|
+
const position = $derived.by(() => {
|
|
12
|
+
if (!dnd) return {
|
|
13
|
+
x: 0,
|
|
14
|
+
y: 0
|
|
15
|
+
};
|
|
16
|
+
let x = dnd.pointer.x - dnd.offset.x;
|
|
17
|
+
let y = dnd.pointer.y - dnd.offset.y;
|
|
18
|
+
if (root && dnd.active) {
|
|
19
|
+
const rect = root.getBoundingClientRect();
|
|
20
|
+
x = Math.max(rect.left, Math.min(x, rect.right - dnd.width));
|
|
21
|
+
y = Math.max(rect.top, Math.min(y, rect.bottom - dnd.height));
|
|
22
|
+
}
|
|
23
|
+
return {
|
|
24
|
+
x,
|
|
25
|
+
y
|
|
26
|
+
};
|
|
27
|
+
});
|
|
28
|
+
</script>
|
|
29
|
+
|
|
30
|
+
{#if dnd?.active && draggedCard}
|
|
31
|
+
<div
|
|
32
|
+
class="wx-ghost"
|
|
33
|
+
style:width="{dnd.width}px"
|
|
34
|
+
style:height="{dnd.height}px"
|
|
35
|
+
style:transform="translate({position.x}px, {position.y}px)"
|
|
36
|
+
>
|
|
37
|
+
<CardWrapper card={draggedCard} {cardContent} {cardShape} />
|
|
38
|
+
</div>
|
|
39
|
+
{/if}
|
|
40
|
+
|
|
41
|
+
<style>
|
|
42
|
+
.wx-ghost {
|
|
43
|
+
position: fixed;
|
|
44
|
+
top: 0;
|
|
45
|
+
left: 0;
|
|
46
|
+
z-index: 10000;
|
|
47
|
+
pointer-events: none;
|
|
48
|
+
box-shadow: var(--wx-kanban-card-shadow-drag);
|
|
49
|
+
border-radius: var(--wx-border-radius);
|
|
50
|
+
transform-origin: top left;
|
|
51
|
+
will-change: transform;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
.wx-ghost :global(.wx-card) {
|
|
55
|
+
cursor: grabbing;
|
|
56
|
+
}
|
|
57
|
+
</style>
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { Component } from "svelte";
|
|
2
|
+
import type { KanbanCard } from "@svar-ui/kanban-store";
|
|
3
|
+
import type { CardShape } from "../types.js";
|
|
4
|
+
type Props = {
|
|
5
|
+
root?: HTMLElement;
|
|
6
|
+
cardContent?: Component<{
|
|
7
|
+
card: KanbanCard;
|
|
8
|
+
cardShape: CardShape;
|
|
9
|
+
}>;
|
|
10
|
+
cardShape: CardShape;
|
|
11
|
+
};
|
|
12
|
+
declare const DragGhost: Component<Props, {}, "">;
|
|
13
|
+
type DragGhost = ReturnType<typeof DragGhost>;
|
|
14
|
+
export default DragGhost;
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
<script lang="ts">import { getContext, setContext } from "svelte";
|
|
2
|
+
import { Editor as EditorBase, registerEditorItem } from "@svar-ui/svelte-editor";
|
|
3
|
+
import { DatePicker, MultiCombo, RichSelect, Slider } from "@svar-ui/svelte-core";
|
|
4
|
+
import { locale } from "@svar-ui/lib-dom";
|
|
5
|
+
import { en } from "@svar-ui/kanban-locales";
|
|
6
|
+
import { en as coreEn } from "@svar-ui/core-locales";
|
|
7
|
+
import { getEditorItems } from "../defaults.js";
|
|
8
|
+
registerEditorItem("richselect", RichSelect);
|
|
9
|
+
registerEditorItem("multicombo", MultiCombo);
|
|
10
|
+
registerEditorItem("datepicker", DatePicker);
|
|
11
|
+
registerEditorItem("slider", Slider);
|
|
12
|
+
let { api, values, items = getEditorItems(), placement = "sidebar", layout = "default", focus = true, css = "", topBar, autoSave = true, onchange, onsave, onaction, ...editorProps } = $props();
|
|
13
|
+
// svelte-ignore state_referenced_locally
|
|
14
|
+
void values;
|
|
15
|
+
// svelte-ignore state_referenced_locally
|
|
16
|
+
const { editorData } = api.getReactiveState();
|
|
17
|
+
let l = getContext("wx-i18n");
|
|
18
|
+
if (!l) {
|
|
19
|
+
l = locale({
|
|
20
|
+
...en,
|
|
21
|
+
...coreEn
|
|
22
|
+
});
|
|
23
|
+
setContext("wx-i18n", l);
|
|
24
|
+
}
|
|
25
|
+
const _ = l.getGroup("kanban");
|
|
26
|
+
function translate(value) {
|
|
27
|
+
return typeof value === "string" ? _(value) : value;
|
|
28
|
+
}
|
|
29
|
+
function applyLocale(list) {
|
|
30
|
+
return list.map((item) => {
|
|
31
|
+
const next = { ...item };
|
|
32
|
+
next.label = translate(next.label);
|
|
33
|
+
if (Array.isArray(next.options)) {
|
|
34
|
+
next.options = next.options.map((opt) => ({
|
|
35
|
+
...opt,
|
|
36
|
+
label: translate(opt.label)
|
|
37
|
+
}));
|
|
38
|
+
}
|
|
39
|
+
return next;
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
const cItems = $derived(applyLocale(items));
|
|
43
|
+
const defaultTopBar = { items: [
|
|
44
|
+
{
|
|
45
|
+
comp: "icon",
|
|
46
|
+
icon: "wxi-close",
|
|
47
|
+
id: "close"
|
|
48
|
+
},
|
|
49
|
+
{ comp: "spacer" },
|
|
50
|
+
{
|
|
51
|
+
comp: "button",
|
|
52
|
+
id: "delete",
|
|
53
|
+
text: _("Delete"),
|
|
54
|
+
type: "primary danger",
|
|
55
|
+
onclick: handleDelete
|
|
56
|
+
}
|
|
57
|
+
] };
|
|
58
|
+
const editorTopBar = $derived(topBar === undefined ? defaultTopBar : topBar);
|
|
59
|
+
const editorCss = $derived(["wx-editor-kanban", css].filter(Boolean).join(" "));
|
|
60
|
+
function handleSave(ev) {
|
|
61
|
+
onsave?.(ev);
|
|
62
|
+
const data = $editorData;
|
|
63
|
+
if (!data) return;
|
|
64
|
+
api.exec("update-card", {
|
|
65
|
+
id: data.id,
|
|
66
|
+
card: { ...ev.values }
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
function handleChange(ev) {
|
|
70
|
+
onchange?.(ev);
|
|
71
|
+
}
|
|
72
|
+
function handleDelete() {
|
|
73
|
+
const data = $editorData;
|
|
74
|
+
if (!data) return;
|
|
75
|
+
api.exec("delete-card", { id: data.id });
|
|
76
|
+
api.exec("select-card", { id: null });
|
|
77
|
+
}
|
|
78
|
+
function handleAction(ev) {
|
|
79
|
+
onaction?.(ev);
|
|
80
|
+
const { item } = ev;
|
|
81
|
+
if (item.id === "close" && !!item.comp) {
|
|
82
|
+
api.exec("select-card", { id: null });
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
</script>
|
|
86
|
+
|
|
87
|
+
{#if $editorData}
|
|
88
|
+
<EditorBase
|
|
89
|
+
{...editorProps}
|
|
90
|
+
{focus}
|
|
91
|
+
items={cItems}
|
|
92
|
+
topBar={editorTopBar}
|
|
93
|
+
{autoSave}
|
|
94
|
+
onchange={handleChange}
|
|
95
|
+
onaction={handleAction}
|
|
96
|
+
onsave={handleSave}
|
|
97
|
+
{placement}
|
|
98
|
+
{layout}
|
|
99
|
+
values={$editorData}
|
|
100
|
+
css={editorCss}
|
|
101
|
+
/>
|
|
102
|
+
{/if}
|
|
103
|
+
|
|
104
|
+
<style>
|
|
105
|
+
:global(.wx-sidearea .wx-editor-kanban) {
|
|
106
|
+
width: 450px;
|
|
107
|
+
}
|
|
108
|
+
</style>
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { type ComponentProps } from "svelte";
|
|
2
|
+
import { Editor as EditorBase } from "@svar-ui/svelte-editor";
|
|
3
|
+
type BaseEditorProps = ComponentProps<typeof EditorBase>;
|
|
4
|
+
type EditorProps = Omit<BaseEditorProps, "values"> & {
|
|
5
|
+
api: any;
|
|
6
|
+
values?: never;
|
|
7
|
+
};
|
|
8
|
+
declare const Editor: import("svelte").Component<EditorProps, {}, "">;
|
|
9
|
+
type Editor = ReturnType<typeof Editor>;
|
|
10
|
+
export default Editor;
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
<script lang="ts">import { getContext } from "svelte";
|
|
2
|
+
import { KANBAN_API_CONTEXT } from "../context.js";
|
|
3
|
+
let { cardCss, columnCss, cardContent: CardContent, cardShape } = $props();
|
|
4
|
+
const store = getContext(KANBAN_API_CONTEXT);
|
|
5
|
+
const viewData = store.getReactiveState().viewData;
|
|
6
|
+
let root = $state();
|
|
7
|
+
$effect(() => {
|
|
8
|
+
const out = {};
|
|
9
|
+
if (CardContent) {
|
|
10
|
+
const c = {};
|
|
11
|
+
root.querySelectorAll(".wx-ex-cell").forEach((element) => {
|
|
12
|
+
c[element.dataset.id] = element.innerHTML;
|
|
13
|
+
});
|
|
14
|
+
out.cardContent = c;
|
|
15
|
+
}
|
|
16
|
+
const cs = {};
|
|
17
|
+
if (cardCss) {
|
|
18
|
+
$viewData.columns.forEach((column) => {
|
|
19
|
+
column.cards.forEach((card) => {
|
|
20
|
+
cs[card.id.toString()] = cardCss(card, column);
|
|
21
|
+
});
|
|
22
|
+
});
|
|
23
|
+
out.cardCss = cs;
|
|
24
|
+
}
|
|
25
|
+
const cls = {};
|
|
26
|
+
if (columnCss) {
|
|
27
|
+
$viewData.columns.forEach((column) => {
|
|
28
|
+
cls[column.id.toString()] = columnCss(column.cards, column);
|
|
29
|
+
});
|
|
30
|
+
out.columnCss = cls;
|
|
31
|
+
}
|
|
32
|
+
store.exec("export-data", {
|
|
33
|
+
format: "inner",
|
|
34
|
+
data: out
|
|
35
|
+
});
|
|
36
|
+
});
|
|
37
|
+
</script>
|
|
38
|
+
|
|
39
|
+
<div style="visibility: hidden;position:absolute;" bind:this={root}>
|
|
40
|
+
{#if CardContent}
|
|
41
|
+
{#each $viewData.columns as column}
|
|
42
|
+
{#each column.cards as card}
|
|
43
|
+
<div class="wx-ex-cell" data-id={card.id} >
|
|
44
|
+
<CardContent
|
|
45
|
+
{card}
|
|
46
|
+
{cardShape}
|
|
47
|
+
></CardContent>
|
|
48
|
+
</div>
|
|
49
|
+
{/each}
|
|
50
|
+
{/each}
|
|
51
|
+
{/if}
|
|
52
|
+
</div>
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { CardCssFn, ColumnCssFn, CardShape } from "../types.js";
|
|
2
|
+
import type { Component } from "svelte";
|
|
3
|
+
import type { KanbanCard } from "@svar-ui/kanban-store";
|
|
4
|
+
type Props = {
|
|
5
|
+
cardShape: CardShape;
|
|
6
|
+
cardCss?: CardCssFn;
|
|
7
|
+
columnCss?: ColumnCssFn;
|
|
8
|
+
cardContent?: Component<{
|
|
9
|
+
card: KanbanCard;
|
|
10
|
+
cardShape: CardShape;
|
|
11
|
+
}>;
|
|
12
|
+
};
|
|
13
|
+
declare const ExportLayout: Component<Props, {}, "">;
|
|
14
|
+
type ExportLayout = ReturnType<typeof ExportLayout>;
|
|
15
|
+
export default ExportLayout;
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
<script lang="ts">import { setContext } from "svelte";
|
|
2
|
+
import { writable } from "svelte/store";
|
|
3
|
+
import { EventBusRouter } from "@svar-ui/lib-state";
|
|
4
|
+
import { KanbanStore } from "@svar-ui/kanban-store";
|
|
5
|
+
import Layout from "./Layout.svelte";
|
|
6
|
+
import ExportLayout from "./ExportLayout.svelte";
|
|
7
|
+
import { KANBAN_API_CONTEXT, DND_CONTEXT } from "../context.js";
|
|
8
|
+
import { DndState } from "./useDrag.svelte.js";
|
|
9
|
+
import { getCardShape } from "../defaults.js";
|
|
10
|
+
// locales
|
|
11
|
+
import { en } from "@svar-ui/kanban-locales";
|
|
12
|
+
import { en as coreEn } from "@svar-ui/core-locales";
|
|
13
|
+
import { Locale } from "@svar-ui/svelte-core";
|
|
14
|
+
let { cards, columns, columnAccessor = "column", filters = new Map(), sort = null, card = getCardShape(), readonly = false, render, dynamicData = false, history = false, cardContent, init, tooltip, cardPopup, cardCss, columnCss, ...restProps } = $props();
|
|
15
|
+
// svelte-ignore state_referenced_locally
|
|
16
|
+
const store = new KanbanStore(writable, { undo: history });
|
|
17
|
+
// define event route
|
|
18
|
+
let firstInRoute = store.in;
|
|
19
|
+
const dash = /-/g;
|
|
20
|
+
let lastInRoute = new EventBusRouter((a, b) => {
|
|
21
|
+
const name = "on" + a.replace(dash, "");
|
|
22
|
+
const handler = restProps[name];
|
|
23
|
+
if (handler) {
|
|
24
|
+
handler(b);
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
firstInRoute.setNext(lastInRoute);
|
|
28
|
+
export const getState = store.getState.bind(store), getReactiveState = store.getReactive.bind(store), getStores = () => ({ data: store }), getCards = store.getCards.bind(store), exec = store.in.exec.bind(store.in), on = store.in.on.bind(store.in), detach = store.in.detach.bind(store.in), setNext = store.in.setNext.bind(store.in), intercept = store.in.intercept.bind(store.in);
|
|
29
|
+
const api = {
|
|
30
|
+
getState,
|
|
31
|
+
getReactiveState,
|
|
32
|
+
getStores,
|
|
33
|
+
getCards,
|
|
34
|
+
setNext,
|
|
35
|
+
exec,
|
|
36
|
+
on,
|
|
37
|
+
detach,
|
|
38
|
+
intercept
|
|
39
|
+
};
|
|
40
|
+
setContext(KANBAN_API_CONTEXT, {
|
|
41
|
+
getReactiveState,
|
|
42
|
+
getState,
|
|
43
|
+
exec,
|
|
44
|
+
getBrandmark: store.getBrandmark.bind(store)
|
|
45
|
+
});
|
|
46
|
+
setContext(DND_CONTEXT, new DndState());
|
|
47
|
+
const input = () => ({
|
|
48
|
+
cards,
|
|
49
|
+
columns,
|
|
50
|
+
columnAccessor,
|
|
51
|
+
filters,
|
|
52
|
+
sort,
|
|
53
|
+
dynamicData
|
|
54
|
+
});
|
|
55
|
+
store.init({
|
|
56
|
+
...input(),
|
|
57
|
+
renderMode: ""
|
|
58
|
+
});
|
|
59
|
+
// svelte-ignore state_referenced_locally
|
|
60
|
+
init?.(api);
|
|
61
|
+
let firstEffect = true;
|
|
62
|
+
$effect(() => {
|
|
63
|
+
const data = input();
|
|
64
|
+
if (firstEffect) {
|
|
65
|
+
firstEffect = false;
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
store.init(data);
|
|
69
|
+
});
|
|
70
|
+
$effect(() => {
|
|
71
|
+
store.meta["export-data"] = {
|
|
72
|
+
card,
|
|
73
|
+
cardContent,
|
|
74
|
+
cardCss,
|
|
75
|
+
columnCss
|
|
76
|
+
};
|
|
77
|
+
});
|
|
78
|
+
const renderMode = store.getReactive().renderMode;
|
|
79
|
+
</script>
|
|
80
|
+
|
|
81
|
+
<Locale words={{...coreEn, ...en}} optional={true}>
|
|
82
|
+
<Layout
|
|
83
|
+
cardShape={card}
|
|
84
|
+
{readonly}
|
|
85
|
+
{render}
|
|
86
|
+
{cardContent}
|
|
87
|
+
{tooltip}
|
|
88
|
+
{cardPopup}
|
|
89
|
+
{cardCss}
|
|
90
|
+
{columnCss}
|
|
91
|
+
/>
|
|
92
|
+
{#if $renderMode === "export"}
|
|
93
|
+
<ExportLayout
|
|
94
|
+
cardShape={card}
|
|
95
|
+
{cardContent}
|
|
96
|
+
{cardCss}
|
|
97
|
+
{columnCss}
|
|
98
|
+
/>
|
|
99
|
+
{/if}
|
|
100
|
+
</Locale>
|
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
import type { Component } from "svelte";
|
|
2
|
+
import { KanbanStore } from "@svar-ui/kanban-store";
|
|
3
|
+
import type { KanbanCard, ColumnConfig, ColumnAccessor, SortCriterion, FilterPredicate } from "@svar-ui/kanban-store";
|
|
4
|
+
import type { CardShape, KanbanInstanceApi, RenderConfig, CardCssFn, ColumnCssFn } from "../types.js";
|
|
5
|
+
type Props = {
|
|
6
|
+
cards: KanbanCard[];
|
|
7
|
+
columns: ColumnConfig[];
|
|
8
|
+
columnAccessor?: ColumnAccessor;
|
|
9
|
+
filters?: Map<string, FilterPredicate>;
|
|
10
|
+
sort?: SortCriterion;
|
|
11
|
+
card?: CardShape;
|
|
12
|
+
readonly?: boolean;
|
|
13
|
+
render?: RenderConfig;
|
|
14
|
+
dynamicData?: boolean;
|
|
15
|
+
history?: boolean;
|
|
16
|
+
cardContent?: Component<{
|
|
17
|
+
card: KanbanCard;
|
|
18
|
+
cardShape: CardShape;
|
|
19
|
+
}>;
|
|
20
|
+
init?: (api: KanbanInstanceApi) => void;
|
|
21
|
+
tooltip?: any;
|
|
22
|
+
cardPopup?: any;
|
|
23
|
+
cardCss?: CardCssFn;
|
|
24
|
+
columnCss?: ColumnCssFn;
|
|
25
|
+
};
|
|
26
|
+
declare const Kanban: Component<Props, {
|
|
27
|
+
getState: () => import("@svar-ui/kanban-store").State;
|
|
28
|
+
getReactiveState: () => {
|
|
29
|
+
renderMode: import("@svar-ui/lib-state").IPublicWritable<string>;
|
|
30
|
+
cards: import("@svar-ui/lib-state").IPublicWritable<import("@svar-ui/kanban-store").CardsStore>;
|
|
31
|
+
columns: import("@svar-ui/lib-state").IPublicWritable<ColumnConfig[]>;
|
|
32
|
+
columnAccessor: import("@svar-ui/lib-state").IPublicWritable<ColumnAccessor>;
|
|
33
|
+
filters: import("@svar-ui/lib-state").IPublicWritable<Map<string, FilterPredicate>>;
|
|
34
|
+
sort: import("@svar-ui/lib-state").IPublicWritable<SortCriterion>;
|
|
35
|
+
editorData: import("@svar-ui/lib-state").IPublicWritable<KanbanCard | null>;
|
|
36
|
+
dynamicData: import("@svar-ui/lib-state").IPublicWritable<boolean>;
|
|
37
|
+
columnData: import("@svar-ui/lib-state").IPublicWritable<Map<import("@svar-ui/kanban-store").ColumnID, import("@svar-ui/kanban-store").ColumnDataState>>;
|
|
38
|
+
history: import("@svar-ui/lib-state").IPublicWritable<import("@svar-ui/kanban-store").HistoryState>;
|
|
39
|
+
viewData: import("@svar-ui/lib-state").IPublicWritable<{
|
|
40
|
+
columns: import("@svar-ui/kanban-store").ColumnView[];
|
|
41
|
+
}>;
|
|
42
|
+
};
|
|
43
|
+
getStores: () => {
|
|
44
|
+
data: KanbanStore;
|
|
45
|
+
};
|
|
46
|
+
getCards: () => KanbanCard[];
|
|
47
|
+
exec: (name: keyof import("@svar-ui/kanban-store").StoreActions, ev: import("@svar-ui/kanban-store").ExportConfig | {
|
|
48
|
+
card: Partial<KanbanCard>;
|
|
49
|
+
edit?: boolean;
|
|
50
|
+
id?: import("@svar-ui/kanban-store").CardID;
|
|
51
|
+
after?: import("@svar-ui/kanban-store").CardID;
|
|
52
|
+
} | {
|
|
53
|
+
id: import("@svar-ui/kanban-store").CardID;
|
|
54
|
+
card: Partial<KanbanCard>;
|
|
55
|
+
} | {
|
|
56
|
+
id: import("@svar-ui/kanban-store").CardID;
|
|
57
|
+
column?: import("@svar-ui/kanban-store").ColumnID;
|
|
58
|
+
before?: import("@svar-ui/kanban-store").CardID | null;
|
|
59
|
+
} | {
|
|
60
|
+
id: import("@svar-ui/kanban-store").ColumnID;
|
|
61
|
+
column: Partial<ColumnConfig>;
|
|
62
|
+
} | {
|
|
63
|
+
id: import("@svar-ui/kanban-store").CardID;
|
|
64
|
+
card?: Partial<KanbanCard>;
|
|
65
|
+
edit?: boolean;
|
|
66
|
+
} | {
|
|
67
|
+
id: import("@svar-ui/kanban-store").CardID;
|
|
68
|
+
} | {
|
|
69
|
+
id: import("@svar-ui/kanban-store").CardID | null;
|
|
70
|
+
} | {
|
|
71
|
+
filter?: FilterPredicate | null;
|
|
72
|
+
tag?: string;
|
|
73
|
+
} | {
|
|
74
|
+
sort?: SortCriterion;
|
|
75
|
+
} | {
|
|
76
|
+
id: import("@svar-ui/kanban-store").ColumnID;
|
|
77
|
+
} | {
|
|
78
|
+
id?: import("@svar-ui/kanban-store").ColumnID;
|
|
79
|
+
cards: KanbanCard[];
|
|
80
|
+
} | Record<string, never>) => Promise<import("@svar-ui/kanban-store").ExportConfig | {
|
|
81
|
+
card: Partial<KanbanCard>;
|
|
82
|
+
edit?: boolean;
|
|
83
|
+
id?: import("@svar-ui/kanban-store").CardID;
|
|
84
|
+
after?: import("@svar-ui/kanban-store").CardID;
|
|
85
|
+
} | {
|
|
86
|
+
id: import("@svar-ui/kanban-store").CardID;
|
|
87
|
+
card: Partial<KanbanCard>;
|
|
88
|
+
} | {
|
|
89
|
+
id: import("@svar-ui/kanban-store").CardID;
|
|
90
|
+
column?: import("@svar-ui/kanban-store").ColumnID;
|
|
91
|
+
before?: import("@svar-ui/kanban-store").CardID | null;
|
|
92
|
+
} | {
|
|
93
|
+
id: import("@svar-ui/kanban-store").ColumnID;
|
|
94
|
+
column: Partial<ColumnConfig>;
|
|
95
|
+
} | {
|
|
96
|
+
id: import("@svar-ui/kanban-store").CardID;
|
|
97
|
+
card?: Partial<KanbanCard>;
|
|
98
|
+
edit?: boolean;
|
|
99
|
+
} | {
|
|
100
|
+
id: import("@svar-ui/kanban-store").CardID;
|
|
101
|
+
} | {
|
|
102
|
+
id: import("@svar-ui/kanban-store").CardID | null;
|
|
103
|
+
} | {
|
|
104
|
+
filter?: FilterPredicate | null;
|
|
105
|
+
tag?: string;
|
|
106
|
+
} | {
|
|
107
|
+
sort?: SortCriterion;
|
|
108
|
+
} | {
|
|
109
|
+
id: import("@svar-ui/kanban-store").ColumnID;
|
|
110
|
+
} | {
|
|
111
|
+
id?: import("@svar-ui/kanban-store").ColumnID;
|
|
112
|
+
cards: KanbanCard[];
|
|
113
|
+
} | Record<string, never>>;
|
|
114
|
+
on: (name: keyof import("@svar-ui/kanban-store").StoreActions, handler: (v: import("@svar-ui/kanban-store").ExportConfig | {
|
|
115
|
+
card: Partial<KanbanCard>;
|
|
116
|
+
edit?: boolean;
|
|
117
|
+
id?: import("@svar-ui/kanban-store").CardID;
|
|
118
|
+
after?: import("@svar-ui/kanban-store").CardID;
|
|
119
|
+
} | {
|
|
120
|
+
id: import("@svar-ui/kanban-store").CardID;
|
|
121
|
+
card: Partial<KanbanCard>;
|
|
122
|
+
} | {
|
|
123
|
+
id: import("@svar-ui/kanban-store").CardID;
|
|
124
|
+
column?: import("@svar-ui/kanban-store").ColumnID;
|
|
125
|
+
before?: import("@svar-ui/kanban-store").CardID | null;
|
|
126
|
+
} | {
|
|
127
|
+
id: import("@svar-ui/kanban-store").ColumnID;
|
|
128
|
+
column: Partial<ColumnConfig>;
|
|
129
|
+
} | {
|
|
130
|
+
id: import("@svar-ui/kanban-store").CardID;
|
|
131
|
+
card?: Partial<KanbanCard>;
|
|
132
|
+
edit?: boolean;
|
|
133
|
+
} | {
|
|
134
|
+
id: import("@svar-ui/kanban-store").CardID;
|
|
135
|
+
} | {
|
|
136
|
+
id: import("@svar-ui/kanban-store").CardID | null;
|
|
137
|
+
} | {
|
|
138
|
+
filter?: FilterPredicate | null;
|
|
139
|
+
tag?: string;
|
|
140
|
+
} | {
|
|
141
|
+
sort?: SortCriterion;
|
|
142
|
+
} | {
|
|
143
|
+
id: import("@svar-ui/kanban-store").ColumnID;
|
|
144
|
+
} | {
|
|
145
|
+
id?: import("@svar-ui/kanban-store").ColumnID;
|
|
146
|
+
cards: KanbanCard[];
|
|
147
|
+
} | Record<string, never>) => void | boolean | Promise<boolean>, config?: import("@svar-ui/lib-state").IEventConfig) => void;
|
|
148
|
+
detach: (tag: number | string | symbol) => void;
|
|
149
|
+
setNext: (next: import("@svar-ui/lib-state").IEventBus<import("@svar-ui/kanban-store").StoreActions>) => import("@svar-ui/lib-state").IEventBus<import("@svar-ui/kanban-store").StoreActions>;
|
|
150
|
+
intercept: (name: keyof import("@svar-ui/kanban-store").StoreActions, handler: (v: import("@svar-ui/kanban-store").ExportConfig | {
|
|
151
|
+
card: Partial<KanbanCard>;
|
|
152
|
+
edit?: boolean;
|
|
153
|
+
id?: import("@svar-ui/kanban-store").CardID;
|
|
154
|
+
after?: import("@svar-ui/kanban-store").CardID;
|
|
155
|
+
} | {
|
|
156
|
+
id: import("@svar-ui/kanban-store").CardID;
|
|
157
|
+
card: Partial<KanbanCard>;
|
|
158
|
+
} | {
|
|
159
|
+
id: import("@svar-ui/kanban-store").CardID;
|
|
160
|
+
column?: import("@svar-ui/kanban-store").ColumnID;
|
|
161
|
+
before?: import("@svar-ui/kanban-store").CardID | null;
|
|
162
|
+
} | {
|
|
163
|
+
id: import("@svar-ui/kanban-store").ColumnID;
|
|
164
|
+
column: Partial<ColumnConfig>;
|
|
165
|
+
} | {
|
|
166
|
+
id: import("@svar-ui/kanban-store").CardID;
|
|
167
|
+
card?: Partial<KanbanCard>;
|
|
168
|
+
edit?: boolean;
|
|
169
|
+
} | {
|
|
170
|
+
id: import("@svar-ui/kanban-store").CardID;
|
|
171
|
+
} | {
|
|
172
|
+
id: import("@svar-ui/kanban-store").CardID | null;
|
|
173
|
+
} | {
|
|
174
|
+
filter?: FilterPredicate | null;
|
|
175
|
+
tag?: string;
|
|
176
|
+
} | {
|
|
177
|
+
sort?: SortCriterion;
|
|
178
|
+
} | {
|
|
179
|
+
id: import("@svar-ui/kanban-store").ColumnID;
|
|
180
|
+
} | {
|
|
181
|
+
id?: import("@svar-ui/kanban-store").ColumnID;
|
|
182
|
+
cards: KanbanCard[];
|
|
183
|
+
} | Record<string, never>) => void | boolean | Promise<boolean>, config?: import("@svar-ui/lib-state").IEventConfig) => void;
|
|
184
|
+
}, "">;
|
|
185
|
+
type Kanban = ReturnType<typeof Kanban>;
|
|
186
|
+
export default Kanban;
|