Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions code/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added

- [#305](https://github.com/InditexTech/weavejs/issues/305) Don't allow to transform when more than one element is selected
- [#308](https://github.com/InditexTech/weavejs/issues/308) Allow to configure transformer configuration per node

### Fixed

Expand Down
2 changes: 2 additions & 0 deletions code/packages/sdk/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@

export { Weave } from './weave';
export { WeaveStore } from './stores/store';
export * from './stores/types';
export { WeaveNode } from './nodes/node';
export * from './nodes/constants';
export { WeaveAction } from './actions/action';
export * from './actions/types';
export { WeavePlugin } from './plugins/plugin';
Expand Down
14 changes: 14 additions & 0 deletions code/packages/sdk/src/nodes/constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// SPDX-FileCopyrightText: 2025 2025 INDUSTRIA DE DISEÑO TEXTIL S.A. (INDITEX S.A.)
//
// SPDX-License-Identifier: Apache-2.0

export const DEFAULT_ANCHORS_ENABLED: string[] = [
'top-left',
'top-center',
'top-right',
'middle-right',
'middle-left',
'bottom-left',
'bottom-center',
'bottom-right',
];
5 changes: 5 additions & 0 deletions code/packages/sdk/src/nodes/frame/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,11 @@ export const WEAVE_FRAME_NODE_DEFAULT_CONFIG = {
borderColor: '#ff6863ff',
fill: '#ffffffff',
},
transform: {
rotateEnabled: false,
resizeEnabled: false,
enabledAnchors: [] as string[],
},
};

export const WEAVE_FRAME_NODE_DEFAULT_PROPS = {
Expand Down
4 changes: 4 additions & 0 deletions code/packages/sdk/src/nodes/frame/frame.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,10 @@ export class WeaveFrameNode extends WeaveNode {
name: 'node',
});

frame.getTransformerProperties = () => {
return this.config.transform;
};

const background = new Konva.Rect({
id: `${id}-bg`,
nodeId: id,
Expand Down
2 changes: 2 additions & 0 deletions code/packages/sdk/src/nodes/frame/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import type {
WEAVE_FRAME_NODE_SIZES_ORIENTATION,
WEAVE_FRAME_NODE_SIZES_TYPES,
} from './constants';
import type { WeaveNodeTransformerProperties } from '../types';

export type WeaveFrameNodeSizesOrientationKeys =
keyof typeof WEAVE_FRAME_NODE_SIZES_ORIENTATION;
Expand Down Expand Up @@ -40,6 +41,7 @@ export type WeaveFrameProperties = {
borderColor: string;
fill: string;
};
transform: WeaveNodeTransformerProperties;
};

export type WeaveFrameAttributes = WeaveElementAttributes & {
Expand Down
11 changes: 11 additions & 0 deletions code/packages/sdk/src/nodes/node-extensions.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// SPDX-FileCopyrightText: 2025 2025 INDUSTRIA DE DISEÑO TEXTIL S.A. (INDITEX S.A.)
//
// SPDX-License-Identifier: Apache-2.0

import 'konva';

declare module 'konva/lib/Node' {
interface Node {
getTransformerProperties(): WeaveNodeTransformerProperties;
}
}
10 changes: 10 additions & 0 deletions code/packages/sdk/src/nodes/node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,16 @@ import {
moveNodeToContainer,
} from '@/utils';
import type { WeaveNodesSnappingPlugin } from '@/plugins/nodes-snapping/nodes-snapping';
import './node-extensions.d';
import { DEFAULT_ANCHORS_ENABLED } from './constants';

Konva.Node.prototype.getTransformerProperties = function () {
return {
rotateEnabled: true,
resizeEnabled: true,
enabledAnchors: DEFAULT_ANCHORS_ENABLED,
};
};

export abstract class WeaveNode implements WeaveNodeBase {
protected instance!: Weave;
Expand Down
9 changes: 9 additions & 0 deletions code/packages/sdk/src/nodes/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// SPDX-FileCopyrightText: 2025 2025 INDUSTRIA DE DISEÑO TEXTIL S.A. (INDITEX S.A.)
//
// SPDX-License-Identifier: Apache-2.0

export type WeaveNodeTransformerProperties = {
rotateEnabled: boolean;
resizeEnabled: boolean;
enabledAnchors: string[];
};
Original file line number Diff line number Diff line change
Expand Up @@ -652,6 +652,12 @@ export class WeaveNodesSelectionPlugin extends WeavePlugin {
) {
this.tr.enabledAnchors(this.defaultEnabledAnchors);
}
if (nodesSelected === 1 && nodeTargeted.getTransformerProperties) {
this.tr.setAttrs({
...nodeTargeted.getTransformerProperties(),
});
this.tr.forceUpdate();
}

if (areNodesSelected) {
stage.container().tabIndex = 1;
Expand Down
26 changes: 26 additions & 0 deletions docs/content/docs/main/build/nodes/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ description: Nodes maintained by Weave.js team
---

import { CpuIcon, Database } from "lucide-react";
import { Separator } from "@/components/separator";

## Introduction

Expand Down Expand Up @@ -161,6 +162,31 @@ onRender(props: WeaveElementAttributes): WeaveElementInstance
The `onRender` method is the one responsible for rendering the node on the canvas, It's a good place
to initialize the nodes, events, etc.

<Separator />

We extend the `Konva.Node` class to define a function:

```ts
getTransformerProperties(): WeaveNodeTransformerProperties
```

That you can override, allowing to define when the node is selected if can: rotate, resize and if is resizable which anchors for resizing will be available.

By default, all nodes can rotate, resize and the default anchors are:

```ts
const DEFAULT_ANCHORS_ENABLED: string[] = [
"top-left",
"top-center",
"top-right",
"middle-right",
"middle-left",
"bottom-left",
"bottom-center",
"bottom-right",
];
```

#### onUpdate

```ts
Expand Down
1 change: 1 addition & 0 deletions docs/content/docs/main/changelog/prerelease/0.20.0.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ description: Selection & grouping bugfixes
### Added

- [#305](https://github.com/InditexTech/weavejs/issues/305) Don't allow to transform when more than one element is selected
- [#308](https://github.com/InditexTech/weavejs/issues/308) Allow to configure transformer configuration per node

### Fixed

Expand Down