Skip to content

Commit

Permalink
feat: write ancestorsHaveListeners onto interaction panel for the eve…
Browse files Browse the repository at this point in the history
…nt system when skipping over uikit elements
  • Loading branch information
bbohlender committed Nov 5, 2024
1 parent cad0f11 commit 193b9ce
Show file tree
Hide file tree
Showing 12 changed files with 156 additions and 144 deletions.
45 changes: 21 additions & 24 deletions packages/uikit/src/components/container.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ import { Initializers } from '../utils.js'
import { darkPropertyTransformers } from '../dark.js'
import { getDefaultPanelMaterialConfig } from '../panel/index.js'
import {
computeAnyAncestorsHaveListeners,
computedInheritableProperty,
computeOutgoingDefaultProperties,
setupInteractableDecendant,
computeDefaultProperties,
setupPointerEvents,
UpdateMatrixWorldProperties,
} from '../internals.js'
Expand Down Expand Up @@ -66,7 +66,7 @@ export function createContainer(
parentCtx: ParentContext,
style: Signal<ContainerProperties | undefined>,
properties: Signal<ContainerProperties | undefined>,
incommingDefaultProperties: Signal<AllOptionalProperties | undefined>,
defaultProperties: Signal<AllOptionalProperties | undefined>,
object: Object3DRef,
childrenContainer: Object3DRef,
) {
Expand All @@ -79,7 +79,7 @@ export function createContainer(
setupCursorCleanup(hoveredSignal, initializers)

//properties
const mergedProperties = computedMergedProperties(style, properties, incommingDefaultProperties, {
const mergedProperties = computedMergedProperties(style, properties, defaultProperties, {
...darkPropertyTransformers,
...createResponsivePropertyTransformers(parentCtx.root.size),
...createHoverPropertyTransformers(hoveredSignal),
Expand Down Expand Up @@ -136,16 +136,6 @@ export function createContainer(
scrollbarWidth,
initializers,
)
const interactionPanel = createInteractionPanel(
orderInfo,
parentCtx.root,
parentCtx.clippingRect,
flexState.size,
globalMatrix,
initializers,
)
setupPointerEvents(mergedProperties, interactionPanel, initializers)
setupInteractableDecendant(mergedProperties, parentCtx.root, interactionPanel, initializers)
const scrollHandlers = computedScrollHandlers(
scrollPosition,
parentCtx.anyAncestorScrollable,
Expand All @@ -157,6 +147,19 @@ export function createContainer(
initializers,
)

const handlers = computedHandlers(style, properties, defaultProperties, hoveredSignal, activeSignal, scrollHandlers)
const ancestorsHaveListeners = computeAnyAncestorsHaveListeners(parentCtx, handlers)

const interactionPanel = createInteractionPanel(
orderInfo,
parentCtx.root,
parentCtx.clippingRect,
flexState.size,
globalMatrix,
initializers,
)
setupPointerEvents(mergedProperties, ancestorsHaveListeners, parentCtx.root, interactionPanel, initializers, false)

const updateMatrixWorld = computedInheritableProperty(mergedProperties, 'updateMatrixWorld', false)
setupMatrixWorldUpdate(updateMatrixWorld, false, object, parentCtx.root, globalMatrix, initializers, false)
setupMatrixWorldUpdate(updateMatrixWorld, false, interactionPanel, parentCtx.root, globalMatrix, initializers, true)
Expand All @@ -165,7 +168,8 @@ export function createContainer(
setupClippedListeners(style, properties, isClipped, initializers)

return Object.assign(flexState, {
defaultProperties: computeOutgoingDefaultProperties(mergedProperties),
ancestorsHaveListeners,
defaultProperties: computeDefaultProperties(mergedProperties),
globalMatrix,
isClipped,
isVisible,
Expand All @@ -178,14 +182,7 @@ export function createContainer(
root: parentCtx.root,
scrollPosition,
interactionPanel,
handlers: computedHandlers(
style,
properties,
incommingDefaultProperties,
hoveredSignal,
activeSignal,
scrollHandlers,
),
handlers,
initializers,
})
}) satisfies ParentContext
}
10 changes: 6 additions & 4 deletions packages/uikit/src/components/content.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ import { Signal, computed, effect, signal, untracked } from '@preact/signals-cor
import {
VisibilityProperties,
WithConditionals,
computeAnyAncestorsHaveListeners,
computedGlobalMatrix,
computedHandlers,
computedIsVisible,
computedMergedProperties,
createNode,
keepAspectRatioPropertyTransformer,
setupInteractableDecendant,
setupMatrixWorldUpdate,
setupPointerEvents,
} from './utils.js'
Expand Down Expand Up @@ -140,8 +140,10 @@ export function createContent(
)

setupMatrixWorldUpdate(true, true, object, parentCtx.root, globalMatrix, initializers, false)
setupPointerEvents(mergedProperties, object, initializers)
setupInteractableDecendant(mergedProperties, parentCtx.root, object, initializers)

const handlers = computedHandlers(style, properties, defaultProperties, hoveredSignal, activeSignal)
const ancestorsHaveListeners = computeAnyAncestorsHaveListeners(parentCtx, handlers)
setupPointerEvents(mergedProperties, ancestorsHaveListeners, parentCtx.root, object, initializers, true)

setupLayoutListeners(style, properties, flexState.size, initializers)
setupClippedListeners(style, properties, isClipped, initializers)
Expand All @@ -163,7 +165,7 @@ export function createContent(
initializers,
),
interactionPanel,
handlers: computedHandlers(style, properties, defaultProperties, hoveredSignal, activeSignal),
handlers,
initializers,
})
}
Expand Down
10 changes: 5 additions & 5 deletions packages/uikit/src/components/custom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,14 @@ import { Signal, effect, signal } from '@preact/signals-core'
import {
VisibilityProperties,
WithConditionals,
computeAnyAncestorsHaveListeners,
computedGlobalMatrix,
computedHandlers,
computedIsVisible,
computedMergedProperties,
createNode,
setupMatrixWorldUpdate,
setupInteractableDecendant,
setupPointerEvents,
computeOutgoingDefaultProperties,
} from './utils.js'
import { Initializers } from '../utils.js'
import { Listeners, setupLayoutListeners, setupClippedListeners } from '../listeners.js'
Expand Down Expand Up @@ -147,8 +146,9 @@ export function createCustomContainer(

setupMatrixWorldUpdate(true, true, object, parentCtx.root, globalMatrix, initializers, false)

setupPointerEvents(mergedProperties, object, initializers)
setupInteractableDecendant(mergedProperties, parentCtx.root, object, initializers)
const handlers = computedHandlers(style, properties, defaultProperties, hoveredSignal, activeSignal)
const ancestorsHaveListeners = computeAnyAncestorsHaveListeners(parentCtx, handlers)
setupPointerEvents(mergedProperties, ancestorsHaveListeners, parentCtx.root, object, initializers, true)

setupLayoutListeners(style, properties, flexState.size, initializers)
setupClippedListeners(style, properties, isClipped, initializers)
Expand All @@ -159,7 +159,7 @@ export function createCustomContainer(
isVisible,
mergedProperties,
root: parentCtx.root,
handlers: computedHandlers(style, properties, defaultProperties, hoveredSignal, activeSignal),
handlers,
initializers,
})
}
18 changes: 9 additions & 9 deletions packages/uikit/src/components/icon.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { Signal, effect, signal } from '@preact/signals-core'
import { BufferGeometry, Color, Group, Material, Mesh, MeshBasicMaterial, Plane, ShapeGeometry } from 'three'
import { BufferGeometry, Group, Material, Mesh, MeshBasicMaterial, Plane, ShapeGeometry } from 'three'
import { Listeners } from '../index.js'
import { Object3DRef, ParentContext } from '../context.js'
import { FlexNode, FlexNodeState, YogaProperties, createFlexNodeState } from '../flex/index.js'
import { FlexNodeState, YogaProperties, createFlexNodeState } from '../flex/index.js'
import { ElementType, OrderInfo, ZIndexProperties, computedOrderInfo, setupRenderOrder } from '../order.js'
import { PanelProperties, createInstancedPanel } from '../panel/instanced-panel.js'
import { WithAllAliases } from '../properties/alias.js'
Expand All @@ -13,18 +13,17 @@ import {
VisibilityProperties,
WithConditionals,
applyAppearancePropertiesToGroup,
computeOutgoingDefaultProperties,
computeAnyAncestorsHaveListeners,
computedGlobalMatrix,
computedHandlers,
computedIsVisible,
computedMergedProperties,
createNode,
keepAspectRatioPropertyTransformer,
setupInteractableDecendant,
setupMatrixWorldUpdate,
setupPointerEvents,
} from './utils.js'
import { Initializers, Subscriptions, fitNormalizedContentInside } from '../utils.js'
import { Initializers, fitNormalizedContentInside } from '../utils.js'
import { makeClippedCast } from '../panel/interaction-panel-mesh.js'
import { computedIsClipped, createGlobalClippingPlanes } from '../clipping.js'
import { setupLayoutListeners, setupClippedListeners } from '../listeners.js'
Expand All @@ -36,7 +35,7 @@ import { SVGLoader } from 'three/examples/jsm/loaders/SVGLoader.js'
import { AppearanceProperties } from './svg.js'
import { PanelGroupProperties, computedPanelGroupDependencies, getDefaultPanelMaterialConfig } from '../panel/index.js'
import { darkPropertyTransformers } from '../dark.js'
import { computedInheritableProperty, MergedProperties } from '../properties/index.js'
import { MergedProperties } from '../properties/index.js'

export type InheritableIconProperties = WithClasses<
WithConditionals<
Expand Down Expand Up @@ -138,8 +137,9 @@ export function createIcon(

setupMatrixWorldUpdate(true, true, object, parentCtx.root, globalMatrix, initializers, false)

setupPointerEvents(mergedProperties, object, initializers)
setupInteractableDecendant(mergedProperties, parentCtx.root, object, initializers)
const handlers = computedHandlers(style, properties, defaultProperties, hoveredSignal, activeSignal)
const ancestorsHaveListeners = computeAnyAncestorsHaveListeners(parentCtx, handlers)
setupPointerEvents(mergedProperties, ancestorsHaveListeners, parentCtx.root, object, initializers, false)

setupLayoutListeners(style, properties, flexState.size, initializers)
setupClippedListeners(style, properties, isClipped, initializers)
Expand All @@ -151,7 +151,7 @@ export function createIcon(
mergedProperties,
initializers,
iconGroup,
handlers: computedHandlers(style, properties, defaultProperties, hoveredSignal, activeSignal),
handlers,
interactionPanel: createInteractionPanel(
orderInfo,
parentCtx.root,
Expand Down
37 changes: 20 additions & 17 deletions packages/uikit/src/components/image.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,15 @@ import {
UpdateMatrixWorldProperties,
VisibilityProperties,
WithConditionals,
computeOutgoingDefaultProperties,
computeAnyAncestorsHaveListeners,
computeDefaultProperties,
computedGlobalMatrix,
computedHandlers,
computedIsVisible,
computedMergedProperties,
createNode,
keepAspectRatioPropertyTransformer,
loadResourceWithParams,
setupInteractableDecendant,
setupMatrixWorldUpdate,
setupPointerEvents,
} from './utils.js'
Expand Down Expand Up @@ -176,6 +176,17 @@ export function createImage(
scrollbarWidth,
initializers,
)
const scrollHandlers = computedScrollHandlers(
scrollPosition,
parentCtx.anyAncestorScrollable,
flexState,
object,
scrollbarWidth,
properties,
parentCtx.root,
initializers,
)

const imageMesh = createImageMesh(
mergedProperties,
texture,
Expand All @@ -188,18 +199,9 @@ export function createImage(
initializers,
)

setupPointerEvents(mergedProperties, imageMesh, initializers)
setupInteractableDecendant(mergedProperties, parentCtx.root, imageMesh, initializers)
const scrollHandlers = computedScrollHandlers(
scrollPosition,
parentCtx.anyAncestorScrollable,
flexState,
object,
scrollbarWidth,
properties,
parentCtx.root,
initializers,
)
const handlers = computedHandlers(style, properties, defaultProperties, hoveredSignal, activeSignal, scrollHandlers)
const ancestorsHaveListeners = computeAnyAncestorsHaveListeners(parentCtx, handlers)
setupPointerEvents(mergedProperties, ancestorsHaveListeners, parentCtx.root, imageMesh, initializers, false)

const updateMatrixWorld = computedInheritableProperty(mergedProperties, 'updateMatrixWorld', false)
setupMatrixWorldUpdate(updateMatrixWorld, false, object, parentCtx.root, globalMatrix, initializers, false)
Expand All @@ -209,22 +211,23 @@ export function createImage(
setupClippedListeners(style, properties, isClipped, initializers)

return Object.assign(flexState, {
defaultProperties: computeOutgoingDefaultProperties(mergedProperties),
ancestorsHaveListeners,
defaultProperties: computeDefaultProperties(mergedProperties),
globalMatrix,
scrollPosition,
isClipped,
isVisible,
mergedProperties,
anyAncestorScrollable: computedAnyAncestorScrollable(flexState.scrollable, parentCtx.anyAncestorScrollable),
initializers,
handlers: computedHandlers(style, properties, defaultProperties, hoveredSignal, activeSignal, scrollHandlers),
handlers,
interactionPanel: imageMesh,
clippingRect: computedClippingRect(globalMatrix, flexState, parentCtx.root.pixelSize, parentCtx.clippingRect),
childrenMatrix,
node,
orderInfo,
root: parentCtx.root,
})
}) satisfies ParentContext
}

let imageMaterialConfig: PanelMaterialConfig | undefined
Expand Down
28 changes: 14 additions & 14 deletions packages/uikit/src/components/input.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,12 @@ import {
UpdateMatrixWorldProperties,
VisibilityProperties,
WithConditionals,
computeOutgoingDefaultProperties,
computeAnyAncestorsHaveListeners,
computedGlobalMatrix,
computedHandlers,
computedIsVisible,
computedMergedProperties,
createNode,
setupInteractableDecendant,
setupMatrixWorldUpdate,
setupPointerEvents,
} from './utils.js'
Expand Down Expand Up @@ -250,9 +249,6 @@ export function createInput(
initializers,
)

setupPointerEvents(mergedProperties, interactionPanel, initializers)
setupInteractableDecendant(mergedProperties, parentCtx.root, interactionPanel, initializers)

const updateMatrixWorld = computedInheritableProperty(mergedProperties, 'updateMatrixWorld', false)
setupMatrixWorldUpdate(updateMatrixWorld, false, object, parentCtx.root, globalMatrix, initializers, false)
setupMatrixWorldUpdate(updateMatrixWorld, false, interactionPanel, parentCtx.root, globalMatrix, initializers, true)
Expand Down Expand Up @@ -305,6 +301,18 @@ export function createInput(
})
const selectionHandlers = computedSelectionHandlers(type, valueSignal, flexState, instancedTextRef, focus, disabled)

const handlers = computedHandlers(
style,
properties,
defaultProperties,
hoveredSignal,
activeSignal,
selectionHandlers,
'text',
)
const ancestorsHaveListeners = computeAnyAncestorsHaveListeners(parentCtx, handlers)
setupPointerEvents(mergedProperties, ancestorsHaveListeners, parentCtx.root, interactionPanel, initializers, false)

return Object.assign(flexState, {
globalMatrix,
isClipped,
Expand All @@ -317,15 +325,7 @@ export function createInput(
element,
node: nodeSignal,
interactionPanel,
handlers: computedHandlers(
style,
properties,
defaultProperties,
hoveredSignal,
activeSignal,
selectionHandlers,
'text',
),
handlers,
initializers,
})
}
Expand Down
Loading

0 comments on commit 193b9ce

Please sign in to comment.