@@ -202,17 +202,53 @@ export default class Block extends EventsDispatcher<BlockEvents> {
202202
203203 /**
204204 * Is fired when DOM mutation has been happened
205+ *
206+ * mutationsOrInputEvent — actual changes
207+ * - MutationRecord[] - any DOM change
208+ * - InputEvent — <input> change
209+ * - undefined — manual triggering of block.dispatchChange()
205210 */
206- private didMutated = _ . debounce ( ( mutationsOrInputEvent : MutationRecord [ ] | InputEvent = [ ] ) : void => {
207- const shouldFireUpdate = mutationsOrInputEvent instanceof InputEvent ||
208- ! mutationsOrInputEvent . some ( ( {
209- addedNodes = [ ] ,
210- removedNodes,
211- } ) => {
212- return [ ...Array . from ( addedNodes ) , ...Array . from ( removedNodes ) ]
213- . some ( node => $ . isElement ( node ) && ( node as HTMLElement ) . dataset . mutationFree === 'true' ) ;
211+ private didMutated = _ . debounce ( ( mutationsOrInputEvent : MutationRecord [ ] | InputEvent = undefined ) : void => {
212+ /**
213+ * We won't fire a Block mutation event if mutation contain only nodes marked with 'data-mutation-free' attributes
214+ */
215+ let shouldFireUpdate ;
216+
217+ if ( mutationsOrInputEvent === undefined ) {
218+ shouldFireUpdate = true ;
219+ } else if ( mutationsOrInputEvent instanceof InputEvent ) {
220+ shouldFireUpdate = true ;
221+ } else {
222+ /**
223+ * Update from 2023, Feb 17:
224+ * Changed mutationsOrInputEvent.some() to mutationsOrInputEvent.every()
225+ * since there could be a real mutations same-time with mutation-free changes,
226+ * for example when Block Tune change: block is changing along with FakeCursor (mutation-free) removing
227+ * — we should fire 'didMutated' event in that case
228+ */
229+ const everyRecordIsMutationFree = mutationsOrInputEvent . length > 0 && mutationsOrInputEvent . every ( ( record ) => {
230+ const { addedNodes, removedNodes } = record ;
231+ const changedNodes = [
232+ ...Array . from ( addedNodes ) ,
233+ ...Array . from ( removedNodes ) ,
234+ ] ;
235+
236+ return changedNodes . some ( ( node ) => {
237+ if ( $ . isElement ( node ) === false ) {
238+ return false ;
239+ }
240+
241+ return ( node as HTMLElement ) . dataset . mutationFree === 'true' ;
242+ } ) ;
214243 } ) ;
215244
245+ if ( everyRecordIsMutationFree ) {
246+ shouldFireUpdate = false ;
247+ } else {
248+ shouldFireUpdate = true ;
249+ }
250+ }
251+
216252 /**
217253 * In case some mutation free elements are added or removed, do not trigger didMutated event
218254 */
0 commit comments