Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add todo list application #2016

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 18 additions & 13 deletions packages/boxel-ui/addon/src/components/drag-and-drop/index.gts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ import Component from '@glimmer/component';
import { tracked } from '@glimmer/tracking';

import { and, eq } from '../../helpers/truth-helpers.ts';
import type {
DndDraggableItemModifier,
DndDropTargetModifier,
DndSortableItemModifier,
} from '../../types/drag-and-drop.ts';

const isFastBoot = typeof (globalThis as any).FastBoot !== 'undefined';

Expand Down Expand Up @@ -48,13 +53,16 @@ export default class DndKanbanBoard extends Component<
DndKanbanBoardSignature<DndColumn>
> {
@tracked areModifiersLoaded = false;
@tracked DndDraggableItemModifier: any = null;
@tracked DndDropTargetModifier: any = null;
@tracked DndSortableItemModifier: any = null;
@tracked insertAfter: any;
@tracked insertAt: any;
@tracked insertBefore: any;
@tracked removeItem: any;
@tracked DndDraggableItemModifier: DndDraggableItemModifier | undefined;
@tracked DndDropTargetModifier: DndDropTargetModifier | undefined;
@tracked DndSortableItemModifier: DndSortableItemModifier | undefined;
@tracked insertAfter: <T>(array: T[], index: number, element: T) => T[] =
undefined as any;
@tracked insertAt: <T>(array: T[], index: number, element: T) => T[] =
undefined as any;
@tracked insertBefore: <T>(array: T[], index: number, element: T) => T[] =
undefined as any;
@tracked removeItem: <T>(array: T[], item: T) => T[] = undefined as any;
@tracked draggedCard: DndItem | null = null;

constructor(owner: unknown, args: DndKanbanBoardArgs<DndColumn>) {
Expand All @@ -70,25 +78,22 @@ export default class DndKanbanBoard extends Component<
// See: https://github.com/alvarocastro/ember-draggable-modifiers/issues/1 and https://github.com/cardstack/boxel/pull/1683#discussion_r1803979937
async loadModifiers() {
// @ts-expect-error Dynamic imports are only supported when the '--module' flag is set to 'es2020', 'es2022', 'esnext', 'commonjs', 'amd', 'system', 'umd', 'node16', or 'nodenext'
const DndDraggableItemModifier = await import(
const DndDraggableItemModifier: DndDraggableItemModifier = await import(
'ember-draggable-modifiers/modifiers/draggable-item'
);

// @ts-expect-error Dynamic imports are only supported when the '--module' flag is set to 'es2020', 'es2022', 'esnext', 'commonjs', 'amd', 'system', 'umd', 'node16', or 'nodenext'
const DndDropTargetModifier = await import(
const DndDropTargetModifier: DndDropTargetModifier = await import(
'ember-draggable-modifiers/modifiers/drop-target'
);

// @ts-expect-error Dynamic imports are only supported when the '--module' flag is set to 'es2020', 'es2022', 'esnext', 'commonjs', 'amd', 'system', 'umd', 'node16', or 'nodenext'
const DndSortableItemModifier = await import(
const DndSortableItemModifier: DndSortableItemModifier = await import(
'ember-draggable-modifiers/modifiers/sortable-item'
);
// @ts-expect-error Dynamic imports are only supported when the '--module' flag is set to 'es2020', 'es2022', 'esnext', 'commonjs', 'amd', 'system', 'umd', 'node16', or 'nodenext'
const arrayUtils = await import('ember-draggable-modifiers/utils/array');

this.DndDraggableItemModifier = DndDraggableItemModifier.default;
this.DndDropTargetModifier = DndDropTargetModifier.default;
this.DndSortableItemModifier = DndSortableItemModifier.default;
this.insertAfter = arrayUtils.insertAfter;
this.insertAt = arrayUtils.insertAt;
this.insertBefore = arrayUtils.insertBefore;
Expand Down
71 changes: 71 additions & 0 deletions packages/boxel-ui/addon/src/types/drag-and-drop.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import Modifier from 'ember-modifier';

export interface DndDraggableItemSignature {
Args: {
Named: {
data?: any;
disabled?: boolean;
dragHandleElement?: string;
group?: string;
isDraggingClass?: string;
onDragEnd?: (event: DragEvent) => void;
onDragStart?: (event: DragEvent) => void;
onDrop?: (event: { destination: unknown; source: unknown }) => void;
};
Positional: [];
};
}

export interface DndDropTargetSignature {
Args: {
Named: {
accepts?: string[];
allowDropOnChildren?: boolean;
allowDropOnItself?: boolean;
allowedEdges?: ('top' | 'bottom' | 'left' | 'right')[];
canDrop?: (event: DragEvent) => boolean;
data?: any;
direction?: 'horizontal' | 'vertical';
disabled?: boolean;
group?: string;
isOnTargetClass?: string;
onDragEnter?: (event: DragEvent) => void;
onDragLeave?: (event: DragEvent) => void;
onDrop?: (event: DragEvent, item: any) => void;
onHover?: (event: DragEvent) => void;
};
Positional: [];
};
}

export interface DndSortableItemSignature {
Args: {
Named: {
accepts?: string[];
allowDropOnChildren?: boolean;
allowDropOnItself?: boolean;
allowedEdges?: ('top' | 'bottom' | 'left' | 'right')[];
canDrop?: (event: DragEvent) => boolean;
data?: any;
direction?: 'horizontal' | 'vertical';
disabled?: boolean;
disabledDrag?: boolean;
disabledDrop?: boolean;
dragHandleElement?: string;
group?: string;
isDraggingClass?: string;
isOnTargetClass?: string;
onDragEnd?: (event: DragEvent) => void;
onDragEnter?: (event: DragEvent) => void;
onDragLeave?: (event: DragEvent) => void;
onDragStart?: (event: DragEvent) => void;
onDrop?: (event: DragEvent, item: any) => void;
onHover?: (event: DragEvent) => void;
};
Positional: [];
};
}

export type DndDraggableItemModifier = Modifier<DndDraggableItemSignature>;
export type DndDropTargetModifier = Modifier<DndDropTargetSignature>;
export type DndSortableItemModifier = Modifier<DndSortableItemSignature>;
11 changes: 11 additions & 0 deletions packages/experiments-realm/todo-app.gts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import {
field,
CardDef,
linksToMany,
} from 'https://cardstack.com/base/card-api';
import { Todo } from './todo';

export class TodoApp extends CardDef {
static displayName = 'Todo App';
@field todos = linksToMany(() => Todo);
}
Loading