feat(tools): add brush raster painting
This commit is contained in:
@@ -18,6 +18,7 @@ import {
|
||||
documentSetLayerClippingMaskCommand,
|
||||
documentSetLayerLockedCommand,
|
||||
documentSetLayerVisibleCommand,
|
||||
documentUpdateAssetSourceCommand,
|
||||
documentUngroupLayerCommand,
|
||||
} from "./document";
|
||||
|
||||
@@ -52,6 +53,17 @@ describe("document commands", () => {
|
||||
]);
|
||||
});
|
||||
|
||||
test("updates asset sources", () => {
|
||||
const state = documentAddAssetCommand.execute(
|
||||
{ state: createInitialAppState("Test") },
|
||||
{ asset: { id: "asset-1", name: "Image", mimeType: "image/png", source: "old", intrinsicSize: { w: 100, h: 50 } } },
|
||||
);
|
||||
|
||||
const next = documentUpdateAssetSourceCommand.execute({ state }, { assetId: "asset-1", source: "new" });
|
||||
|
||||
expect(next.document.assets[0]?.source).toBe("new");
|
||||
});
|
||||
|
||||
test("adds image layers to artboards", () => {
|
||||
const state = documentAddArtboardCommand.execute(
|
||||
{ state: createInitialAppState("Test") },
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import type { Asset } from "@core/asset";
|
||||
import type { ImageDocument } from "@core/document";
|
||||
import type { Rect } from "@core/geometry";
|
||||
import type { ArtboardId, LayerId } from "@core/id";
|
||||
import type { ArtboardId, AssetId, LayerId } from "@core/id";
|
||||
import type { ImageLayer } from "@core/image-layer";
|
||||
import type { Layer } from "@core/layer";
|
||||
import type { RasterLayer } from "@core/raster-layer";
|
||||
@@ -43,6 +43,11 @@ export type DocumentAddAssetPayload = {
|
||||
asset: Asset;
|
||||
};
|
||||
|
||||
export type DocumentUpdateAssetSourcePayload = {
|
||||
assetId: AssetId;
|
||||
source: string;
|
||||
};
|
||||
|
||||
export type DocumentAddImageLayerPayload = {
|
||||
artboardId: ArtboardId;
|
||||
parentGroupId?: LayerId;
|
||||
@@ -219,6 +224,20 @@ export const documentAddAssetCommand: Command<DocumentAddAssetPayload> = {
|
||||
},
|
||||
};
|
||||
|
||||
export const documentUpdateAssetSourceCommand: Command<DocumentUpdateAssetSourcePayload> = {
|
||||
id: commandIds.documentUpdateAssetSource,
|
||||
name: "Update asset source",
|
||||
execute({ state }, payload) {
|
||||
return {
|
||||
...state,
|
||||
document: {
|
||||
...state.document,
|
||||
assets: state.document.assets.map((asset) => (asset.id === payload.assetId ? { ...asset, source: payload.source } : asset)),
|
||||
},
|
||||
};
|
||||
},
|
||||
};
|
||||
|
||||
export const documentAddImageLayerCommand: Command<DocumentAddImageLayerPayload> = {
|
||||
id: commandIds.documentAddImageLayer,
|
||||
name: "Add image layer",
|
||||
@@ -406,6 +425,7 @@ export const documentCommands = [
|
||||
documentSetArtboardLockedCommand,
|
||||
documentRenameArtboardCommand,
|
||||
documentAddAssetCommand,
|
||||
documentUpdateAssetSourceCommand,
|
||||
documentAddImageLayerCommand,
|
||||
documentAddRasterLayerCommand,
|
||||
documentAddGroupLayerCommand,
|
||||
|
||||
@@ -6,6 +6,7 @@ export const commandIds = {
|
||||
documentSetArtboardLocked: "document.setArtboardLocked",
|
||||
documentRenameArtboard: "document.renameArtboard",
|
||||
documentAddAsset: "document.addAsset",
|
||||
documentUpdateAssetSource: "document.updateAssetSource",
|
||||
documentAddImageLayer: "document.addImageLayer",
|
||||
documentAddRasterLayer: "document.addRasterLayer",
|
||||
documentAddGroupLayer: "document.addGroupLayer",
|
||||
|
||||
@@ -18,6 +18,7 @@ export {
|
||||
documentSetLayerClippingMaskCommand,
|
||||
documentSetLayerLockedCommand,
|
||||
documentSetLayerVisibleCommand,
|
||||
documentUpdateAssetSourceCommand,
|
||||
documentUngroupLayerCommand,
|
||||
} from "./document";
|
||||
export type {
|
||||
@@ -38,6 +39,7 @@ export type {
|
||||
DocumentSetLayerClippingMaskPayload,
|
||||
DocumentSetLayerLockedPayload,
|
||||
DocumentSetLayerVisiblePayload,
|
||||
DocumentUpdateAssetSourcePayload,
|
||||
DocumentUngroupLayerPayload,
|
||||
} from "./document";
|
||||
export { historyCommands, historyRedoCommand, historyUndoCommand } from "./history";
|
||||
|
||||
@@ -17,6 +17,7 @@ import type {
|
||||
DocumentSetLayerClippingMaskPayload,
|
||||
DocumentSetLayerLockedPayload,
|
||||
DocumentSetLayerVisiblePayload,
|
||||
DocumentUpdateAssetSourcePayload,
|
||||
DocumentUngroupLayerPayload,
|
||||
} from "./document";
|
||||
import type { SelectionAddLayerPayload, SelectionSetPayload } from "./selection";
|
||||
@@ -38,6 +39,7 @@ export type CommandPayloads = {
|
||||
[commandIds.documentSetArtboardLocked]: DocumentSetArtboardLockedPayload;
|
||||
[commandIds.documentRenameArtboard]: DocumentRenameArtboardPayload;
|
||||
[commandIds.documentAddAsset]: DocumentAddAssetPayload;
|
||||
[commandIds.documentUpdateAssetSource]: DocumentUpdateAssetSourcePayload;
|
||||
[commandIds.documentAddImageLayer]: DocumentAddImageLayerPayload;
|
||||
[commandIds.documentAddRasterLayer]: DocumentAddRasterLayerPayload;
|
||||
[commandIds.documentAddGroupLayer]: DocumentAddGroupLayerPayload;
|
||||
|
||||
Reference in New Issue
Block a user