Skip to content

Commit

Permalink
Reconcile table and image selection for cache (#2714)
Browse files Browse the repository at this point in the history
* Improve cache

* fix build

* improve

* add test

* Cache and entity 2

* Add test

* Reconcile table and image selection for cache

* support reconcile entity delimiter

* fix build

* add test

---------

Co-authored-by: Bryan Valverde U <[email protected]>
  • Loading branch information
JiuqingSong and BryanValverdeU authored Aug 29, 2024
1 parent b3111df commit 5b07b94
Show file tree
Hide file tree
Showing 25 changed files with 984 additions and 82 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { areSameSelections } from './areSameSelections';
import { createTextMutationObserver } from './textMutationObserver';
import { DomIndexerImpl } from './domIndexerImpl';
import { updateCache } from './updateCache';
import type { Mutation } from './textMutationObserver';
import type { Mutation } from './MutationType';
import type {
CachePluginState,
IEditor,
Expand Down Expand Up @@ -90,6 +90,19 @@ class CachePlugin implements PluginWithState<CachePluginState> {
}

switch (event.eventType) {
case 'logicalRootChanged':
this.invalidateCache();

if (this.state.textMutationObserver) {
this.state.textMutationObserver.stopObserving();
this.state.textMutationObserver = createTextMutationObserver(
event.logicalRoot,
this.onMutation
);
this.state.textMutationObserver.startObserving();
}
break;

case 'keyDown':
case 'input':
if (!this.state.textMutationObserver) {
Expand Down Expand Up @@ -133,6 +146,15 @@ class CachePlugin implements PluginWithState<CachePluginState> {
this.updateCachedModel(this.editor, true /*forceUpdate*/);
break;

case 'elementId':
const element = mutation.element;

if (!this.state.domIndexer?.reconcileElementId(element)) {
this.invalidateCache();
}

break;

case 'unknown':
this.invalidateCache();
break;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/**
* @internal Type of mutations
*/
export type MutationType =
/**
* We found some change happened but we cannot handle it, so set mutation type as "unknown"
*/
| 'unknown'
/**
* Element id is changed
*/
| 'elementId'
/**
* Only text is changed
*/
| 'text'
/**
* Child list is changed
*/
| 'childList';

/**
* @internal
*/
export interface MutationBase<T extends MutationType> {
type: T;
}

/**
* @internal
*/
export interface UnknownMutation extends MutationBase<'unknown'> {}

/**
* @internal
*/
export interface ElementIdMutation extends MutationBase<'elementId'> {
element: HTMLElement;
}

/**
* @internal
*/
export interface TextMutation extends MutationBase<'text'> {}

/**
* @internal
*/
export interface ChildListMutation extends MutationBase<'childList'> {
addedNodes: Node[];
removedNodes: Node[];
}

/**
* @internal
*/
export type Mutation = UnknownMutation | ElementIdMutation | TextMutation | ChildListMutation;
Loading

0 comments on commit 5b07b94

Please sign in to comment.