forked from tldraw/tldraw
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
625f578
commit 472276b
Showing
8 changed files
with
164 additions
and
167 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
import { BaseBoxShapeTool } from "@bigbluebutton/editor"; | ||
import { BaseBoxShapeTool } from '@bigbluebutton/editor' | ||
|
||
export class PollShapeTool extends BaseBoxShapeTool { | ||
static override id = 'poll' | ||
static override initial = 'idle' | ||
override shapeType = 'poll' | ||
static override id = 'poll' | ||
static override initial = 'idle' | ||
override shapeType = 'poll' | ||
} |
224 changes: 110 additions & 114 deletions
224
packages/tldraw/src/lib/shapes/poll/PollShapeUtil.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 |
---|---|---|
@@ -1,119 +1,115 @@ | ||
import React from 'react'; | ||
import { | ||
HTMLContainer, | ||
Rectangle2d, | ||
ShapeUtil, | ||
TLOnResizeHandler, | ||
getDefaultColorTheme, | ||
resizeBox, | ||
HTMLContainer, | ||
Rectangle2d, | ||
ShapeUtil, | ||
TLOnResizeHandler, | ||
getDefaultColorTheme, | ||
resizeBox, | ||
} from '@bigbluebutton/editor' | ||
import React from 'react' | ||
|
||
import { pollShapeMigrations } from './poll-shape-migrations'; | ||
import { pollShapeProps } from './poll-shape-props'; | ||
import { IPollShape } from './poll-shape-types'; | ||
import ChatPollContent from './components/poll-content'; | ||
import ChatPollContent from './components/poll-content' | ||
import { pollShapeMigrations } from './poll-shape-migrations' | ||
import { pollShapeProps } from './poll-shape-props' | ||
import { IPollShape } from './poll-shape-types' | ||
|
||
export class PollShapeUtil extends ShapeUtil<IPollShape> { | ||
static override type = 'poll' as const; | ||
|
||
static override props = pollShapeProps; | ||
|
||
static override migrations = pollShapeMigrations; | ||
|
||
// eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
override isAspectRatioLocked = (_shape: IPollShape) => false; | ||
|
||
// eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
override canResize = (_shape: IPollShape) => true; | ||
|
||
// eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
override canBind = (_shape: IPollShape) => true; | ||
|
||
getDefaultProps(): IPollShape['props'] { | ||
return { | ||
w: 300, | ||
h: 300, | ||
color: 'black', | ||
fill: 'white', | ||
question: '', | ||
numRespondents: 0, | ||
numResponders: 0, | ||
questionText: '', | ||
questionType: '', | ||
answers: [], | ||
}; | ||
} | ||
|
||
// eslint-disable-next-line class-methods-use-this | ||
getGeometry(shape: IPollShape) { | ||
return new Rectangle2d({ | ||
width: shape.props.w, | ||
height: shape.props.h, | ||
isFilled: true, | ||
}); | ||
} | ||
|
||
component(shape: IPollShape) { | ||
const { bounds } = this.editor.getShapeGeometry(shape); | ||
const theme = getDefaultColorTheme({ | ||
isDarkMode: this.editor.user.getIsDarkMode(), | ||
}); | ||
|
||
const contentRef = React.useRef<HTMLDivElement>(null); | ||
const pollMetadata = JSON.stringify({ | ||
id: shape.id, | ||
question: shape.props.question, | ||
numRespondents: shape.props.numRespondents, | ||
numResponders: shape.props.numResponders, | ||
questionText: shape.props.questionText, | ||
questionType: shape.props.questionType, | ||
answers: shape.props.answers, | ||
}); | ||
|
||
const adjustedHeight = shape.props.questionText.length > 0 ? bounds.height - 75 : bounds.height; | ||
|
||
return ( | ||
<HTMLContainer | ||
id={shape.id} | ||
style={{ | ||
border: '1px solid #8B9AA8', | ||
borderRadius: '4px', | ||
boxShadow: '0px 0px 4px 0px rgba(0, 0, 0, 0.20)', | ||
display: 'flex', | ||
flexDirection: 'column', | ||
alignItems: 'center', | ||
justifyContent: 'center', | ||
pointerEvents: 'all', | ||
backgroundColor: theme[shape.props.color].semi, | ||
color: theme[shape.props.color].solid, | ||
}} | ||
> | ||
<div | ||
ref={contentRef} | ||
style={{ | ||
width: `${bounds.width}px`, | ||
overflow: 'hidden', | ||
position: 'relative', | ||
}} | ||
> | ||
<ChatPollContent | ||
metadata={pollMetadata} | ||
height={adjustedHeight} | ||
/> | ||
</div> | ||
</HTMLContainer> | ||
); | ||
} | ||
|
||
// eslint-disable-next-line class-methods-use-this | ||
indicator(shape: IPollShape) { | ||
return <rect width={shape.props.w} height={shape.props.h} />; | ||
} | ||
|
||
override onResize: TLOnResizeHandler<IPollShape> = (shape, info) => { | ||
return resizeBox(shape, info); | ||
} | ||
} | ||
|
||
export default PollShapeUtil; | ||
|
||
static override type = 'poll' as const | ||
|
||
static override props = pollShapeProps | ||
|
||
static override migrations = pollShapeMigrations | ||
|
||
// eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
override isAspectRatioLocked = (_shape: IPollShape) => false | ||
|
||
// eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
override canResize = (_shape: IPollShape) => true | ||
|
||
// eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
override canBind = (_shape: IPollShape) => true | ||
|
||
getDefaultProps(): IPollShape['props'] { | ||
return { | ||
w: 300, | ||
h: 300, | ||
color: 'black', | ||
fill: 'white', | ||
question: '', | ||
numRespondents: 0, | ||
numResponders: 0, | ||
questionText: '', | ||
questionType: '', | ||
answers: [], | ||
} | ||
} | ||
|
||
// eslint-disable-next-line class-methods-use-this | ||
getGeometry(shape: IPollShape) { | ||
return new Rectangle2d({ | ||
width: shape.props.w, | ||
height: shape.props.h, | ||
isFilled: true, | ||
}) | ||
} | ||
|
||
component(shape: IPollShape) { | ||
const { bounds } = this.editor.getShapeGeometry(shape) | ||
const theme = getDefaultColorTheme({ | ||
isDarkMode: this.editor.user.getIsDarkMode(), | ||
}) | ||
|
||
const contentRef = React.useRef<HTMLDivElement>(null) | ||
const pollMetadata = JSON.stringify({ | ||
id: shape.id, | ||
question: shape.props.question, | ||
numRespondents: shape.props.numRespondents, | ||
numResponders: shape.props.numResponders, | ||
questionText: shape.props.questionText, | ||
questionType: shape.props.questionType, | ||
answers: shape.props.answers, | ||
}) | ||
|
||
const adjustedHeight = shape.props.questionText.length > 0 ? bounds.height - 75 : bounds.height | ||
|
||
return ( | ||
<HTMLContainer | ||
id={shape.id} | ||
style={{ | ||
border: '1px solid #8B9AA8', | ||
borderRadius: '4px', | ||
boxShadow: '0px 0px 4px 0px rgba(0, 0, 0, 0.20)', | ||
display: 'flex', | ||
flexDirection: 'column', | ||
alignItems: 'center', | ||
justifyContent: 'center', | ||
pointerEvents: 'all', | ||
backgroundColor: theme[shape.props.color].semi, | ||
color: theme[shape.props.color].solid, | ||
}} | ||
> | ||
<div | ||
ref={contentRef} | ||
style={{ | ||
width: `${bounds.width}px`, | ||
overflow: 'hidden', | ||
position: 'relative', | ||
}} | ||
> | ||
<ChatPollContent metadata={pollMetadata} height={adjustedHeight} /> | ||
</div> | ||
</HTMLContainer> | ||
) | ||
} | ||
|
||
// eslint-disable-next-line class-methods-use-this | ||
indicator(shape: IPollShape) { | ||
return <rect width={shape.props.w} height={shape.props.h} /> | ||
} | ||
|
||
override onResize: TLOnResizeHandler<IPollShape> = (shape, info) => { | ||
return resizeBox(shape, info) | ||
} | ||
} | ||
|
||
export default PollShapeUtil |
2 changes: 1 addition & 1 deletion
2
packages/tldraw/src/lib/shapes/poll/components/poll-content.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
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,20 +1,20 @@ | ||
import styled from 'styled-components'; | ||
import styled from 'styled-components' | ||
|
||
export const PollText = styled.div` | ||
margin-top: 0.5rem; | ||
margin-bottom: 0.5rem; | ||
font-size: 1.25rem; | ||
font-weight: 500; | ||
margin-left: 2.75rem; | ||
color: var(--color-text, var(--color-gray, #4E5A66)); | ||
word-break: break-word; | ||
`; | ||
margin-top: 0.5rem; | ||
margin-bottom: 0.5rem; | ||
font-size: 1.25rem; | ||
font-weight: 500; | ||
margin-left: 2.75rem; | ||
color: var(--color-text, var(--color-gray, #4e5a66)); | ||
word-break: break-word; | ||
` | ||
|
||
export const PollWrapper = styled.div` | ||
width: 100%; | ||
`; | ||
width: 100%; | ||
` | ||
|
||
export default { | ||
PollText, | ||
PollWrapper, | ||
}; | ||
PollText, | ||
PollWrapper, | ||
} |
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,17 +1,17 @@ | ||
import { DefaultColorStyle, ShapeProps, T } from '@bigbluebutton/editor'; | ||
import { IPollShape } from './poll-shape-types'; | ||
import { DefaultColorStyle, ShapeProps, T } from '@bigbluebutton/editor' | ||
import { IPollShape } from './poll-shape-types' | ||
|
||
export const pollShapeProps: ShapeProps<IPollShape> = { | ||
w: T.number, | ||
h: T.number, | ||
color: DefaultColorStyle, | ||
fill: T.string, | ||
question: T.string, | ||
numRespondents: T.number, | ||
numResponders: T.number, | ||
questionText: T.string, | ||
questionType: T.string, | ||
answers: T.any, | ||
}; | ||
w: T.number, | ||
h: T.number, | ||
color: DefaultColorStyle, | ||
fill: T.string, | ||
question: T.string, | ||
numRespondents: T.number, | ||
numResponders: T.number, | ||
questionText: T.string, | ||
questionType: T.string, | ||
answers: T.any, | ||
} | ||
|
||
export default pollShapeProps; | ||
export default pollShapeProps |
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,21 +1,21 @@ | ||
import { TLBaseShape, TLDefaultColorStyle } from '@bigbluebutton/editor'; | ||
import { TLBaseShape, TLDefaultColorStyle } from '@bigbluebutton/editor' | ||
|
||
export type IPollShape = TLBaseShape< | ||
'poll', | ||
{ | ||
w: number, | ||
h: number, | ||
color: TLDefaultColorStyle, | ||
fill: string, | ||
question: string, | ||
numRespondents: number, | ||
numResponders: number, | ||
questionText: string, | ||
questionType: string, | ||
answers: Array<{ | ||
id: number, | ||
key: string, | ||
numVotes: number, | ||
}>, | ||
} | ||
'poll', | ||
{ | ||
w: number | ||
h: number | ||
color: TLDefaultColorStyle | ||
fill: string | ||
question: string | ||
numRespondents: number | ||
numResponders: number | ||
questionText: string | ||
questionType: string | ||
answers: Array<{ | ||
id: number | ||
key: string | ||
numVotes: number | ||
}> | ||
} | ||
> |
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 |
---|---|---|
|
@@ -1698,6 +1698,7 @@ __metadata: | |
version: 0.0.0-use.local | ||
resolution: "@bigbluebutton/monorepo@workspace:." | ||
dependencies: | ||
"@bigbluebutton/tldraw": "workspace:^" | ||
"@microsoft/api-extractor": ^7.35.4 | ||
"@next/eslint-plugin-next": ^13.3.0 | ||
"@swc/core": ^1.3.55 | ||
|
@@ -1795,7 +1796,7 @@ __metadata: | |
languageName: unknown | ||
linkType: soft | ||
|
||
"@bigbluebutton/[email protected], @bigbluebutton/tldraw@workspace:packages/tldraw": | ||
"@bigbluebutton/[email protected], @bigbluebutton/tldraw@workspace:^, @bigbluebutton/tldraw@workspace:packages/tldraw": | ||
version: 0.0.0-use.local | ||
resolution: "@bigbluebutton/tldraw@workspace:packages/tldraw" | ||
dependencies: | ||
|