From 6e36d69fa3028e0b7d722bc8b6fd4afefbbb930a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fl=C3=A1vio=20Carvalho?= Date: Thu, 12 May 2022 16:19:59 +0100 Subject: [PATCH] Add on initial apply callback --- .gitignore | 1 + src/plugins/sync-plugin.js | 4 +++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index f06235c..82ee25a 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ node_modules dist +.idea diff --git a/src/plugins/sync-plugin.js b/src/plugins/sync-plugin.js index 07442ff..4cf2524 100644 --- a/src/plugins/sync-plugin.js +++ b/src/plugins/sync-plugin.js @@ -40,6 +40,7 @@ export const isVisible = (item, snapshot) => snapshot === undefined ? !item.dele * @property {Array} [YSyncOpts.colors] * @property {Map} [YSyncOpts.colorMapping] * @property {Y.PermanentUserData|null} [YSyncOpts.permanentUserData] + * @property {() => void} [YSyncOpts.onInitialApply] */ /** @@ -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({ @@ -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: () => {