// Вкладка «Задачи»: канбан с перетаскиванием на Pointer Events, фильтры, шторка задачи, корзина.import{Fragment}from'preact';import{ useEffect, useLayoutEffect, useMemo, useRef, useState, useCallback }from'preact/hooks';import{
html, rpc, act, toast, mutateRes, peekRes, invalidate, useRes, saveUi, svc, humanError,TASK_STATUSES,STATUS_LABEL,PRIORITIES,PRIORITY_LABEL, shortId, copyText, fmtDate, fmtDateTime, relTime,
isOverdue, toDateInput, roleAtLeast, describeAction, reducedMotion useTick
keyFors
key s
snapshot key
patch changes
changes patch members m changesdisplayName
key d d d t taskId t patch t
s taskId changes
e
key snapshot
e e
key s
snapshot key
key d d d t task
s task
key d d t task d d d task
err s task
err key d d d t task
e
key snapshot
e e
col tasks t status t draggedId a b t
at beforeId colbeforeId
at coldraggedId
colat draggedId
col
key s
snapshot key
pos orderedIds id i
key d d d post t status post t
s status orderedIds
e
key snapshot
e e
p p
html
due
over due status
html
text setText
v raw
v valuev value
value v
listId
html
$disabled value html
divdiv style
input type $ v value$v disabled$disabled arialabel
onChange$ x e x x
$v disabled html
divdiv $ t readOnly dragging
style$dragging
dataid$t tabindex role arialabel$t t
ariaroledescription$readOnly
onPointerDown$onPointerDown onKeyDown$onKey
onClick$ readOnly e
div $tdiv
$tlength html
div
$ p$t
button type title onPointerDown$ e
onClick$ e t #$tbutton
$ due$t status$t
$member html
t html
html
div
divdiv button type onClick$ $ name size$ Добавитьbuttondivdiv
input ref$ref value$text placeholder disabled$busy arialabel$ status
onInput$ e
onKeyDown$
e e
e e e
onBlur$ text
div$dxpx $dypxdataid$tr stpx $tr stpx$ev stpx $ev stpxdataiddataidПеремещено в «$ns»div
div
div
div
$ name size$
input value$f placeholder arialabel
onInput$ e
onKeyDown$ e f e e
$f html
div
button type title arialabel onClick$ $ name button
$canEdit html
div
div style
div style
$ html
div
span span
$ $ f items$assigneeItems label width$
$selAssignees html html
$narrow
$ items$prioItems label width$
$ name size$ $narrow $f html
$filtersActive html
div
div
$data html
board data html
htmldiv key style$ drag divsection $ hot key$c datastatus$c role arialabel$c
div span $ cspanspan $cspanspan $visibleCountspandiv
div
$items
$list hot html
div
$canEdit html
section
$ s$s task$openTask open$openTask onClose$ members$members canEdit$canEdit allLabels$allLabels
$ s$s open$creating onClose$ members$members allLabels$allLabels onCreated$ tid
$ s$s open$trashOpen onClose$ canEdit$canEdit
div$t$t$ open$open onClose$close title$html label
headExtra$html
div style
$ value$title rows disabled$canEdit arialabel max$
onFocus$ editing
onInput$ e
onBlur$commitTitle
onKeyDown$ e e e
$ block value$t disabled$canEdit label onChange$ v
options$ x x
div
span Приоритетspan
$ sm value$t disabled$canEdit label options$prioOptions onChange$ v
span Исполнительspan
div style
$t html
$ sm value$t disabled$canEdit label options$members onChange$ v
div
span Срокspan
$ value$t disabled$canEdit onChange$ v
span styleМеткиspan
$ value$t disabled$canEdit suggestions$allLabels onChange$ v
div
$ label
$ value$desc disabled$canEdit max$ placeholder$canEdit
onFocus$ editing
onInput$ e onBlur$commitDesc
onKeyDown$ e e e e e
div а $creatordisplayName · $t$t t t t div
div
div $ name size$ Связанные коммитыdiv
$commits commits html
commitslength html
html
div
div
div $ name size$ Историяdiv
$history history html
historylength html
html
div
div
empty
v setV empty
err setErr
open empty sid open
x patch
epreventDefault
v
r s v v v
rid s d d t r d d d v r
ex ex
html
trash open keyFors s
keyFors d d x t
err s t
err
html
`<divclass="labels-ed">${value.map((l)=> html`<spanclass="tag"key=${l}>${l}${!disabled ? html`<buttontype="button"aria-label=${'Убрать метку '+ l}onClick=${()=>onChange(value.filter((x)=> x !== l))}><${Icon}name="x"size=${11}/></button>`:null}</span>`)}${!disabled && value.length<8? html`<input value=${text} list=${listId} placeholder=${value.length?'':'Добавить метку…'} aria-label="Новая метка"
onInput=${(e)=>setText(e.currentTarget.value)}
onKeyDown=${(e)=>{if(e.key==='Enter'|| e. e text
e text value value
onBlur=${()=> text &&add(text)} />
<datalistid=${listId}>${suggestions.filter((x)=>!value.includes(x)).map((x)=> html`<optionvalue=${x}key=${x}/>`)}</datalist>`
`<divclass="kb-scroll"><divclass="kb-cols">${TASK_STATUSES.map((c, i)=> html`<divclass="kb-col"key=${c.id}><divclass="kb-col-h"><${Skel}w=${80}hgt=${12}/></div><divclass="kb-list">${Array.from({length:3-(i %2)},(_, k)=> html`<${Skel}key=${k}hgt=${68- k *8}r=${10}/>`</div></div>`)}</div></div>`
:
.
error
&&
!
?
`<${Empty}icon="alert"title="Не удалось загрузить доску"text=${humanError(board.error)}><buttonclass="btn"onClick=${board.reload}>Повторить</button><//>`
:
`<divclass="kb-scroll"ref=${scrollRef}><divclass="kb-cols"ref=${colsRef}role="list">${TASK_STATUSES.map((c)=>{const list = columns[c.id]??[];const hot = drag && drag.status=== c.id;const visibleCount = list.filter((t)=> t.id!== drag?.id).length;let k =0;const items =[];
list.forEach((t)=>{const isDragged = drag?.id === t.id;if(hot &&!isDragged && k === drag.index) items.push(html`<divclass="kb-ph"key="__ph"style=${{height: drag.height+'px'}}></div>`);if(!isDragged) k++;const m = memberById.get(t.assigneeId);
items.push(html`<${TaskCard}key=${t.id}t=${t}member=${m}readOnly=${!canEdit}dragging=${isDragged}onPointerDown=${onCardPointerDown(t)}onOpen);});
if (hot && drag.index >= k) items.push(html`
<
class
=
"kb-ph"
=
"__ph"
=
{
{
height
:
.
height
+
'px'
}
}
>
<
/
>
`);
return html`
<
class
=
{
'kb-col'
+
(
?
' hot'
:
''
)
}
=
{
.
id
}
-
=
{
.
id
}
=
"listitem"
-
=
{
.
label
}
>
<
class
=
"kb-col-h"
>
<
class
=
{
'st '
+
.
id
}
>
<
/
>
<
class
=
"ell"
>
{
.
label
}
<
/
>
<
class
=
"cnt"
>
{
}
<
/
>
<
/
>
<
class
=
"kb-list"
>
{
}
{
!
.
length
&&
!
?
`<divclass="kb-empty-col">${filtersActive ?'Нет задач по фильтру':'Пусто'}</div>`
:
null
}
<
/
>
{
?
`<${QuickAdd}s=${s}status=${c.id}/>`
:
null
}
<
/
>
`;
})}
</div>
${canEdit ? html`<div class="faint xs" style="padding:10px 2px 0">Перетащите карточку или используйте <span class="kbd">[</span> <span class="kbd">]</span> для смены колонки, <span class="kbd">Alt</span>+<span class="kbd">↑↓</span> — порядок.</div>`: html`<div class="faint xs" style="padding:10px 2px 0"><${Icon} name="eye" size=${12} /> Режим наблюдателя: доска только для чтения.</div>`}
</div>`
}
<
{
TaskDrawer
}
=
{
}
=
{
}
=
{
!
!
}
=
{
(
)
=>
setOpenId
(
null
)
}
=
{
}
=
{
}
=
{
}
/
>
<
{
NewTaskSheet
}
=
{
}
=
{
}
=
{
(
)
=>
setCreating
(
false
)
}
=
{
}
=
{
}
=
{
(
t
)
=>
?.
&&
setOpenId
(
null
)
}
/
>
<
{
TrashSheet
}
=
{
}
=
{
}
=
{
(
)
=>
setTrashOpen
(
false
)
}
=
{
}
/
>
<
/
>
`;
}
// ---------------------------------------------------------------- шторка задачи
function TaskDrawer({ s, task, open, onClose, members, canEdit, allLabels }) {
const [last, setLast] = useState(task);
useEffect(() => { if (task) setLast(task); }, [task]);
const t = task || last;
const [title, setTitle] = useState(t?.title ?? '');
const [desc, setDesc] = useState(t?.description ?? '');
const editing = useRef({ title: false, desc: false });
useEffect(() => {
if (!t) return;
if (!editing.current.title) setTitle(t.title);
if (!editing.current.desc) setDesc(t.description ?? '');
}, [t?.id, t?.title, t?.description]);
const history = useRes(open && t ? `
// ---------------------------------------------------------------- новая задача
function
NewTaskSheet
(
{ s, open, onClose, members, allLabels }
)
{
const
=
{
title
:
''
,
description
:
''
,
status
:
'todo'
,
priority
:
'normal'
,
assigneeId
:
''
,
labels
:
[
]
,
dueAt
:
null
}
;
const
[
,
]
=
useState
(
)
;
const
[
,
]
=
useState
(
''
)
;
useEffect
(
(
)
=>
{
if
(
)
{
setV
(
{
...
,
assigneeId
:
me
(
)
?.
||
''
}
)
;
setErr
(
''
)
;
}
}
,
[
]
)
;
const
set
=
(
patch
)
=>
setV
(
(
x
)
=>
(
{
...
,
...
}
)
)
;
const
submit
=
async
(
e
)
=>
{
?.
?.
(
)
;
if
(
!
.
title
.
trim
(
)
)
{
setErr
(
'Введите название'
)
;
return
;
}
try
{
const
=
await
rpc
(
'createTask'
,
{
teamId
:
.
teamId
,
...
,
title
:
.
title
.
trim
(
)
,
assigneeId
:
.
assigneeId
||
null
}
)
;
if
(
?.
)
mutateRes
(
boardKey
(
)
,
(
d
)
=>
&&
(
.
tasks
.
some
(
(
t
)
=>
.
id
===
.
id
)
?
:
{
...
,
tasks
:
[
...
.
tasks
,
{
position
:
1e9
,
...
,
...
}
]
}
)
)
;
invalidate
(
'board'
)
;
toast
(
'Задача создана'
,
{
kind
:
'ok'
}
)
;
onClose
(
)
;
}
catch
(
)
{
setErr
(
humanError
(
)
)
;
}
}
;
return
`<${Layer}kind="sheet"open=${open}onClose=${onClose}title="Новая задача"initialFocus="input"footer=${html`<buttontype="button"class="btn"onClick=${onClose}>Отмена</button><${AsyncButton}class="btn primary"onClick=${submit}>Создать задачу<//>`}><formclass="stack"onSubmit=${submit}><${Field}label="Название"><inputclass=${'inp'+(err ?' err':'')}value=${v.title}maxlength="200"placeholder="Что нужно сделать?"onInput=${(e)=>{set({title: e.currentTarget.value});setErr<//>
<${Field}label="Описание"><${AutoTextarea}class="ta"value=${v.description}max=${220}placeholder="Подробности, ссылки, критерии готовности"onInput=${(e)=>set({description: e.currentTarget.value})}/><//>
<${Seg}blockvalue=${v.status}label="Статус"onChange=${(x)=>set({status: x })}options=${TASK_STATUSES}/><divclass="props"><spanclass="k">Приоритет</span><${Select}smvalue=${v.priority}options=${prioOptions}label="Приоритет"onChange=${(x)=>set({priority: x })}/><spanclass="k">Исполнитель</span><${Select}smvalue=${v.assigneeId}options=${memberOptions(members)}label="Исполнитель"onChange=${(x)=>set({assigneeId: x })}/><spanclass="k">Срок</span><${DueInput}value=${v.dueAt}onChange=${(x)=>set({dueAt: x })}/><spanclass="k"style="align-self:start;padding-top:7px">Метки</span><${LabelsEditor}value=${v.labels}suggestions=${allLabels}onChange=${(x)=>set({labels: x })}/></div>${err ? html`<divclass="err-box"><${Icon}name="alert"/>${err}</div>`:null}<buttontype="submit"hidden></button></form>
<//>`