Skip to content

Commit

Permalink
Merge pull request #109 from flaviouk/add-on-initial-apply-callback
Browse files Browse the repository at this point in the history
Add on initial apply callback
  • Loading branch information
dmonad authored May 13, 2022
2 parents e3813d6 + 6e36d69 commit d1f4055
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
node_modules
dist
.idea
4 changes: 3 additions & 1 deletion src/plugins/sync-plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ export const isVisible = (item, snapshot) => snapshot === undefined ? !item.dele
* @property {Array<ColorDef>} [YSyncOpts.colors]
* @property {Map<string,ColorDef>} [YSyncOpts.colorMapping]
* @property {Y.PermanentUserData|null} [YSyncOpts.permanentUserData]
* @property {() => void} [YSyncOpts.onInitialApply]
*/

/**
Expand Down Expand Up @@ -74,7 +75,7 @@ const getUserColor = (colorMapping, colors, user) => {
* @param {YSyncOpts} opts
* @return {any} Returns a prosemirror plugin that binds to this type
*/
export const ySyncPlugin = (yXmlFragment, { colors = defaultColors, colorMapping = new Map(), permanentUserData = null } = {}) => {
export const ySyncPlugin = (yXmlFragment, { colors = defaultColors, colorMapping = new Map(), permanentUserData = null, onInitialApply = () => {} } = {}) => {
let changedInitialContent = false
let rerenderTimeoutId
const plugin = new Plugin({
Expand Down Expand Up @@ -141,6 +142,7 @@ export const ySyncPlugin = (yXmlFragment, { colors = defaultColors, colorMapping
rerenderTimeoutId = eventloop.timeout(0, () => {
binding._forceRerender()
view.dispatch(view.state.tr.setMeta(ySyncPluginKey, { binding }))
onInitialApply()
})
return {
update: () => {
Expand Down

0 comments on commit d1f4055

Please sign in to comment.