PHP 7.4.33
Preview: contracts.ts Size: 1.20 KB
/var/www/uibuilder.cmshelp.dk/httpdocs/node_modules/dnd-core/src/contracts.ts
import { invariant } from '@react-dnd/invariant'

import type { DragSource, DropTarget, Identifier } from './interfaces.js'

export function validateSourceContract(source: DragSource): void {
	invariant(
		typeof source.canDrag === 'function',
		'Expected canDrag to be a function.',
	)
	invariant(
		typeof source.beginDrag === 'function',
		'Expected beginDrag to be a function.',
	)
	invariant(
		typeof source.endDrag === 'function',
		'Expected endDrag to be a function.',
	)
}

export function validateTargetContract(target: DropTarget): void {
	invariant(
		typeof target.canDrop === 'function',
		'Expected canDrop to be a function.',
	)
	invariant(
		typeof target.hover === 'function',
		'Expected hover to be a function.',
	)
	invariant(
		typeof target.drop === 'function',
		'Expected beginDrag to be a function.',
	)
}

export function validateType(
	type: Identifier | Identifier[],
	allowArray?: boolean,
): void {
	if (allowArray && Array.isArray(type)) {
		type.forEach((t) => validateType(t, false))
		return
	}

	invariant(
		typeof type === 'string' || typeof type === 'symbol',
		allowArray
			? 'Type can only be a string, a symbol, or an array of either.'
			: 'Type can only be a string or a symbol.',
	)
}

Directory Contents

Dirs: 4 × Files: 4
Name Size Perms Modified Actions
actions DIR
- drwxr-xr-x 2025-03-28 11:04:37
Edit Download
classes DIR
- drwxr-xr-x 2025-03-28 11:04:37
Edit Download
reducers DIR
- drwxr-xr-x 2025-03-28 11:04:37
Edit Download
utils DIR
- drwxr-xr-x 2025-03-28 11:04:37
Edit Download
1.20 KB lrw-r--r-- 2025-03-28 11:04:37
Edit Download
1.33 KB lrw-r--r-- 2025-03-28 11:04:37
Edit Download
75 B lrw-r--r-- 2025-03-28 11:04:37
Edit Download
6.39 KB lrw-r--r-- 2025-03-28 11:04:37
Edit Download
If ZipArchive is unavailable, a .tar will be created (no compression).