-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(region): Add region manager logic and renderers
- Loading branch information
Showing
27 changed files
with
670 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,16 @@ | ||
/* eslint-disable @typescript-eslint/no-explicit-any, @typescript-eslint/no-namespace */ | ||
declare namespace Intl { | ||
const RelativeTimeFormat: {}; | ||
} | ||
|
||
declare namespace NodeJS { | ||
interface Global { | ||
BoxAnnotations: any; | ||
} | ||
} | ||
|
||
declare namespace Intl { | ||
const RelativeTimeFormat: {}; | ||
} | ||
|
||
declare module 'box-annotations-locale-data'; | ||
declare module 'box-elements-messages'; | ||
declare module 'box-ui-elements/es/components/button'; | ||
declare module 'box-ui-elements/es/components/primary-button'; | ||
declare module 'box-ui-elements/es/constants'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
import './global'; | ||
|
||
export * from './i18n'; | ||
export * from './api'; | ||
export * from './i18n'; | ||
export * from './model'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
/* eslint-disable flowtype/no-types-missing-file-annotation, no-use-before-define */ | ||
|
||
// New Data Model Types | ||
export interface Annotation { | ||
createdAt: Date; | ||
createdBy: User; | ||
description?: Reply; | ||
id: string; | ||
modifiedAt: Date; | ||
modifiedBy: User; | ||
permissions: Permissions; | ||
replies?: Array<Reply>; | ||
target: Target; | ||
type: 'annotation'; | ||
} | ||
|
||
export interface User { | ||
id: string; | ||
login: string; | ||
name: string; | ||
profileImage: string; | ||
type: 'user'; | ||
} | ||
|
||
export interface Rect { | ||
fill?: string; | ||
height: number; | ||
stroke?: Stroke; | ||
width: number; | ||
x: number; | ||
y: number; | ||
} | ||
|
||
export interface Reply { | ||
createdAt: Date; | ||
createdBy: User; | ||
id: string; | ||
message: string; | ||
parentId: string; | ||
type: 'reply'; | ||
} | ||
|
||
export interface Stroke { | ||
color: string; | ||
size: number; | ||
} | ||
|
||
export type Target = TargetDrawing | TargetHighlight | TargetPoint | TargetRegion; | ||
|
||
export interface TargetDrawing { | ||
id: string; | ||
page: number; | ||
paths: [ | ||
{ | ||
points: [number, number]; | ||
}, | ||
]; | ||
stroke: Stroke; | ||
type: 'drawing'; | ||
} | ||
|
||
export interface TargetHighlight { | ||
id: string; | ||
page: number; | ||
rects: Array<Rect>; | ||
text: string; | ||
type: 'highlight'; | ||
} | ||
|
||
export interface TargetPoint { | ||
id: string; | ||
page: number; | ||
type: 'point'; | ||
x: number; | ||
y: number; | ||
} | ||
|
||
export interface TargetRegion { | ||
page: number; | ||
shape: Rect; | ||
type: 'region'; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
@font-face { | ||
font-weight: normal; | ||
font-family: 'Lato'; | ||
font-style: normal; | ||
src: local('Lato Regular'), local('Lato-Regular'), url('https://cdn01.boxcdn.net/fonts/1.0.2/lato/Lato-Regular.woff2') format('woff2'), url('https://cdn01.boxcdn.net/fonts/1.0.2/lato/Lato-Regular.woff') format('woff'); | ||
} | ||
|
||
@font-face { | ||
font-weight: bold; | ||
font-family: 'Lato'; | ||
font-style: normal; | ||
src: local('Lato Bold'), local('Lato-Bold'), url('https://cdn01.boxcdn.net/fonts/1.0.2/lato/Lato-Bold.woff2') format('woff2'), url('https://cdn01.boxcdn.net/fonts/1.0.2/lato/Lato-Bold.woff') format('woff'); | ||
} | ||
|
||
.ba { | ||
@import '~box-ui-elements/es/styles/base'; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
export type Options = { | ||
page: string; | ||
pageEl: HTMLElement; | ||
referenceEl: HTMLElement; | ||
}; | ||
|
||
export type Props = { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import * as React from 'react'; | ||
import noop from 'lodash/noop'; | ||
import { KEYS } from 'box-ui-elements/es/constants'; | ||
|
||
type Props = { | ||
annotationId: string; | ||
children: React.ReactNode; | ||
className?: string; | ||
onSelect?: (annotationId: string) => void; | ||
}; | ||
|
||
const AnnotationTarget = (props: Props, ref: React.Ref<HTMLAnchorElement>): JSX.Element => { | ||
const { annotationId, children, className, onSelect = noop, ...rest } = props; | ||
const cancelEvent = (event: React.SyntheticEvent): void => { | ||
event.preventDefault(); | ||
event.stopPropagation(); | ||
event.nativeEvent.stopImmediatePropagation(); // Prevents document event handlers from executing | ||
}; | ||
const handleClick = (event: React.MouseEvent): void => { | ||
cancelEvent(event); | ||
onSelect(annotationId); | ||
}; | ||
const handleFocus = (event: React.SyntheticEvent): void => { | ||
cancelEvent(event); | ||
onSelect(annotationId); | ||
}; | ||
const handleKeyPress = (event: React.KeyboardEvent): void => { | ||
if (event.key !== KEYS.enter) { | ||
return; | ||
} | ||
|
||
cancelEvent(event); | ||
onSelect(annotationId); | ||
}; | ||
|
||
return ( | ||
<a | ||
ref={ref} | ||
className={className} | ||
onClick={handleClick} | ||
onFocus={handleFocus} | ||
onKeyPress={handleKeyPress} | ||
role="button" | ||
tabIndex={0} | ||
{...rest} | ||
> | ||
{children} | ||
</a> | ||
); | ||
}; | ||
|
||
export default React.forwardRef(AnnotationTarget); |
78 changes: 78 additions & 0 deletions
78
src/components/AnnotationTarget/__tests__/AnnotationTarget-test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
import React from 'react'; | ||
import { KEYS } from 'box-ui-elements/es/constants'; | ||
import { shallow, ShallowWrapper } from 'enzyme'; | ||
import AnnotationTarget from '../AnnotationTarget'; | ||
|
||
describe('AnnotationTarget', () => { | ||
const defaults = { | ||
annotationId: '1', | ||
onSelect: jest.fn(), | ||
}; | ||
const getWrapper = (props = {}): ShallowWrapper => { | ||
return shallow( | ||
<AnnotationTarget {...defaults} {...props}> | ||
Test | ||
</AnnotationTarget>, | ||
); | ||
}; | ||
|
||
describe('keyboard event handlers', () => { | ||
test.each` | ||
key | callCount | ||
${KEYS.enter} | ${1} | ||
${KEYS.escape} | ${0} | ||
${KEYS.space} | ${0} | ||
`('should handle the $key keypress event', ({ callCount, key }) => { | ||
const mockEvent = { | ||
key, | ||
nativeEvent: { | ||
stopImmediatePropagation: jest.fn(), | ||
}, | ||
preventDefault: jest.fn(), | ||
stopPropagation: jest.fn(), | ||
}; | ||
const onSelect = jest.fn(); | ||
const wrapper = getWrapper({ onSelect }); | ||
|
||
wrapper.simulate('keyPress', mockEvent); | ||
|
||
expect(mockEvent.nativeEvent.stopImmediatePropagation).toHaveBeenCalledTimes(callCount); | ||
expect(mockEvent.preventDefault).toHaveBeenCalledTimes(callCount); | ||
expect(mockEvent.stopPropagation).toHaveBeenCalledTimes(callCount); | ||
expect(onSelect).toHaveBeenCalledTimes(callCount); | ||
}); | ||
}); | ||
|
||
describe('mouse event handlers', () => { | ||
test.each(['click', 'focus'])('should cancel the %s event and trigger onSelect', event => { | ||
const mockEvent = { | ||
nativeEvent: { | ||
stopImmediatePropagation: jest.fn(), | ||
}, | ||
preventDefault: jest.fn(), | ||
stopPropagation: jest.fn(), | ||
}; | ||
const onSelect = jest.fn(); | ||
const wrapper = getWrapper({ onSelect }); | ||
|
||
wrapper.simulate(event, mockEvent); | ||
|
||
expect(mockEvent.nativeEvent.stopImmediatePropagation).toHaveBeenCalled(); | ||
expect(mockEvent.preventDefault).toHaveBeenCalled(); | ||
expect(mockEvent.stopPropagation).toHaveBeenCalled(); | ||
expect(onSelect).toHaveBeenCalledWith('1'); | ||
}); | ||
}); | ||
|
||
describe('render()', () => { | ||
test('should pass the requiredprops to the underlying anchor', () => { | ||
const wrapper = getWrapper({ className: 'ba-Test' }); | ||
|
||
expect(wrapper.props()).toMatchObject({ | ||
className: 'ba-Test', | ||
role: 'button', | ||
tabIndex: 0, | ||
}); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { default } from './AnnotationTarget'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
.bp-doc .ba-Layer { | ||
& > div, | ||
& > svg { | ||
margin: 15px 0; // Padding on each page provided by Preview SDK | ||
} | ||
} |
Oops, something went wrong.