mirror of
https://github.com/ankitects/anki.git
synced 2025-09-23 16:26:40 -04:00
Improve typing of custom fabric.Object properties (#3134)
* Ensure increasing ordinals of new masks
* Add fabric.d.ts
* Revert "Ensure increasing ordinals of new masks"
This reverts commit dedfeec9ad
.
This commit is contained in:
parent
31439e325d
commit
e486d6b513
3 changed files with 12 additions and 5 deletions
12
ts/routes/image-occlusion/fabric.d.ts
vendored
Normal file
12
ts/routes/image-occlusion/fabric.d.ts
vendored
Normal file
|
@ -0,0 +1,12 @@
|
|||
export {};
|
||||
|
||||
declare global {
|
||||
namespace fabric {
|
||||
interface Object {
|
||||
id: string;
|
||||
ordinal: number;
|
||||
/** a custom property set on groups in the ungrouping routine to avoid adding a spurious undo entry */
|
||||
destroyed: boolean;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -64,12 +64,10 @@ export const groupShapes = (canvas: fabric.Canvas): void => {
|
|||
const activeObject = canvas.getActiveObject() as fabric.ActiveSelection;
|
||||
const items = activeObject.getObjects();
|
||||
|
||||
// @ts-expect-error not defined
|
||||
let minOrdinal: number | undefined = Math.min(...items.map((item) => item.ordinal));
|
||||
minOrdinal = Number.isNaN(minOrdinal) ? undefined : minOrdinal;
|
||||
|
||||
items.forEach((item) => {
|
||||
// @ts-expect-error not defined
|
||||
item.set({ opacity: 1, ordinal: minOrdinal });
|
||||
});
|
||||
|
||||
|
@ -90,13 +88,11 @@ export const unGroupShapes = (canvas: fabric.Canvas): void => {
|
|||
const group = canvas.getActiveObject() as fabric.Group;
|
||||
const items = group.getObjects();
|
||||
group._restoreObjectsState();
|
||||
// @ts-expect-error not defined
|
||||
group.destroyed = true;
|
||||
|
||||
items.forEach((item) => {
|
||||
item.set({
|
||||
opacity: get(opacityStateStore) ? 0.4 : 1,
|
||||
// @ts-expect-error not defined
|
||||
ordinal: undefined,
|
||||
});
|
||||
canvas.add(item);
|
||||
|
|
|
@ -50,7 +50,6 @@ class UndoStack {
|
|||
this.canvas = canvas;
|
||||
this.canvas.on("object:modified", (opts) => this.maybePush(opts));
|
||||
this.canvas.on("object:removed", (opts) => {
|
||||
// @ts-expect-error `destroyed` is a custom property set on groups in the ungrouping routine to avoid adding a spurious undo entry
|
||||
if (!opts.target!.group && !opts.target!.destroyed) {
|
||||
this.maybePush(opts);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue