@tldraw/editor 5.0.0 → 5.1.0-canary.2eb9f83a5993

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -2643,6 +2643,7 @@ export declare class Editor extends EventEmitter<TLEventMap> {
2643
2643
  * @public
2644
2644
  */
2645
2645
  getRenderingShapes(): TLRenderingShape[];
2646
+ private _renderingShapesSortCache;
2646
2647
  private _getAllPagesQuery;
2647
2648
  /**
2648
2649
  * Info about the project's current pages.
package/dist-cjs/index.js CHANGED
@@ -380,7 +380,7 @@ var import_uniq = require("./lib/utils/uniq");
380
380
  var import_defaultThemes2 = require("./lib/editor/managers/ThemeManager/defaultThemes");
381
381
  (0, import_utils.registerTldrawLibraryVersion)(
382
382
  "@tldraw/editor",
383
- "5.0.0",
383
+ "5.1.0-canary.2eb9f83a5993",
384
384
  "cjs"
385
385
  );
386
386
  //# sourceMappingURL=index.js.map
@@ -93,6 +93,7 @@ var import_TickManager = require("./managers/TickManager/TickManager");
93
93
  var import_UserPreferencesManager = require("./managers/UserPreferencesManager/UserPreferencesManager");
94
94
  var import_OverlayManager = require("./overlays/OverlayManager");
95
95
  var import_RootState = require("./tools/RootState");
96
+ const RENDERING_SHAPES_SORT_CACHE_THRESHOLD = 100;
96
97
  class Editor extends import_eventemitter3.default {
97
98
  id = (0, import_utils.uniqueId)();
98
99
  constructor({
@@ -3385,8 +3386,34 @@ class Editor extends import_eventemitter3.default {
3385
3386
  }
3386
3387
  getRenderingShapes() {
3387
3388
  const renderingShapes = this.getUnorderedRenderingShapes(true);
3388
- return renderingShapes.sort(import_utils.sortById);
3389
+ if (renderingShapes.length <= RENDERING_SHAPES_SORT_CACHE_THRESHOLD) {
3390
+ this._renderingShapesSortCache = null;
3391
+ return renderingShapes.sort(import_utils.sortById);
3392
+ }
3393
+ const cache = this._renderingShapesSortCache;
3394
+ if (cache !== null && cache.size === renderingShapes.length) {
3395
+ const sorted = new Array(renderingShapes.length);
3396
+ let allMatched = true;
3397
+ for (let i = 0; i < renderingShapes.length; i++) {
3398
+ const entry = renderingShapes[i];
3399
+ const pos = cache.get(entry.id);
3400
+ if (pos === void 0) {
3401
+ allMatched = false;
3402
+ break;
3403
+ }
3404
+ sorted[pos] = entry;
3405
+ }
3406
+ if (allMatched) return sorted;
3407
+ }
3408
+ renderingShapes.sort(import_utils.sortById);
3409
+ const positionById = /* @__PURE__ */ new Map();
3410
+ for (let i = 0; i < renderingShapes.length; i++) {
3411
+ positionById.set(renderingShapes[i].id, i);
3412
+ }
3413
+ this._renderingShapesSortCache = positionById;
3414
+ return renderingShapes;
3389
3415
  }
3416
+ _renderingShapesSortCache = null;
3390
3417
  _getAllPagesQuery() {
3391
3418
  return this.store.query.records("page");
3392
3419
  }