Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
W
wax-prosemirror
Manage
Activity
Members
Labels
Plan
Issues
34
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
2
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Container Registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
wax
wax-prosemirror
Commits
039fe4e3
Commit
039fe4e3
authored
9 months ago
by
chris
Browse files
Options
Downloads
Patches
Plain Diff
use WaxView
parent
dfdde04f
No related branches found
No related tags found
1 merge request
!597
Use view context
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
editors/demo/src/Editors.js
+1
-1
1 addition, 1 deletion
editors/demo/src/Editors.js
wax-prosemirror-core/src/WaxView.js
+4
-25
4 additions, 25 deletions
wax-prosemirror-core/src/WaxView.js
wax-prosemirror-core/src/useWaxView.js
+7
-8
7 additions, 8 deletions
wax-prosemirror-core/src/useWaxView.js
with
12 additions
and
34 deletions
editors/demo/src/Editors.js
+
1
−
1
View file @
039fe4e3
...
...
@@ -91,7 +91,7 @@ const Editors = () => {
case
'
oen
'
:
return
<
OEN
/>
;
default
:
return
<
Editoria
/>
;
return
<
HHMI
/>
;
}
};
...
...
This diff is collapsed.
Click to expand it.
wax-prosemirror-core/src/WaxView.js
+
4
−
25
View file @
039fe4e3
/* eslint-disable consistent-return */
/* eslint-disable react/prop-types */
import
React
,
{
useContext
,
useCallback
,
useEffect
,
useRef
}
from
'
react
'
;
import
React
,
{
useCallback
,
useEffect
,
useRef
}
from
'
react
'
;
import
styled
from
'
styled-components
'
;
import
{
WaxContext
}
from
'
./WaxContext
'
;
import
ComponentPlugin
from
'
./ComponentPlugin
'
;
import
'
./styles/styles.css
'
;
import
useWaxView
from
'
./useWaxView
'
;
...
...
@@ -20,37 +17,19 @@ const WaxPortals = ComponentPlugin('waxPortals');
const
WaxOverlays
=
ComponentPlugin
(
'
waxOverlays
'
);
const
WaxView
=
props
=>
{
const
{
autoFocus
}
=
props
;
const
main
=
useWaxView
(
props
);
// const {
// pmViews: { main },
// } = useContext(WaxContext);
useEffect
(()
=>
{
if
(
autoFocus
&&
main
)
{
main
.
focus
();
}
},
[
autoFocus
]);
const
divRef
=
useRef
(
null
);
const
initialize
=
useCallback
(()
=>
{
console
.
log
(
'
Initializing only once
'
);
// You can perform any initialization logic here
// This code will only run once when the component mounts
const
initializeWaxView
=
useCallback
(()
=>
{
if
(
divRef
.
current
)
{
console
.
log
(
'
dkddkkdk
'
,
main
?.
dom
);
divRef
.
current
.
replaceChildren
(
main
?.
dom
);
// Perform some operation with divRef.current
}
},
[
main
]);
useEffect
(()
=>
{
initialize
();
},
[
initialize
]);
initialize
WaxView
();
},
[
initialize
WaxView
]);
return
(
<
EditorContainer
>
...
...
This diff is collapsed.
Click to expand it.
wax-prosemirror-core/src/useWaxView.js
+
7
−
8
View file @
039fe4e3
/* eslint-disable consistent-return */
/* eslint-disable react/prop-types */
import
{
useContext
,
useEffect
,
useImperativeHandle
,
useState
}
from
'
react
'
;
import
{
EditorState
}
from
'
prosemirror-state
'
;
import
{
EditorView
}
from
'
prosemirror-view
'
;
...
...
@@ -26,6 +24,7 @@ const useWaxView = props => {
scrollThreshold
,
onChange
,
}
=
props
;
const
context
=
useContext
(
WaxContext
);
const
[
WaxView
,
setWaxView
]
=
useState
(
null
);
const
{
createPortal
}
=
useContext
(
PortalContext
);
...
...
@@ -33,12 +32,12 @@ const useWaxView = props => {
context
.
app
.
setContext
({
...
context
,
createPortal
});
const
schema
=
context
.
app
.
getSchema
();
let
view
;
useEffect
(()
=>
{
context
.
app
.
bootServices
();
context
.
app
.
getShortCuts
();
context
.
app
.
getRules
();
console
.
log
(
'
all props
'
,
props
);
const
options
=
WaxOptions
({
...
props
,
schema
,
...
...
@@ -98,11 +97,6 @@ const useWaxView = props => {
const
state
=
view
.
state
.
apply
(
tr
);
view
.
updateState
(
state
);
const
docContent
=
targetFormat
===
'
JSON
'
?
state
.
doc
.
toJSON
()
:
state
.
doc
.
content
;
if
(
!
previousDoc
.
eq
(
view
.
state
.
doc
)
||
tr
.
getMeta
(
'
forceUpdate
'
))
if
(
onChange
)
onChange
(
docContent
);
/* when a transaction comes from a view other than
main don't keep updating the view ,as this is
the central point of each transaction
...
...
@@ -117,6 +111,11 @@ const useWaxView = props => {
'
main
'
,
);
}
const
docContent
=
targetFormat
===
'
JSON
'
?
state
.
doc
.
toJSON
()
:
state
.
doc
.
content
;
if
(
!
previousDoc
.
eq
(
view
.
state
.
doc
)
||
tr
.
getMeta
(
'
forceUpdate
'
))
onChange
(
docContent
);
};
return
WaxView
;
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
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