Skip to content

Commit

Permalink
feat: Support callbacks for box(path=) #76
Browse files Browse the repository at this point in the history
  • Loading branch information
lo5 committed Aug 25, 2022
1 parent 2c3ce90 commit 3f29a2e
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 4 deletions.
3 changes: 3 additions & 0 deletions py/pkg/h2o_nitro/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -676,6 +676,7 @@ def __init__(
self._plugins = plugins
self._locales = locales
self._default_locale = default_locale or 'en-US'
# TODO clone instead? (to account for view-local closures)
self._delegator = delegator or Delegator()

for options in [self._menu, self._nav, self._hotkeys, self._routes]:
Expand Down Expand Up @@ -775,6 +776,7 @@ def _run(self):
return

def _write(self, read: bool, b: Box, edit: Edit):
self._delegator.scan(b)
self._send(_marshal(_clean(dict(t=_MsgType.Output, box=b.dump(), edit=edit.dump() if edit else None))))
if read:
return self._read(_MsgType.Input)
Expand Down Expand Up @@ -910,6 +912,7 @@ async def _read(self, expected: int):
raise InterruptError()

async def _write(self, read: bool, b: Box, edit: Edit):
self._delegator.scan(b)
await self._send(_marshal(_clean(dict(t=_MsgType.Output, box=b.dump(), edit=edit.dump() if edit else None))))
if read:
return await self._read(_MsgType.Input)
Expand Down
2 changes: 1 addition & 1 deletion web/src/heuristics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ const determineMode = (box: Box): BoxMode => {
return 'text'
}

if (box.text && !box.style) {
if (box.text && !box.path && !box.style) {
return 'md'
}

Expand Down
5 changes: 2 additions & 3 deletions web/src/zone.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -116,11 +116,10 @@ export const Zone = ({ context, box }: Container) => {
onClick = path ? (e: React.MouseEvent<HTMLDivElement>) => {
jump(path ?? '')
e.preventDefault()
} : undefined,
pointer = path ? 'cursor-pointer' : undefined
} : undefined
return (
<div
className={css(flex, pointer, style)}
className={css(flex, path ? 'cursor-pointer' : undefined, style)}
data-name={box.name ?? undefined}
onClick={onClick}
style={background}
Expand Down

0 comments on commit 3f29a2e

Please sign in to comment.