Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Mirador annotations
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
IIIF
Mirador
Mirador annotations
Commits
40dc5d44
Commit
40dc5d44
authored
Jan 10, 2024
by
Samuel Jugnet
Browse files
Options
Downloads
Patches
Plain Diff
non working text keydown handling
parent
fc7e81b2
Branches
Branches containing commit
No related tags found
1 merge request
!10
Draft: MigratingAnnotationCreation to MUI5.
Pipeline
#1703
failed
Jan 10, 2024
Stage: test
Changes
1
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/AnnotationDrawing.js
+139
-15
139 additions, 15 deletions
src/AnnotationDrawing.js
with
139 additions
and
15 deletions
src/AnnotationDrawing.js
+
139
−
15
View file @
40dc5d44
...
@@ -23,7 +23,7 @@ class TextNode extends React.Component {
...
@@ -23,7 +23,7 @@ class TextNode extends React.Component {
}
}
handleClick
=
()
=>
{
handleClick
=
()
=>
{
this
.
props
.
onShapeClick
(
this
.
props
.
id
);
this
.
props
.
onShapeClick
(
this
.
props
.
_
id
);
};
};
...
@@ -32,14 +32,70 @@ class TextNode extends React.Component {
...
@@ -32,14 +32,70 @@ class TextNode extends React.Component {
if
(
this
.
trRef
.
current
)
{
if
(
this
.
trRef
.
current
)
{
this
.
trRef
.
current
.
nodes
([
this
.
shapeRef
.
current
]);
this
.
trRef
.
current
.
nodes
([
this
.
shapeRef
.
current
]);
this
.
trRef
.
current
.
getLayer
().
batchDraw
();
this
.
trRef
.
current
.
getLayer
().
batchDraw
();
// add event listener for key down
// this.shapeRef.current.addEventListener('keydown', this.handleKeyDown);
}
}
handleKeyDown
=
(
e
)
=>
{
// if (e.keyCode === 13) {
// this.shapeRef.current.blur();
// }
//type text content
console
.
log
(
'
Key down:
'
,
e
.
evt
.
key
);
//update text content
if
(
e
.
evt
.
key
===
'
Backspace
'
)
{
const
{
shapes
}
=
this
.
state
;
const
{
selectedShapeId
}
=
this
.
state
;
// update text of selected shape
const
newShapes
=
shapes
.
map
((
shape
)
=>
{
if
(
shape
.
id
===
selectedShapeId
)
{
shape
.
text
=
shape
.
text
.
slice
(
0
,
-
1
);
}
return
shape
;
}
);
this
.
setState
({
shapes
:
newShapes
});
}
else
{
const
{
shapes
}
=
this
.
state
;
const
{
selectedShapeId
}
=
this
.
state
;
// update text of selected shape
const
newShapes
=
shapes
.
map
((
shape
)
=>
{
if
(
shape
.
id
===
selectedShapeId
)
{
shape
.
text
=
shape
.
text
+
e
.
evt
.
key
;
}
}
return
shape
;
}
);
this
.
setState
({
shapes
:
newShapes
});
}
}
}
render
()
{
render
()
{
const
{
activeTool
}
=
this
.
props
;
const
{
activeTool
}
=
this
.
props
;
console
.
log
(
"
selectedId
"
,
this
.
props
.
selectedShapeId
);
console
.
log
(
"
selectedId
"
,
this
.
props
.
_id
,
window
.
selectedShapeId
);
const
isSelected
=
this
.
props
.
id
===
this
.
props
.
selectedShapeId
;
const
isSelected
=
this
.
props
.
_id
===
window
.
selectedShapeId
;
console
.
log
(
'
is selected
'
,
this
.
props
.
_id
,
isSelected
);
return
(
return
(
...
@@ -51,11 +107,14 @@ class TextNode extends React.Component {
...
@@ -51,11 +107,14 @@ class TextNode extends React.Component {
fontSize
=
{
this
.
props
.
fontSize
}
fontSize
=
{
this
.
props
.
fontSize
}
fill
=
{
this
.
props
.
fill
}
fill
=
{
this
.
props
.
fill
}
text
=
{
this
.
props
.
text
}
text
=
{
this
.
props
.
text
}
id
=
{
this
.
props
.
_id
}
//dragable if tool is cursor or edit
//dragable if tool is cursor or edit
draggable
=
{
activeTool
===
'
cursor
'
||
activeTool
===
'
edit
'
}
draggable
=
{
activeTool
===
'
cursor
'
||
activeTool
===
'
edit
'
}
onClick
=
{
this
.
handleClick
}
onClick
=
{
this
.
handleClick
}
onKeyDown
=
{
this
.
handleKeyDown
}
// onClick={activeTool === 'cursor' ? null : null}
// onClick={activeTool === 'cursor' ? null : null}
// onDblClick={acveTool === 'edit' ? this.handleClick : null}ti
// onDblClick={acveTool === 'edit' ? this.handleClick : null}ti
...
@@ -87,6 +146,9 @@ class Rectangle extends React.Component {
...
@@ -87,6 +146,9 @@ class Rectangle extends React.Component {
this
.
shapeRef
=
React
.
createRef
();
this
.
shapeRef
=
React
.
createRef
();
this
.
trRef
=
React
.
createRef
();
this
.
trRef
=
React
.
createRef
();
}
}
...
@@ -99,16 +161,17 @@ class Rectangle extends React.Component {
...
@@ -99,16 +161,17 @@ class Rectangle extends React.Component {
}
}
handleClick
=
()
=>
{
handleClick
=
()
=>
{
this
.
props
.
onShapeClick
(
this
.
props
.
id
);
this
.
props
.
onShapeClick
(
this
.
props
.
_
id
);
};
};
render
()
{
render
()
{
const
{
activeTool
}
=
this
.
props
;
const
{
activeTool
}
=
this
.
props
;
console
.
log
(
'
active tool ===>
'
,
activeTool
);
console
.
log
(
"
selectedId
"
,
this
.
props
.
_id
,
window
.
selectedShapeId
);
console
.
log
(
"
selectedId
"
,
this
.
props
.
selectedShapeId
);
const
isSelected
=
this
.
props
.
id
===
this
.
props
.
selectedShapeId
;
const
isSelected
=
this
.
props
.
_id
===
window
.
selectedShapeId
;
console
.
log
(
'
is selected
'
,
this
.
props
.
_id
,
isSelected
);
return
(
return
(
<
React
.
Fragment
>
<
React
.
Fragment
>
...
@@ -122,6 +185,7 @@ class Rectangle extends React.Component {
...
@@ -122,6 +185,7 @@ class Rectangle extends React.Component {
fill
=
{
this
.
props
.
fill
||
'
red
'
}
fill
=
{
this
.
props
.
fill
||
'
red
'
}
stroke
=
{
this
.
props
.
stroke
||
'
black
'
}
stroke
=
{
this
.
props
.
stroke
||
'
black
'
}
strokeWidth
=
{
this
.
props
.
strokeWidth
||
1
}
strokeWidth
=
{
this
.
props
.
strokeWidth
||
1
}
id
=
{
this
.
props
.
_id
}
draggable
=
{
activeTool
===
'
cursor
'
||
activeTool
===
'
edit
'
}
draggable
=
{
activeTool
===
'
cursor
'
||
activeTool
===
'
edit
'
}
onClick
=
{
this
.
handleClick
}
onClick
=
{
this
.
handleClick
}
...
@@ -136,7 +200,7 @@ class Rectangle extends React.Component {
...
@@ -136,7 +200,7 @@ class Rectangle extends React.Component {
<
Transformer
ref
=
{
this
.
trRef
}
<
Transformer
ref
=
{
this
.
trRef
}
visible
=
{
activeTool
===
'
edit
'
}
visible
=
{
activeTool
===
'
edit
'
&&
isSelected
}
/
>
/
>
...
@@ -153,25 +217,67 @@ class ParentComponent extends React.Component {
...
@@ -153,25 +217,67 @@ class ParentComponent extends React.Component {
constructor
(
props
)
{
constructor
(
props
)
{
super
(
props
);
super
(
props
);
this
.
state
=
{
selectedShapeId
:
this
.
props
.
selectedShapeId
,
currentShape
:
null
,
};
}
}
handleShapeClick
=
(
id
)
=>
{
handleShapeClick
=
(
id
)
=>
{
console
.
log
(
'
shape clicked
'
,
id
);
console
.
log
(
'
shape clicked
'
,
id
);
window
.
selectedShapeId
=
id
;
this
.
setState
({
selectedShapeId
:
id
});
this
.
setState
({
selectedShapeId
:
id
});
// this.setState({ selectedShapeId: id });
};
};
//handle key down
// handleKeyPress = (e) => {
// console.log('key press', e);
// if (e.key === 'Backspace') {
// const { shapes } = this.state;
// const { selectedShapeId } = this.state;
// const newShapes = shapes.filter((shape) => shape.id !== selectedShapeId);
// this.setState({ shapes: newShapes });
// }
// if (e.key === 'Escape') {
// this.setState({ currentShape: null });
// window.removeEventListener('keydown', this.handleKeyPress);
// }
// if (e.key === 'Enter') {
// this.setState({ currentShape: null });
// window.removeEventListener('keydown', this.handleKeyPress);
// }
// if (e.key === 'Delete') {
// const { shapes } = this.state;
// const { selectedShapeId } = this.state;
// const newShapes = shapes.filter((shape) => shape.id !== selectedShapeId);
// this.setState({ shapes: newShapes });
// }
// }
render
()
{
render
()
{
const
{
shapes
,
selectedShapeId
const
{
shapes
}
=
this
.
props
;
}
=
this
.
props
;
console
.
log
(
"
selectedId
"
,
this
.
props
.
selectedShapeId
);
console
.
log
(
'
shapes
'
,
this
.
props
.
shapes
);
return
(
return
(
<
Layer
>
<
Layer
>
{
shapes
.
map
((
shape
,
i
)
=>
{
{
shapes
.
map
((
shape
,
i
)
=>
{
console
.
log
(
'
shape
'
,
shape
);
switch
(
shape
.
type
)
{
switch
(
shape
.
type
)
{
case
'
rectangle
'
:
case
'
rectangle
'
:
...
@@ -179,7 +285,7 @@ class ParentComponent extends React.Component {
...
@@ -179,7 +285,7 @@ class ParentComponent extends React.Component {
return
(
return
(
<
Rectangle
<
Rectangle
selectedShapeId
=
{
this
.
props
.
selectedShapeId
}
activeTool
=
{
this
.
props
.
activeTool
}
activeTool
=
{
this
.
props
.
activeTool
}
_id
=
{
shape
.
id
}
_id
=
{
shape
.
id
}
key
=
{
i
}
key
=
{
i
}
...
@@ -204,7 +310,7 @@ class ParentComponent extends React.Component {
...
@@ -204,7 +310,7 @@ class ParentComponent extends React.Component {
<
TextNode
<
TextNode
activeTool
=
{
this
.
props
.
activeTool
}
activeTool
=
{
this
.
props
.
activeTool
}
selectedShapeId
=
{
this
.
props
.
selectedShapeId
}
_id
=
{
shape
.
id
}
_id
=
{
shape
.
id
}
key
=
{
i
}
key
=
{
i
}
x
=
{
shape
.
x
}
x
=
{
shape
.
x
}
...
@@ -366,7 +472,24 @@ class AnnotationDrawing extends Component {
...
@@ -366,7 +472,24 @@ class AnnotationDrawing extends Component {
console
.
log
(
'
draw konvas
'
,
this
.
props
);
console
.
log
(
'
draw konvas
'
,
this
.
props
);
const
{
shapes
,
newShape
,
currentShape
}
=
this
.
state
;
const
{
shapes
,
newShape
}
=
this
.
state
;
// update selected shape with new props if any
// for (let shape of shapes) {
// if (shape.id === window.selectedShapeId) {
// shape.strokeColor = this.props.strokeColor;
// shape.strokeWidth = this.props.strokeWidth;
// shape.fill = this.props.fillColor;
// // update shape in state
// this.setState({ shapes: [...shapes] });
// }
// }
...
@@ -389,8 +512,9 @@ class AnnotationDrawing extends Component {
...
@@ -389,8 +512,9 @@ class AnnotationDrawing extends Component {
<
ParentComponent
shapes
=
{
shapes
}
<
ParentComponent
shapes
=
{
shapes
}
selectedShapeId
activeTool
=
{
this
.
props
.
activeTool
}
activeTool
=
{
this
.
props
.
activeTool
}
selectedShapeId
=
{
this
.
state
.
selectedShapeId
}
/
>
/
>
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment