-
-
Notifications
You must be signed in to change notification settings - Fork 651
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
57 changed files
with
448 additions
and
9,784 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
module.exports = { | ||
root: true, | ||
extends: ['dnd-kit', 'plugin:storybook/recommended'] | ||
}; | ||
extends: ['@dnd-kit/eslint-config'], | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import { dirname, join, resolve } from "path"; | ||
|
||
function getAbsolutePath(value) { | ||
return dirname(require.resolve(join(value, "package.json"))); | ||
} | ||
|
||
const config = { | ||
stories: ["../stories/*.stories.tsx", "../stories/**/*.stories.tsx"], | ||
addons: [ | ||
getAbsolutePath("@storybook/addon-links"), | ||
getAbsolutePath("@storybook/addon-essentials"), | ||
getAbsolutePath("@storybook/addon-docs"), | ||
], | ||
framework: { | ||
name: getAbsolutePath("@storybook/react-vite"), | ||
options: {}, | ||
}, | ||
|
||
core: {}, | ||
|
||
async viteFinal(config, { configType }) { | ||
// customize the Vite config here | ||
return { | ||
...config, | ||
define: { "process.env": {} }, | ||
resolve: { | ||
alias: [ | ||
{ | ||
find: "ui", | ||
replacement: resolve(__dirname, "../../../packages/ui/"), | ||
}, | ||
], | ||
}, | ||
}; | ||
}, | ||
|
||
docs: { | ||
autodocs: true, | ||
}, | ||
}; | ||
|
||
export default config; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,47 +1,42 @@ | ||
{ | ||
"name": "@dnd-kit/docs", | ||
"name": "@dnd-kit/storybook", | ||
"version": "0.0.0", | ||
"type": "module", | ||
"private": true, | ||
"scripts": { | ||
"dev": "storybook dev -p 6006", | ||
"build:storybook": "storybook build", | ||
"build": "storybook build --docs", | ||
"preview-storybook": "serve storybook-static", | ||
"clean": "rm -rf .turbo && rm -rf node_modules" | ||
"clean": "rm -rf .turbo && rm -rf node_modules", | ||
"lint": "eslint ./stories/*.stories.tsx --max-warnings 0" | ||
}, | ||
"dependencies": { | ||
"@dnd-kit/abstract": "*", | ||
"@dnd-kit/dom": "*", | ||
"@dnd-kit/react": "*", | ||
"@dnd-kit/state-management": "*", | ||
"@dnd-kit/helpers": "*", | ||
"@tanstack/react-virtual": "^3.0.0-beta.54", | ||
"prismjs": "^1.29.0", | ||
"clipboard": "^2.0.11", | ||
"prismjs": "^1.29.0", | ||
"react": "^18.2.0", | ||
"react-dom": "^18.2.0", | ||
"use-pan-and-zoom": "^0.6.5", | ||
"react-tiny-virtual-list": "^2.2.0", | ||
"react-window": "1.8.9" | ||
}, | ||
"devDependencies": { | ||
"@dnd-kit/abstract": "*", | ||
"@dnd-kit/config-eslint": "*", | ||
"@dnd-kit/dom": "*", | ||
"@dnd-kit/react": "*", | ||
"@dnd-kit/state-management": "*", | ||
"@storybook/addon-actions": "^7.3.2", | ||
"@storybook/addon-docs": "^7.3.2", | ||
"@storybook/addon-essentials": "^7.3.2", | ||
"@storybook/addon-links": "^7.3.2", | ||
"@storybook/manager-api": "^7.3.2", | ||
"@storybook/react": "^7.3.2", | ||
"@storybook/react-vite": "^7.3.2", | ||
"@storybook/theming": "^7.3.2", | ||
"storybook-dark-mode": "^3.0.1", | ||
"@vitejs/plugin-react": "^4.0.3", | ||
"eslint-plugin-storybook": "^0.6.13", | ||
"serve": "^13.0.2", | ||
"storybook": "next", | ||
"typescript": "^5.1.6", | ||
"vite": "^4.4.7" | ||
"@dnd-kit/eslint-config": "*", | ||
"@storybook/addon-actions": "^7.6.7", | ||
"@storybook/addon-docs": "^7.6.7", | ||
"@storybook/addon-essentials": "^7.6.7", | ||
"@storybook/addon-links": "^7.6.7", | ||
"@storybook/react": "^7.6.7", | ||
"@storybook/react-vite": "^7.6.7", | ||
"@vitejs/plugin-react": "^4.2.1", | ||
"eslint": "^8.56.0", | ||
"serve": "^14.2.1", | ||
"storybook": "^7.6.7", | ||
"storybook-dark-mode": "^3.0.3", | ||
"typescript": "^5.3.3", | ||
"vite": "^5.0.10" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import './Item.css'; | ||
|
||
export class Item extends HTMLElement { | ||
connectedCallback() { | ||
this.classList.add('Item'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export {Item} from './Item'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
export {Code, Info, Preview} from './docs'; | ||
export {Button} from './Button'; | ||
export {Dropzone} from './Dropzone'; | ||
export {Item} from './Item'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
apps/docs/stories/react/Sortable/MultipleLists/docs/examples/QuickStart.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
export interface Item { | ||
id: string; | ||
children: Item[]; | ||
collapsed?: boolean; | ||
} | ||
|
||
export interface FlattenedItem extends Item { | ||
parentId: string | null; | ||
depth: number; | ||
index: number; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
import {UniqueIdentifier} from '@dnd-kit/abstract'; | ||
import type {Item, FlattenedItem} from './types'; | ||
|
||
export function flattenTree( | ||
items: Item[], | ||
parentId: string | null = null, | ||
depth = 0 | ||
): FlattenedItem[] { | ||
return items.reduce<FlattenedItem[]>((acc, item, index) => { | ||
return [ | ||
...acc, | ||
{...item, parentId, depth, index}, | ||
...flattenTree(item.children, item.id, depth + 1), | ||
]; | ||
}, []); | ||
} | ||
|
||
export function buildTree(flattenedItems: FlattenedItem[]): Item[] { | ||
const root: Item = {id: 'root', children: []}; | ||
const nodes: Record<string, Item> = {[root.id]: root}; | ||
const items = flattenedItems.map((item) => ({...item, children: []})); | ||
|
||
for (const item of items) { | ||
const {id, children} = item; | ||
const parentId = item.parentId ?? root.id; | ||
const parent = nodes[parentId] ?? items.find(({id}) => id === parentId); | ||
|
||
nodes[id] = {id, children}; | ||
parent.children.push(item); | ||
} | ||
|
||
return root.children; | ||
} | ||
|
||
export function getDragDepth(offset: number, indentationWidth: number) { | ||
return Math.round(offset / indentationWidth); | ||
} | ||
|
||
export function getProjection( | ||
items: FlattenedItem[], | ||
targetId: UniqueIdentifier, | ||
projectedDepth: number | ||
) { | ||
const targetItemIndex = items.findIndex(({id}) => id === targetId); | ||
const previousItem = items[targetItemIndex - 1]; | ||
const nextItem = items[targetItemIndex + 1]; | ||
const maxDepth = getMaxDepth(previousItem); | ||
const minDepth = getMinDepth(previousItem, nextItem); | ||
let depth = projectedDepth; | ||
|
||
if (projectedDepth >= maxDepth) { | ||
depth = maxDepth; | ||
} else if (projectedDepth < minDepth) { | ||
depth = minDepth; | ||
} | ||
|
||
return {depth, maxDepth, minDepth, parentId: getParentId()}; | ||
|
||
function getParentId() { | ||
if (depth === 0 || !previousItem) { | ||
return null; | ||
} | ||
|
||
if (depth === previousItem.depth) { | ||
return previousItem.parentId; | ||
} | ||
|
||
if (depth > previousItem.depth) { | ||
return previousItem.id; | ||
} | ||
|
||
const newParent = items | ||
.slice(0, targetItemIndex) | ||
.reverse() | ||
.find((item) => item.depth === depth)?.parentId; | ||
|
||
return newParent ?? null; | ||
} | ||
} | ||
|
||
function getMaxDepth(previousItem: FlattenedItem) { | ||
if (previousItem) { | ||
return previousItem.depth + 1; | ||
} | ||
|
||
return 0; | ||
} | ||
|
||
function getMinDepth(previousItem: FlattenedItem, nextItem: FlattenedItem) { | ||
if (previousItem && nextItem) { | ||
return Math.min(previousItem.depth, nextItem.depth); | ||
} | ||
|
||
if (nextItem) { | ||
return nextItem.depth; | ||
} | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.