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 touch support to useDrag - wip #499

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "theatre-monorepo",
"license": "Apache-2.0",
"version": "0.7.0",
"version": "0.7.1",
"workspaces": [
"packages/*",
"examples/*",
Expand Down
2 changes: 1 addition & 1 deletion packages/browser-bundles/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@theatre/browser-bundles",
"version": "0.7.0",
"version": "0.7.1",
"license": "SEE LICENSE IN LICENSE",
"author": {
"name": "Aria Minaei",
Expand Down
2 changes: 1 addition & 1 deletion packages/dataverse/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@theatre/dataverse",
"version": "0.7.0",
"version": "0.7.1",
"license": "Apache-2.0",
"author": {
"name": "Aria Minaei",
Expand Down
2 changes: 1 addition & 1 deletion packages/r3f/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@theatre/r3f",
"version": "0.7.0",
"version": "0.7.1",
"license": "Apache-2.0",
"authors": [
{
Expand Down
2 changes: 1 addition & 1 deletion packages/react/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@theatre/react",
"version": "0.7.0",
"version": "0.7.1",
"license": "Apache-2.0",
"author": {
"name": "Aria Minaei",
Expand Down
2 changes: 1 addition & 1 deletion packages/theatric/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "theatric",
"version": "0.7.0",
"version": "0.7.1",
"license": "Apache-2.0",
"author": {
"name": "Andrew Prifer",
Expand Down
2 changes: 1 addition & 1 deletion theatre/core/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@theatre/core",
"version": "0.7.0",
"version": "0.7.1",
"license": "Apache-2.0",
"description": "Motion design editor for the web",
"repository": {
Expand Down
6 changes: 6 additions & 0 deletions theatre/core/src/sequences/Sequence.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ const possibleDirections = [
]

export default class Sequence implements PointerToPrismProvider {
get type(): 'Theatre_Sequence' {
return 'Theatre_Sequence'
}
public readonly address: SequenceAddress
publicApi: TheatreSequence

Expand Down Expand Up @@ -98,6 +101,7 @@ export default class Sequence implements PointerToPrismProvider {
length: val(this.pointer.length),
playing: val(this.pointer.playing),
position: val(this.pointer.position),
subUnitsPerUnit: val(this.pointer.subUnitsPerUnit),
})) as $IntentionalAny as Prism<V>
}
if (path.length > 1) {
Expand All @@ -106,6 +110,8 @@ export default class Sequence implements PointerToPrismProvider {
const [prop] = path
if (prop === 'length') {
return this._lengthD as $IntentionalAny as Prism<V>
} else if (prop === 'subUnitsPerUnit') {
return this._subUnitsPerUnitD as $IntentionalAny as Prism<V>
} else if (prop === 'position') {
return this._positionD as $IntentionalAny as Prism<V>
} else if (prop === 'playing') {
Expand Down
1 change: 1 addition & 0 deletions theatre/core/src/sequences/TheatreSequence.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ export interface ISequence {
playing: boolean
length: number
position: number
subUnitsPerUnit: number
}>

/**
Expand Down
18 changes: 18 additions & 0 deletions theatre/core/src/sheets/TheatreSheet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,10 @@ export interface ISheet {
},
): ISheetObject<Props>

__experimental_getExistingObject<Props extends UnknownShorthandCompoundProps>(
key: string,
): ISheetObject<Props> | undefined

/**
* Detaches a previously created child object from the sheet.
*
Expand Down Expand Up @@ -204,6 +208,20 @@ export default class TheatreSheet implements ISheet {
}
}

__experimental_getExistingObject<Props extends UnknownShorthandCompoundProps>(
key: string,
): ISheetObject<Props> | undefined {
const internal = privateAPI(this)
const sanitizedPath = validateAndSanitiseSlashedPathOrThrow(
key,
`sheet.object`,
)

const existingObject = internal.getObject(sanitizedPath as ObjectAddressKey)

return existingObject?.publicApi as $IntentionalAny
}

get sequence(): TheatreSequence {
return privateAPI(this).getSequence().publicApi
}
Expand Down
2 changes: 1 addition & 1 deletion theatre/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "theatre",
"private": true,
"version": "0.7.0",
"version": "0.7.1",
"workspaces": [
"./shared",
"./core",
Expand Down
3 changes: 3 additions & 0 deletions theatre/shared/src/instanceTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import type SheetObjectTemplate from '@theatre/core/sheetObjects/SheetObjectTemp
import type Sheet from '@theatre/core/sheets/Sheet'
import type SheetTemplate from '@theatre/core/sheets/SheetTemplate'
import type {$IntentionalAny} from './utils/types'
import type Sequence from '@theatre/core/sequences/Sequence'

/**
* Since \@theatre/core and \@theatre/studio are separate bundles,
Expand All @@ -22,6 +23,8 @@ export const isSheetTemplate = typeAsserter<SheetTemplate>(

export const isSheetObject = typeAsserter<SheetObject>('Theatre_SheetObject')

export const isSequence = typeAsserter<Sequence>('Theatre_Sequence')

export const isSheetObjectTemplate = typeAsserter<SheetObjectTemplate>(
'Theatre_SheetObjectTemplate',
)
Expand Down
2 changes: 1 addition & 1 deletion theatre/studio/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@theatre/studio",
"version": "0.7.0",
"version": "0.7.1",
"license": "AGPL-3.0-only",
"description": "Motion design editor for the web",
"repository": {
Expand Down
32 changes: 30 additions & 2 deletions theatre/studio/src/StudioStore/createTransactionPrivateApi.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import type {Pointer} from '@theatre/dataverse'
import {isSheetObject} from '@theatre/shared/instanceTypes'
import {isSequence, isSheetObject} from '@theatre/shared/instanceTypes'
import type {$FixMe, $IntentionalAny} from '@theatre/shared/utils/types'
import get from 'lodash-es/get'
import isInteger from 'lodash-es/isInteger'
import type {ITransactionPrivateApi} from './StudioStore'
import forEachPropDeep from '@theatre/shared/utils/forEachDeep'
import getDeep from '@theatre/shared/utils/getDeep'
Expand Down Expand Up @@ -186,9 +187,36 @@ export default function createTransactionPrivateApi(
} else {
setStaticOrKeyframeProp(_value, propConfig, path)
}
} else if (isSequence(root)) {
const [prop] = path
if (prop === 'subUnitsPerUnit') {
if (typeof _value !== 'number' || !isInteger(_value) || _value < 1) {
throw new Error(
`Value ${_value} is not an integer, which is required for setting sequence prop ${prop}`,
)
}
stateEditors.coreByProject.historic.sheetsById.sequence.setSubUnitsPerUnit(
{
...root.address,
subUnitsPerUnit: _value,
},
)
} else if (prop === 'length') {
if (typeof _value !== 'number' || _value <= 0.001) {
throw new Error(
`Value ${_value} is not a positive number, which is required for setting sequence prop ${prop}`,
)
}
stateEditors.coreByProject.historic.sheetsById.sequence.setLength({
...root.address,
length: _value,
})
} else {
throw new Error(`Setting sequence prop ${prop} is not supported`)
}
} else {
throw new Error(
'Only setting props of SheetObject-s is supported in a transaction so far',
'Only setting props of SheetObject-s and sequences is supported in a transaction so far',
)
}
},
Expand Down
6 changes: 6 additions & 0 deletions theatre/studio/src/store/stateEditors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -671,6 +671,12 @@ namespace stateEditors {
)
}

export function setSubUnitsPerUnit(
p: WithoutSheetInstance<SheetAddress> & {subUnitsPerUnit: number},
) {
_ensure(p).subUnitsPerUnit = clamp(p.subUnitsPerUnit, 1, 2 ** 12)
}

function _ensureTracksOfObject(
p: WithoutSheetInstance<SheetObjectAddress>,
) {
Expand Down
Loading