@multicomma/arkcn 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/README.md +78 -0
- package/bin/arkcn.mjs +78 -0
- package/cli/commands.mjs +251 -0
- package/cli/project.mjs +168 -0
- package/cli/registry.mjs +50 -0
- package/cli/ui.mjs +46 -0
- package/mcp/server.mjs +149 -0
- package/package.json +201 -0
- package/registry/base.css +680 -0
- package/registry/index.json +1833 -0
- package/registry/items/accordion.json +18 -0
- package/registry/items/activity-feed.json +18 -0
- package/registry/items/alert-dialog.json +18 -0
- package/registry/items/alert.json +17 -0
- package/registry/items/angle-slider.json +17 -0
- package/registry/items/app-shell.json +28 -0
- package/registry/items/aspect-ratio.json +13 -0
- package/registry/items/attachment.json +19 -0
- package/registry/items/avatar.json +17 -0
- package/registry/items/badge.json +18 -0
- package/registry/items/breadcrumb.json +18 -0
- package/registry/items/bubble.json +18 -0
- package/registry/items/button-group.json +19 -0
- package/registry/items/button.json +18 -0
- package/registry/items/calendar.json +19 -0
- package/registry/items/canvas.json +24 -0
- package/registry/items/card.json +15 -0
- package/registry/items/carousel.json +19 -0
- package/registry/items/cascader.json +23 -0
- package/registry/items/chart.json +17 -0
- package/registry/items/chat.json +23 -0
- package/registry/items/checkbox.json +18 -0
- package/registry/items/clipboard.json +19 -0
- package/registry/items/collapsible.json +15 -0
- package/registry/items/color-picker.json +19 -0
- package/registry/items/combobox.json +20 -0
- package/registry/items/command.json +21 -0
- package/registry/items/comment-thread.json +25 -0
- package/registry/items/context-menu.json +18 -0
- package/registry/items/controllable.json +14 -0
- package/registry/items/data-grid.json +24 -0
- package/registry/items/data-table-adapter.json +14 -0
- package/registry/items/data-table.json +32 -0
- package/registry/items/date-input.json +17 -0
- package/registry/items/dialog.json +19 -0
- package/registry/items/direction.json +13 -0
- package/registry/items/drag-preview.json +16 -0
- package/registry/items/drawer.json +18 -0
- package/registry/items/dropdown-menu.json +18 -0
- package/registry/items/editable.json +17 -0
- package/registry/items/empty.json +17 -0
- package/registry/items/field.json +19 -0
- package/registry/items/file-upload.json +19 -0
- package/registry/items/floating-panel.json +19 -0
- package/registry/items/floating-toolbar.json +16 -0
- package/registry/items/form.json +14 -0
- package/registry/items/format.json +15 -0
- package/registry/items/gantt.json +22 -0
- package/registry/items/history.json +14 -0
- package/registry/items/hotkeys.json +18 -0
- package/registry/items/hover-card.json +17 -0
- package/registry/items/image-cropper.json +17 -0
- package/registry/items/input-group.json +20 -0
- package/registry/items/input-otp.json +18 -0
- package/registry/items/input.json +15 -0
- package/registry/items/item.json +19 -0
- package/registry/items/json-tree-view.json +17 -0
- package/registry/items/kanban.json +26 -0
- package/registry/items/kbd.json +15 -0
- package/registry/items/label.json +15 -0
- package/registry/items/live-region.json +16 -0
- package/registry/items/marker.json +18 -0
- package/registry/items/marquee.json +17 -0
- package/registry/items/menubar.json +19 -0
- package/registry/items/message.json +15 -0
- package/registry/items/navigation-menu.json +19 -0
- package/registry/items/node-graph.json +22 -0
- package/registry/items/number-input.json +18 -0
- package/registry/items/pagination.json +18 -0
- package/registry/items/password-input.json +18 -0
- package/registry/items/popconfirm.json +20 -0
- package/registry/items/popover.json +18 -0
- package/registry/items/progress.json +17 -0
- package/registry/items/qr-code.json +17 -0
- package/registry/items/query-builder.json +23 -0
- package/registry/items/radio-group.json +17 -0
- package/registry/items/rating-group.json +18 -0
- package/registry/items/resizable.json +17 -0
- package/registry/items/rich-text-editor.json +37 -0
- package/registry/items/row-layout.json +15 -0
- package/registry/items/scheduler.json +23 -0
- package/registry/items/scroll-area.json +17 -0
- package/registry/items/segment-group.json +17 -0
- package/registry/items/select.json +19 -0
- package/registry/items/separator.json +15 -0
- package/registry/items/sheet.json +19 -0
- package/registry/items/sidebar.json +27 -0
- package/registry/items/signature-pad.json +19 -0
- package/registry/items/skeleton.json +15 -0
- package/registry/items/slider.json +17 -0
- package/registry/items/sonner.json +17 -0
- package/registry/items/spinner.json +17 -0
- package/registry/items/steps.json +19 -0
- package/registry/items/swap.json +17 -0
- package/registry/items/switch.json +17 -0
- package/registry/items/table.json +16 -0
- package/registry/items/tabs.json +18 -0
- package/registry/items/tags-input.json +18 -0
- package/registry/items/textarea.json +15 -0
- package/registry/items/time.json +14 -0
- package/registry/items/timer.json +18 -0
- package/registry/items/toc.json +17 -0
- package/registry/items/toggle-group.json +19 -0
- package/registry/items/toggle.json +18 -0
- package/registry/items/tooltip.json +17 -0
- package/registry/items/tour.json +19 -0
- package/registry/items/transfer-list.json +24 -0
- package/registry/items/tree-select.json +24 -0
- package/registry/items/tree-view.json +18 -0
- package/registry/items/use-mobile.json +13 -0
- package/registry/items/utils.json +17 -0
- package/registry/items/virtual-list.json +16 -0
- package/src/components/ui/accordion.tsx +111 -0
- package/src/components/ui/activity-feed.tsx +228 -0
- package/src/components/ui/alert-dialog.tsx +204 -0
- package/src/components/ui/alert.tsx +55 -0
- package/src/components/ui/angle-slider.tsx +117 -0
- package/src/components/ui/app-shell.tsx +985 -0
- package/src/components/ui/aspect-ratio.tsx +35 -0
- package/src/components/ui/attachment.tsx +193 -0
- package/src/components/ui/avatar.tsx +94 -0
- package/src/components/ui/badge.tsx +45 -0
- package/src/components/ui/breadcrumb.tsx +93 -0
- package/src/components/ui/bubble.tsx +119 -0
- package/src/components/ui/button-group.tsx +79 -0
- package/src/components/ui/button.tsx +65 -0
- package/src/components/ui/calendar.tsx +172 -0
- package/src/components/ui/canvas.tsx +723 -0
- package/src/components/ui/card.tsx +69 -0
- package/src/components/ui/carousel.tsx +228 -0
- package/src/components/ui/cascader.tsx +754 -0
- package/src/components/ui/chart.tsx +303 -0
- package/src/components/ui/chat.tsx +544 -0
- package/src/components/ui/checkbox.tsx +94 -0
- package/src/components/ui/clipboard.tsx +94 -0
- package/src/components/ui/collapsible.tsx +32 -0
- package/src/components/ui/color-picker.tsx +441 -0
- package/src/components/ui/combobox.tsx +400 -0
- package/src/components/ui/command.tsx +292 -0
- package/src/components/ui/comment-thread.tsx +923 -0
- package/src/components/ui/context-menu.tsx +331 -0
- package/src/components/ui/data-grid.tsx +1227 -0
- package/src/components/ui/data-table.tsx +993 -0
- package/src/components/ui/date-input.tsx +103 -0
- package/src/components/ui/dialog.tsx +159 -0
- package/src/components/ui/direction.tsx +32 -0
- package/src/components/ui/drawer.tsx +200 -0
- package/src/components/ui/dropdown-menu.tsx +329 -0
- package/src/components/ui/editable.tsx +90 -0
- package/src/components/ui/empty.tsx +86 -0
- package/src/components/ui/field.tsx +218 -0
- package/src/components/ui/file-upload.tsx +204 -0
- package/src/components/ui/floating-panel.tsx +199 -0
- package/src/components/ui/floating-toolbar.tsx +79 -0
- package/src/components/ui/format.tsx +22 -0
- package/src/components/ui/gantt.tsx +950 -0
- package/src/components/ui/hotkeys.tsx +340 -0
- package/src/components/ui/hover-card.tsx +83 -0
- package/src/components/ui/image-cropper.tsx +100 -0
- package/src/components/ui/input-group.tsx +133 -0
- package/src/components/ui/input-otp.tsx +82 -0
- package/src/components/ui/input.tsx +18 -0
- package/src/components/ui/item.tsx +174 -0
- package/src/components/ui/json-tree-view.tsx +37 -0
- package/src/components/ui/kanban.tsx +884 -0
- package/src/components/ui/kbd.tsx +20 -0
- package/src/components/ui/label.tsx +30 -0
- package/src/components/ui/live-region.tsx +54 -0
- package/src/components/ui/marker.tsx +66 -0
- package/src/components/ui/marquee.tsx +61 -0
- package/src/components/ui/menubar.tsx +456 -0
- package/src/components/ui/message.tsx +74 -0
- package/src/components/ui/navigation-menu.tsx +202 -0
- package/src/components/ui/node-graph.tsx +1723 -0
- package/src/components/ui/number-input.tsx +148 -0
- package/src/components/ui/pagination.tsx +88 -0
- package/src/components/ui/password-input.tsx +104 -0
- package/src/components/ui/popconfirm.tsx +149 -0
- package/src/components/ui/popover.tsx +126 -0
- package/src/components/ui/progress.tsx +114 -0
- package/src/components/ui/qr-code.tsx +51 -0
- package/src/components/ui/query-builder.tsx +938 -0
- package/src/components/ui/radio-group.tsx +108 -0
- package/src/components/ui/rating-group.tsx +91 -0
- package/src/components/ui/resizable.tsx +41 -0
- package/src/components/ui/rich-text-editor.tsx +845 -0
- package/src/components/ui/scheduler.tsx +1164 -0
- package/src/components/ui/scroll-area.tsx +82 -0
- package/src/components/ui/segment-group.tsx +95 -0
- package/src/components/ui/select.tsx +354 -0
- package/src/components/ui/separator.tsx +32 -0
- package/src/components/ui/sheet.tsx +130 -0
- package/src/components/ui/sidebar.tsx +665 -0
- package/src/components/ui/signature-pad.tsx +112 -0
- package/src/components/ui/skeleton.tsx +7 -0
- package/src/components/ui/slider.tsx +183 -0
- package/src/components/ui/sonner.tsx +37 -0
- package/src/components/ui/spinner.tsx +16 -0
- package/src/components/ui/steps.tsx +152 -0
- package/src/components/ui/swap.tsx +33 -0
- package/src/components/ui/switch.tsx +83 -0
- package/src/components/ui/table.tsx +72 -0
- package/src/components/ui/tabs.tsx +100 -0
- package/src/components/ui/tags-input.tsx +153 -0
- package/src/components/ui/textarea.tsx +17 -0
- package/src/components/ui/timer.tsx +67 -0
- package/src/components/ui/toc.tsx +64 -0
- package/src/components/ui/toggle-group.tsx +89 -0
- package/src/components/ui/toggle.tsx +46 -0
- package/src/components/ui/tooltip.tsx +113 -0
- package/src/components/ui/tour.tsx +168 -0
- package/src/components/ui/transfer-list.tsx +700 -0
- package/src/components/ui/tree-select.tsx +638 -0
- package/src/components/ui/tree-view.tsx +217 -0
- package/src/components/ui/virtual-list.tsx +343 -0
- package/src/hooks/use-mobile.ts +19 -0
- package/src/lib/controllable.ts +31 -0
- package/src/lib/data-table-adapter.ts +67 -0
- package/src/lib/drag-preview.ts +39 -0
- package/src/lib/form.ts +39 -0
- package/src/lib/history.ts +55 -0
- package/src/lib/row-layout.ts +81 -0
- package/src/lib/table.ts +483 -0
- package/src/lib/time.ts +37 -0
- package/src/lib/utils.ts +6 -0
- package/src/styles/arkcn.css +764 -0
- package/src/styles/index.css +3 -0
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { preserveOffsetOnSource } from "@atlaskit/pragmatic-drag-and-drop/utils/preserve-offset-on-source"
|
|
2
|
+
import { setCustomNativeDragPreview } from "@atlaskit/pragmatic-drag-and-drop/utils/set-custom-native-drag-preview"
|
|
3
|
+
import type { ElementEventBasePayload } from "@atlaskit/pragmatic-drag-and-drop/element/adapter"
|
|
4
|
+
|
|
5
|
+
type GeneratePreviewArgs = ElementEventBasePayload & {
|
|
6
|
+
nativeSetDragImage: ((image: Element, x: number, y: number) => void) | null
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Render a crisp clone of the dragged element as the native drag preview,
|
|
11
|
+
* keeping the pointer at the same offset it had on the source. Use from a
|
|
12
|
+
* draggable's `onGenerateDragPreview`.
|
|
13
|
+
*/
|
|
14
|
+
export function cloneDragPreview(
|
|
15
|
+
{ source, location, nativeSetDragImage }: GeneratePreviewArgs,
|
|
16
|
+
options: { className?: string; element?: HTMLElement } = {}
|
|
17
|
+
) {
|
|
18
|
+
const element = options.element ?? source.element
|
|
19
|
+
const rect = element.getBoundingClientRect()
|
|
20
|
+
setCustomNativeDragPreview({
|
|
21
|
+
nativeSetDragImage,
|
|
22
|
+
getOffset: preserveOffsetOnSource({ element, input: location.current.input }),
|
|
23
|
+
render({ container }) {
|
|
24
|
+
const clone = element.cloneNode(true) as HTMLElement
|
|
25
|
+
clone.removeAttribute("data-dragging")
|
|
26
|
+
clone.removeAttribute("data-grabbed")
|
|
27
|
+
clone.style.width = `${rect.width}px`
|
|
28
|
+
clone.style.height = `${rect.height}px`
|
|
29
|
+
clone.style.boxSizing = "border-box"
|
|
30
|
+
clone.style.pointerEvents = "none"
|
|
31
|
+
clone.classList.add("shadow-xl", "rotate-1", "opacity-95")
|
|
32
|
+
if (options.className) clone.classList.add(...options.className.split(" ").filter(Boolean))
|
|
33
|
+
container.appendChild(clone)
|
|
34
|
+
return () => {
|
|
35
|
+
container.removeChild(clone)
|
|
36
|
+
}
|
|
37
|
+
},
|
|
38
|
+
})
|
|
39
|
+
}
|
package/src/lib/form.ts
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import * as React from "react"
|
|
2
|
+
|
|
3
|
+
type Errors<T> = Partial<Record<keyof T, string>>
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* A small, dependency-free form hook: values, per-field errors, and a submit
|
|
7
|
+
* handler that validates first. Pair it with the `Field*` parts
|
|
8
|
+
* (`data-invalid` on `Field`, `aria-invalid` on the control, `FieldError` for
|
|
9
|
+
* the message). Validation is a plain function so any schema library can be
|
|
10
|
+
* adapted by returning its messages keyed by field.
|
|
11
|
+
*/
|
|
12
|
+
export function useForm<T extends object>(
|
|
13
|
+
defaultValues: T,
|
|
14
|
+
validate: (values: T) => Errors<T>,
|
|
15
|
+
onSubmit: (values: T) => void,
|
|
16
|
+
options: { mode?: "onSubmit" | "onChange" } = {}
|
|
17
|
+
) {
|
|
18
|
+
const [values, setValues] = React.useState<T>(defaultValues)
|
|
19
|
+
const [errors, setErrors] = React.useState<Errors<T>>({})
|
|
20
|
+
const [submitted, setSubmitted] = React.useState(false)
|
|
21
|
+
|
|
22
|
+
const setValue = <K extends keyof T>(key: K, value: T[K]) => {
|
|
23
|
+
setValues((prev) => {
|
|
24
|
+
const next = { ...prev, [key]: value }
|
|
25
|
+
if (options.mode === "onChange" || submitted) setErrors(validate(next))
|
|
26
|
+
return next
|
|
27
|
+
})
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const handleSubmit = (event: React.FormEvent<HTMLFormElement>) => {
|
|
31
|
+
event.preventDefault()
|
|
32
|
+
setSubmitted(true)
|
|
33
|
+
const nextErrors = validate(values)
|
|
34
|
+
setErrors(nextErrors)
|
|
35
|
+
if (Object.keys(nextErrors).length === 0) onSubmit(values)
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
return { values, errors, setValue, setValues, handleSubmit }
|
|
39
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import * as React from "react"
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Undo/redo state for any immutable value. `set` records a history entry
|
|
5
|
+
* unless `{ commit: false }` is passed (live drags, typing); `checkpoint`
|
|
6
|
+
* snapshots the present before such a sequence so one undo restores it.
|
|
7
|
+
*/
|
|
8
|
+
export function useHistory<T>(initial: T | (() => T), limit = 100) {
|
|
9
|
+
const [state, setState] = React.useState(() => ({
|
|
10
|
+
past: [] as T[],
|
|
11
|
+
present: typeof initial === "function" ? (initial as () => T)() : initial,
|
|
12
|
+
future: [] as T[],
|
|
13
|
+
}))
|
|
14
|
+
const set = React.useCallback(
|
|
15
|
+
(update: T | ((prev: T) => T), options?: { commit?: boolean }) =>
|
|
16
|
+
setState((s) => {
|
|
17
|
+
const next = typeof update === "function" ? (update as (prev: T) => T)(s.present) : update
|
|
18
|
+
if (Object.is(next, s.present)) return s
|
|
19
|
+
if (options?.commit === false) return { ...s, present: next }
|
|
20
|
+
return { past: [...s.past.slice(-(limit - 1)), s.present], present: next, future: [] }
|
|
21
|
+
}),
|
|
22
|
+
[limit]
|
|
23
|
+
)
|
|
24
|
+
const checkpoint = React.useCallback(
|
|
25
|
+
() => setState((s) => ({ past: [...s.past.slice(-(limit - 1)), s.present], present: s.present, future: [] })),
|
|
26
|
+
[limit]
|
|
27
|
+
)
|
|
28
|
+
const undo = React.useCallback(
|
|
29
|
+
() =>
|
|
30
|
+
setState((s) =>
|
|
31
|
+
s.past.length
|
|
32
|
+
? { past: s.past.slice(0, -1), present: s.past[s.past.length - 1], future: [s.present, ...s.future] }
|
|
33
|
+
: s
|
|
34
|
+
),
|
|
35
|
+
[]
|
|
36
|
+
)
|
|
37
|
+
const redo = React.useCallback(
|
|
38
|
+
() =>
|
|
39
|
+
setState((s) =>
|
|
40
|
+
s.future.length ? { past: [...s.past, s.present], present: s.future[0], future: s.future.slice(1) } : s
|
|
41
|
+
),
|
|
42
|
+
[]
|
|
43
|
+
)
|
|
44
|
+
const reset = React.useCallback((value: T) => setState({ past: [], present: value, future: [] }), [])
|
|
45
|
+
return {
|
|
46
|
+
present: state.present,
|
|
47
|
+
set,
|
|
48
|
+
checkpoint,
|
|
49
|
+
undo,
|
|
50
|
+
redo,
|
|
51
|
+
reset,
|
|
52
|
+
canUndo: state.past.length > 0,
|
|
53
|
+
canRedo: state.future.length > 0,
|
|
54
|
+
}
|
|
55
|
+
}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import type { CanvasDropDetails } from "@/components/ui/canvas"
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Rows-and-columns layout helpers for the Canvas primitive. A layout is
|
|
5
|
+
* `Row[]`, each row a list of items with a `width` (flex-grow weight). Drops
|
|
6
|
+
* above/below an item create a row, beside it a column; the resize handle
|
|
7
|
+
* shifts width between neighbours. Shared by the form builder and the widgets
|
|
8
|
+
* page.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
export type RowItem = { id: string; width: number }
|
|
12
|
+
export type Row<T extends RowItem> = { id: string; items: T[] }
|
|
13
|
+
|
|
14
|
+
const MIN_SHARE = 0.12
|
|
15
|
+
|
|
16
|
+
export function applyRowDrop<T extends RowItem>(
|
|
17
|
+
rows: Row<T>[],
|
|
18
|
+
details: CanvasDropDetails,
|
|
19
|
+
options: { create: (data: unknown) => T | null; rowId: () => string }
|
|
20
|
+
): Row<T>[] {
|
|
21
|
+
let item: T | undefined
|
|
22
|
+
let next = rows
|
|
23
|
+
let sourceRowIndex = -1
|
|
24
|
+
if (details.source.type === "node") {
|
|
25
|
+
const id = details.source.id
|
|
26
|
+
item = rows.flatMap((r) => r.items).find((i) => i.id === id)
|
|
27
|
+
sourceRowIndex = rows.findIndex((r) => r.items.some((i) => i.id === id))
|
|
28
|
+
next = rows.map((r) => ({ ...r, items: r.items.filter((i) => i.id !== id) })).filter((r) => r.items.length > 0)
|
|
29
|
+
} else {
|
|
30
|
+
item = options.create(details.source.data) ?? undefined
|
|
31
|
+
}
|
|
32
|
+
if (!item) return rows
|
|
33
|
+
|
|
34
|
+
const target = details.target
|
|
35
|
+
if (target.type === "area") return [...next, { id: options.rowId(), items: [{ ...item, width: 1 }] }]
|
|
36
|
+
|
|
37
|
+
// Dropping a node on its own top/bottom edge (keyboard: "move up/down" while it has siblings)
|
|
38
|
+
// pulls it out into a new row above or below its current row.
|
|
39
|
+
if (details.source.type === "node" && target.id === details.source.id) {
|
|
40
|
+
if (target.edge !== "top" && target.edge !== "bottom") return rows
|
|
41
|
+
const stillThere = next.length === rows.length
|
|
42
|
+
if (!stillThere) return rows
|
|
43
|
+
const at = target.edge === "top" ? sourceRowIndex : sourceRowIndex + 1
|
|
44
|
+
const newRow = { id: options.rowId(), items: [{ ...item, width: 1 }] }
|
|
45
|
+
return [...next.slice(0, at), newRow, ...next.slice(at)]
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
const rowIndex = next.findIndex((r) => r.items.some((i) => i.id === target.id))
|
|
49
|
+
if (rowIndex < 0) return rows
|
|
50
|
+
const row = next[rowIndex]
|
|
51
|
+
const index = row.items.findIndex((i) => i.id === target.id)
|
|
52
|
+
if (target.edge === "top" || target.edge === "bottom") {
|
|
53
|
+
const at = target.edge === "top" ? rowIndex : rowIndex + 1
|
|
54
|
+
const newRow = { id: options.rowId(), items: [{ ...item, width: 1 }] }
|
|
55
|
+
return [...next.slice(0, at), newRow, ...next.slice(at)]
|
|
56
|
+
}
|
|
57
|
+
const mean = row.items.reduce((s, i) => s + i.width, 0) / row.items.length
|
|
58
|
+
const at = target.edge === "left" ? index : index + 1
|
|
59
|
+
const items = [...row.items.slice(0, at), { ...item, width: mean }, ...row.items.slice(at)]
|
|
60
|
+
return next.map((r, i) => (i === rowIndex ? { ...r, items } : r))
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/** Move width from item `index` to `index + 1` by a fraction of the row. */
|
|
64
|
+
export function resizeRowItems<T extends RowItem>(row: Row<T>, index: number, deltaFraction: number): Row<T> {
|
|
65
|
+
const total = row.items.reduce((s, i) => s + i.width, 0)
|
|
66
|
+
const delta = deltaFraction * total
|
|
67
|
+
const a = row.items[index]
|
|
68
|
+
const b = row.items[index + 1]
|
|
69
|
+
if (!a || !b) return row
|
|
70
|
+
const min = MIN_SHARE * total
|
|
71
|
+
const clamped = Math.max(min - a.width, Math.min(delta, b.width - min))
|
|
72
|
+
if (clamped === 0) return row
|
|
73
|
+
const items = row.items.map((i, k) =>
|
|
74
|
+
k === index ? { ...i, width: a.width + clamped } : k === index + 1 ? { ...i, width: b.width - clamped } : i
|
|
75
|
+
)
|
|
76
|
+
return { ...row, items }
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
export function removeRowItem<T extends RowItem>(rows: Row<T>[], id: string): Row<T>[] {
|
|
80
|
+
return rows.map((r) => ({ ...r, items: r.items.filter((i) => i.id !== id) })).filter((r) => r.items.length > 0)
|
|
81
|
+
}
|