Skip to content

Commit

Permalink
Basic turbopack shit
Browse files Browse the repository at this point in the history
  • Loading branch information
PuruVJ committed Dec 21, 2024
1 parent 5613c08 commit 191e098
Show file tree
Hide file tree
Showing 67 changed files with 188 additions and 322 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ dist/
.DS_Store
.env
.pnpm-store/
.turbo
8 changes: 5 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
"type": "module",
"scripts": {
"changeset": "changeset",
"compile": "pnpm -r compile",
"docs:build": "pnpm compile && pnpm sizes && cd docs && pnpm build",
"compile": "turbo run compile",
"docs:build": "turbo run docs#build",
"ci:version": "changeset version",
"ci:release": "changeset publish",
"sizes": "tsx scripts/gather-sizes.ts"
Expand All @@ -29,6 +29,7 @@
"terser": "^5.26.0",
"tsup": "^8.0.1",
"tsx": "^4.6.2",
"turbo": "^2.3.3",
"typescript": "^5.4.5",
"vite": "^5.2.9",
"vitest": "^1.5.0",
Expand All @@ -38,5 +39,6 @@
"overrides": {
"vite": "^6.0"
}
}
},
"packageManager": "[email protected]"
}
49 changes: 29 additions & 20 deletions packages/core/src/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,27 @@ export interface DraggableInstance {

type Result<T> = { ok: true; value: T } | { ok: false; error: unknown };

export const DEFAULTS = {
plugins: [
ignoreMultitouch(),
stateMarker(),
applyUserSelectHack(),
transform(),
threshold(),
touchAction(),
],

onError: (error: ErrorInfo) => {
console.error(error);
},

delegate: () => document.body,
};

export function createDraggable({
plugins: initial_plugins = [],
delegate: delegateTargetFn = () => document.body,
onError,
plugins: initial_plugins = DEFAULTS.plugins,
delegate: delegateTargetFn = DEFAULTS.delegate,
onError = DEFAULTS.onError,
}: {
plugins?: Plugin[];
delegate?: () => HTMLElement;
Expand Down Expand Up @@ -368,7 +385,13 @@ export function createDraggable({
let has_changes = false;

// Check if this instance is currently involved in any drag operation
const is_active = Array.from(active_nodes.values()).includes(instance.root_node);
let is_active = false;
for (const node of active_nodes.values()) {
if (node === instance.root_node) {
is_active = true;
break;
}
}

// During drag, only update plugins that opted into live updates
if (is_active && (instance.ctx.isDragging || instance.ctx.isInteracting)) {
Expand Down Expand Up @@ -503,7 +526,8 @@ export function createDraggable({
instances.set(node, instance);

return {
update: (new_opts: Plugin[]) => update(instance, new_opts),
update: (newOptions: Plugin[]) => update(instance, newOptions),

destroy() {
for (const [pointer_id, active_node] of active_nodes) {
if (active_node === node) {
Expand All @@ -521,18 +545,3 @@ export function createDraggable({
},
};
}

export const DEFAULT_plugins = [
ignoreMultitouch(),
stateMarker(),
applyUserSelectHack(),
transform(),
threshold(),
touchAction(),
];

export const DEFAULT_onError = (error: ErrorInfo) => {
console.error(error);
};

export const DEFAULT_delegate = () => document.body;
10 changes: 3 additions & 7 deletions packages/svelte/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
import { createDraggable, DEFAULT_delegate, DEFAULT_onError, DEFAULT_plugins } from '@neodrag/core';
import { createDraggable } from '@neodrag/core';
import type { Plugin } from '@neodrag/core/plugins';
import type { Action } from 'svelte/action';

const { draggable: core, instances } = createDraggable({
delegate: DEFAULT_delegate,
plugins: DEFAULT_plugins,
onError: DEFAULT_onError,
});
const { draggable: core, instances } = createDraggable();

export const draggable = core as Action<HTMLElement | SVGElement, Plugin[] | undefined>;
export { instances };
export * from '@neodrag/core/plugins';
export { instances };
2 changes: 1 addition & 1 deletion packages/svelte/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"target": "ESNext",
"declaration": true,
"emitDeclarationOnly": true,
"declarationDir": "dist/",
"declarationDir": "dist",
"strict": true,
"esModuleInterop": true,
"moduleResolution": "Bundler",
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "demo",
"name": "react-demo",
"private": true,
"version": "0.0.1",
"scripts": {
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "demo",
"name": "solid-demo",
"version": "0.0.0",
"private": true,
"scripts": {
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "demo",
"name": "svelte-demo",
"private": true,
"version": "0.0.1",
"type": "module",
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "demo",
"name": "vanilla-umd-demo",
"private": true,
"version": "0.0.0",
"scripts": {},
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "demo",
"name": "vanilla-demo",
"private": true,
"version": "0.0.0",
"scripts": {
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "demo",
"name": "vue-demo",
"private": true,
"version": "0.0.9",
"scripts": {
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Loading

0 comments on commit 191e098

Please sign in to comment.