feat: ability to debug the state of fractional indices (#8235)

This commit is contained in:
Marcel Mraz 2024-07-30 10:03:27 +02:00 committed by GitHub
parent 7b36de0476
commit d0a380758e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 122 additions and 10 deletions

View file

@ -1,5 +1,10 @@
import { ENV } from "../constants";
import type { OrderedExcalidrawElement } from "../element/types";
import { orderByFractionalIndex, syncInvalidIndices } from "../fractionalIndex";
import {
orderByFractionalIndex,
syncInvalidIndices,
validateFractionalIndices,
} from "../fractionalIndex";
import type { AppState } from "../types";
import type { MakeBrand } from "../utility-types";
import { arrayToMap } from "../utils";
@ -72,6 +77,27 @@ export const reconcileElements = (
const orderedElements = orderByFractionalIndex(reconciledElements);
if (
import.meta.env.DEV ||
import.meta.env.MODE === ENV.TEST ||
window?.DEBUG_FRACTIONAL_INDICES
) {
const elements = syncInvalidIndices(
// create new instances due to the mutation
orderedElements.map((x) => ({ ...x })),
);
validateFractionalIndices(elements, {
// throw in dev & test only, to remain functional on `DEBUG_FRACTIONAL_INDICES`
shouldThrow: import.meta.env.DEV || import.meta.env.MODE === ENV.TEST,
includeBoundTextValidation: true,
reconciliationContext: {
localElements,
remoteElements,
},
});
}
// de-duplicate indices
syncInvalidIndices(orderedElements);