@@ -32,6 +32,29 @@ const DEAD_KEY_PLACEHOLDER_MARKS = new Map([
3232 [ '¨' , '\u0308' ] ,
3333] ) ;
3434
35+ const TRACKABLE_META_KEYS = [
36+ 'inputType' ,
37+ 'uiEvent' ,
38+ 'paste' ,
39+ 'pointer' ,
40+ 'composition' ,
41+ 'superdocSlicePaste' ,
42+ 'forceTrackChanges' ,
43+ 'protectTrackedReviewState' ,
44+ ] ;
45+
46+ const PASSTHROUGH_META_KEYS = [
47+ 'inputType' ,
48+ 'uiEvent' ,
49+ 'paste' ,
50+ 'pointer' ,
51+ 'composition' ,
52+ 'addToHistory' ,
53+ 'superdocSlicePaste' ,
54+ ] ;
55+
56+ const ALLOWED_META_KEYS = new Set ( [ ...TRACKABLE_META_KEYS , ySyncPluginKey . key ] ) ;
57+
3558const getTextNodeAtPos = ( { doc, pos } ) => {
3659 let found = null ;
3760
@@ -275,6 +298,15 @@ const mergeTrackChangesMeta = (tr, extraMeta) => {
275298 tr . setMeta ( TrackChangesBasePluginKey , { ...existingMeta , ...extraMeta } ) ;
276299} ;
277300
301+ const copyPassthroughMeta = ( sourceTr , targetTr ) => {
302+ PASSTHROUGH_META_KEYS . forEach ( ( key ) => {
303+ const value = sourceTr . getMeta ( key ) ;
304+ if ( value !== undefined ) {
305+ targetTr . setMeta ( key , value ) ;
306+ }
307+ } ) ;
308+ } ;
309+
278310const getPendingDeadKeyPlaceholder = ( { tr, newTr, user } ) => {
279311 if ( ! isCompositionTransaction ( tr ) || tr . steps . length !== 1 ) {
280312 return null ;
@@ -343,18 +375,11 @@ const getPendingDeadKeyPlaceholder = ({ tr, newTr, user }) => {
343375 * transaction ready to dispatch.
344376 */
345377export const trackedTransaction = ( { tr, state, user, replacements = 'paired' } ) => {
346- const onlyInputTypeMeta = [ 'inputType' , 'uiEvent' , 'paste' , 'pointer' , 'composition' ] ;
347378 const notAllowedMeta = [ 'historyUndo' , 'historyRedo' , 'acceptReject' ] ;
348379 const isProgrammaticInput = tr . getMeta ( 'inputType' ) === 'programmatic' ;
349380 const ySyncMeta = tr . getMeta ( ySyncPluginKey ) ;
350381 const pendingDeadKeyPlaceholder = TrackChangesBasePluginKey . getState ( state ) ?. pendingDeadKeyPlaceholder ?? null ;
351- const allowedMeta = new Set ( [
352- ...onlyInputTypeMeta ,
353- ySyncPluginKey . key ,
354- 'forceTrackChanges' ,
355- 'protectTrackedReviewState' ,
356- ] ) ;
357- const hasDisallowedMeta = tr . meta && Object . keys ( tr . meta ) . some ( ( meta ) => ! allowedMeta . has ( meta ) ) ;
382+ const hasDisallowedMeta = tr . meta && Object . keys ( tr . meta ) . some ( ( meta ) => ! ALLOWED_META_KEYS . has ( meta ) ) ;
358383
359384 if (
360385 ySyncMeta ?. isChangeOrigin || // Skip Yjs-origin transactions (remote/rehydration).
@@ -442,21 +467,7 @@ export const trackedTransaction = ({ tr, state, user, replacements = 'paired' })
442467 }
443468 } ) ;
444469
445- if ( tr . getMeta ( 'inputType' ) ) {
446- newTr . setMeta ( 'inputType' , tr . getMeta ( 'inputType' ) ) ;
447- }
448-
449- if ( tr . getMeta ( 'uiEvent' ) ) {
450- newTr . setMeta ( 'uiEvent' , tr . getMeta ( 'uiEvent' ) ) ;
451- }
452-
453- if ( tr . getMeta ( 'composition' ) !== undefined ) {
454- newTr . setMeta ( 'composition' , tr . getMeta ( 'composition' ) ) ;
455- }
456-
457- if ( tr . getMeta ( 'addToHistory' ) !== undefined ) {
458- newTr . setMeta ( 'addToHistory' , tr . getMeta ( 'addToHistory' ) ) ;
459- }
470+ copyPassthroughMeta ( tr , newTr ) ;
460471
461472 mergeTrackChangesMeta ( newTr , {
462473 pendingDeadKeyPlaceholder : getPendingDeadKeyPlaceholder ( { tr, newTr, user } ) ,
0 commit comments