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
64 changes: 53 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ Therefore, to use this, an understanding of the following two libraries is essen
- [canUndo()](#canundo)
- [canRedo()](#canredo)
- [clear()](#clear)
- [subscribe(listener)](#subscribelistener)
- [πŸ“’ Full List of Available Events](#-full-list-of-available-events)
- [πŸ§‘β€πŸ’» Development](#-development)
- [Setting up the development environment](#setting-up-the-development-environment)
- [VSCode Integration](#vscode-integration)
Expand Down Expand Up @@ -560,6 +560,22 @@ patchmap.transformer.elements = [selectedObject];
patchmap.transformer.elements = [];
```

#### transformer.selection

An instance of `SelectionModel` for dedicated management of the `Transformer`'s selection state. This allows you to programmatically control the selected elements.

```js
// Add, remove, and replace selected elements
transformer.selection.add(item1);
transformer.selection.remove(item1);
transformer.selection.set([item2]);

// Subscribe to selection change events
transformer.on('update_elements', ({ current, added, removed }) => {
console.log('Current selection:', current);
});
```

<br/>

## undoRedoManager
Expand Down Expand Up @@ -591,17 +607,43 @@ Returns whether redo is possible.
#### `clear()`
Clears all command history.

#### `subscribe(listener)`
Subscribes a listener that will be called when command-related changes occur. You can call the returned function to unsubscribe.
```js
let canUndo = false;
let canRedo = false;
<br/>

const unsubscribe = undoRedoManager.subscribe((manager) => {
canUndo = manager.canUndo();
canRedo = manager.canRedo();
});
```
## πŸ“’ Full List of Available Events

This is the list of events that can be subscribed to with this update. You can subscribe using `.on(eventName, callback)`.

#### `Patchmap`

* `patchmap:initialized`: Fired when `patchmap.init()` completes successfully.
* `patchmap:draw`: Fired when new data is rendered via `patchmap.draw()`.
* `patchmap:updated`: Fired when elements are updated via `patchmap.update()`.
* `patchmap:destroyed`: Fired when the instance is destroyed by calling `patchmap.destroy()`.

#### `UndoRedoManager`

* `history:executed`: Fired when a new command is added to the execution stack.
* `history:undone`: Fired when `undo()` is executed.
* `history:redone`: Fired when `redo()` is executed.
* `history:cleared`: Fired when all history is deleted with `clear()`.
* `history:destroyed`: Fired when `destroy()` is called.
* `history:*`: Subscribes to all of the above `history:` namespace events.

#### `StateManager`

* `state:pushed`: Fired when a new state is added to the stack.
* `state:popped`: Fired when the current state is removed from the stack.
* `state:set`: Fired when the state stack is reset and a new state is set via `setState()`.
* `state:reset`: Fired when all states are removed with `resetState()`.
* `state:destroyed`: Fired when `destroy()` is called.
* `modifier:activated`: Fired when a modifier state is activated.
* `modifier:deactivated`: Fired when a modifier state is deactivated.
* `state:*`: Subscribes to all of the above `state:` namespace events.
* `modifier:*`: Subscribes to all of the above `modifier:` namespace events.

#### `Transformer`

* `update_elements`: Fired when the content of `transformer.elements` or `transformer.selection` changes.

<br/>

Expand Down
83 changes: 70 additions & 13 deletions README_KR.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ PATCH MAP은 PATCH μ„œλΉ„μŠ€μ˜ μš”κ΅¬ 사항을 μΆ©μ‘±μ‹œν‚€κΈ° μœ„ν•΄ `pixi.js
- [canUndo()](#canundo)
- [canRedo()](#canredo)
- [clear()](#clear)
- [subscribe(listener)](#subscribelistener)
- [πŸ“’ μ‚¬μš© κ°€λŠ₯ν•œ 전체 이벀트 λͺ©λ‘](#-μ‚¬μš©-κ°€λŠ₯ν•œ-전체-이벀트-λͺ©λ‘)
- [πŸ§‘β€πŸ’» 개발](#-개발)
- [개발 ν™˜κ²½ μ„ΈνŒ…](#개발-ν™˜κ²½-μ„ΈνŒ…)
- [VSCode 톡합](#vscode-톡합)
Expand All @@ -48,19 +48,24 @@ PATCH MAP은 PATCH μ„œλΉ„μŠ€μ˜ μš”κ΅¬ 사항을 μΆ©μ‘±μ‹œν‚€κΈ° μœ„ν•΄ `pixi.js
## πŸš€ μ‹œμž‘ν•˜κΈ°

### μ„€μΉ˜

#### NPM

```sh
npm install @conalog/patch-map
```

#### CDN

```html
<script src="https://cdn.jsdelivr.net/npm/pixi.js@latest/dist/pixi.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/@conalog/patch-map@latest/dist/index.umd.js"></script>
```

### 기본 예제

μ‹œμž‘ν•˜λŠ” 데 도움이 λ˜λŠ” κ°„λ‹¨ν•œ μ˜ˆμ œμž…λ‹ˆλ‹€: [예제](https://codesandbox.io/p/sandbox/yvjrpx)

```js
import { Patchmap } from '@conalog/patch-map';

Expand Down Expand Up @@ -109,6 +114,7 @@ patchmap.draw(data);
## Patchmap

### `init(el, options)`

PATCH MAP을 μ΄ˆκΈ°ν™”ν•˜λŠ” κ²ƒμœΌλ‘œ, 1번만 μ‹€ν–‰λ˜μ–΄μ•Ό ν•©λ‹ˆλ‹€.

```js
Expand All @@ -124,6 +130,7 @@ await patchmap.init(el, {
```

#### **Options**

λ Œλ”λ§ λ™μž‘μ„ μ‚¬μš©μž μ •μ˜ν•˜λ €λ©΄ λ‹€μŒ μ˜΅μ…˜μ„ μ‚¬μš©ν•˜μ„Έμš”:

- `app`
Expand Down Expand Up @@ -395,6 +402,7 @@ patchmap.fit(['item-1', 'item-2'])
<br/>

### `selector(path)`

[jsonpath](https://github.com/JSONPath-Plus/JSONPath) 문법에 λ”°λ₯Έ 객체 νƒμƒ‰κΈ°μž…λ‹ˆλ‹€.

```js
Expand Down Expand Up @@ -559,6 +567,22 @@ patchmap.transformer.elements = [selectedObject];
patchmap.transformer.elements = [];
```

#### transformer.selection

`Transformer`의 선택 μƒνƒœλ₯Ό μ „λ¬Έμ μœΌλ‘œ κ΄€λ¦¬ν•˜λŠ” `SelectionModel` μΈμŠ€ν„΄μŠ€μž…λ‹ˆλ‹€. 이λ₯Ό 톡해 μ„ νƒλœ μš”μ†Œλ₯Ό ν”„λ‘œκ·Έλž˜λ° λ°©μ‹μœΌλ‘œ μ œμ–΄ν•  수 μžˆμŠ΅λ‹ˆλ‹€.

```js
// 선택 μš”μ†Œ μΆ”κ°€, 제거, ꡐ체
transformer.selection.add(item1);
transformer.selection.remove(item1);
transformer.selection.set([item2]);

// 선택 λ³€κ²½ 이벀트 ꡬ독
transformer.on('update_elements', ({ current, added, removed }) => {
console.log('ν˜„μž¬ 선택:', current);
});
```

<br/>

## undoRedoManager
Expand All @@ -582,31 +606,61 @@ undoRedoManager.redo();
```

#### `canUndo()`

μ‹€ν–‰ μ·¨μ†Œκ°€ κ°€λŠ₯ν•œμ§€ μ—¬λΆ€λ₯Ό λ°˜ν™˜ν•©λ‹ˆλ‹€.

#### `canRedo()`

μž¬μ‹€ν–‰μ΄ κ°€λŠ₯ν•œμ§€ μ—¬λΆ€λ₯Ό λ°˜ν™˜ν•©λ‹ˆλ‹€.

#### `clear()`

λͺ¨λ“  λͺ…λ Ή 기둝을 μ΄ˆκΈ°ν™”ν•©λ‹ˆλ‹€.

#### `subscribe(listener)`
λ¦¬μŠ€λ„ˆλ₯Ό κ΅¬λ…ν•˜μ—¬ λͺ…λ Ή κ΄€λ ¨ λ³€κ²½ 사항이 μ΄λ£¨μ–΄μ‘Œμ„ λ•Œ, ν•΄λ‹Ή λ¦¬μŠ€λ„ˆκ°€ ν˜ΈμΆœλ©λ‹ˆλ‹€. λ°˜ν™˜λœ ν•¨μˆ˜λ₯Ό ν˜ΈμΆœν•˜μ—¬ ꡬ독을 μ·¨μ†Œν•  수 μžˆμŠ΅λ‹ˆλ‹€.
```js
let canUndo = false;
let canRedo = false;
<br/>

const unsubscribe = undoRedoManager.subscribe((manager) => {
canUndo = manager.canUndo();
canRedo = manager.canRedo();
});
```
## πŸ“’ μ‚¬μš© κ°€λŠ₯ν•œ 전체 이벀트 λͺ©λ‘

이번 μ—…λ°μ΄νŠΈλ‘œ 인해 ꡬ독 κ°€λŠ₯ν•œ 이벀트 λͺ©λ‘μž…λ‹ˆλ‹€. `.on(eventName, callback)`을 μ‚¬μš©ν•˜μ—¬ ꡬ독할 수 μžˆμŠ΅λ‹ˆλ‹€.

#### `Patchmap`

* `patchmap:initialized`: `patchmap.init()`이 μ„±κ³΅μ μœΌλ‘œ μ™„λ£Œλ˜μ—ˆμ„ λ•Œ λ°œμƒν•©λ‹ˆλ‹€.
* `patchmap:draw`: `patchmap.draw()`λ₯Ό 톡해 μƒˆλ‘œμš΄ 데이터가 λ Œλ”λ§λ˜μ—ˆμ„ λ•Œ λ°œμƒν•©λ‹ˆλ‹€.
* `patchmap:updated`: `patchmap.update()`λ₯Ό 톡해 μš”μ†Œκ°€ μ—…λ°μ΄νŠΈλ˜μ—ˆμ„ λ•Œ λ°œμƒν•©λ‹ˆλ‹€.
* `patchmap:destroyed`: `patchmap.destroy()`κ°€ ν˜ΈμΆœλ˜μ–΄ μΈμŠ€ν„΄μŠ€κ°€ 파괴될 λ•Œ λ°œμƒν•©λ‹ˆλ‹€.

#### `UndoRedoManager`

* `history:executed`: μƒˆλ‘œμš΄ μ»€λ§¨λ“œκ°€ μ‹€ν–‰ μŠ€νƒμ— μΆ”κ°€λ˜μ—ˆμ„ λ•Œ λ°œμƒν•©λ‹ˆλ‹€.
* `history:undone`: `undo()`κ°€ μ‹€ν–‰λ˜μ—ˆμ„ λ•Œ λ°œμƒν•©λ‹ˆλ‹€.
* `history:redone`: `redo()`κ°€ μ‹€ν–‰λ˜μ—ˆμ„ λ•Œ λ°œμƒν•©λ‹ˆλ‹€.
* `history:cleared`: `clear()`둜 λͺ¨λ“  νžˆμŠ€ν† λ¦¬κ°€ μ‚­μ œλ˜μ—ˆμ„ λ•Œ λ°œμƒν•©λ‹ˆλ‹€.
* `history:destroyed`: `destroy()`κ°€ ν˜ΈμΆœλ˜μ—ˆμ„ λ•Œ λ°œμƒν•©λ‹ˆλ‹€.
* `history:*`: μœ„μ˜ λͺ¨λ“  `history:` λ„€μž„μŠ€νŽ˜μ΄μŠ€ 이벀트λ₯Ό κ΅¬λ…ν•©λ‹ˆλ‹€.

#### `StateManager`

* `state:pushed`: μƒˆλ‘œμš΄ μƒνƒœκ°€ μŠ€νƒμ— μΆ”κ°€λ˜μ—ˆμ„ λ•Œ λ°œμƒν•©λ‹ˆλ‹€.
* `state:popped`: ν˜„μž¬ μƒνƒœκ°€ μŠ€νƒμ—μ„œ μ œκ±°λ˜μ—ˆμ„ λ•Œ λ°œμƒν•©λ‹ˆλ‹€.
* `state:set`: `setState()`λ₯Ό 톡해 μƒνƒœ μŠ€νƒμ΄ λ¦¬μ…‹λ˜κ³  μƒˆλ‘œμš΄ μƒνƒœκ°€ μ„€μ •λ˜μ—ˆμ„ λ•Œ λ°œμƒν•©λ‹ˆλ‹€.
* `state:reset`: `resetState()`둜 λͺ¨λ“  μƒνƒœκ°€ μ œκ±°λ˜μ—ˆμ„ λ•Œ λ°œμƒν•©λ‹ˆλ‹€.
* `state:destroyed`: `destroy()`κ°€ ν˜ΈμΆœλ˜μ—ˆμ„ λ•Œ λ°œμƒν•©λ‹ˆλ‹€.
* `modifier:activated`: μˆ˜μ •μž(Modifier) μƒνƒœκ°€ ν™œμ„±ν™”λ˜μ—ˆμ„ λ•Œ λ°œμƒν•©λ‹ˆλ‹€.
* `modifier:deactivated`: μˆ˜μ •μž(Modifier) μƒνƒœκ°€ λΉ„ν™œμ„±ν™”λ˜μ—ˆμ„ λ•Œ λ°œμƒν•©λ‹ˆλ‹€.
* `state:*`: μœ„μ˜ λͺ¨λ“  `state:` λ„€μž„μŠ€νŽ˜μ΄μŠ€ 이벀트λ₯Ό κ΅¬λ…ν•©λ‹ˆλ‹€.
* `modifier:*`: μœ„μ˜ λͺ¨λ“  `modifier:` λ„€μž„μŠ€νŽ˜μ΄μŠ€ 이벀트λ₯Ό κ΅¬λ…ν•©λ‹ˆλ‹€.

#### `Transformer`

* `update_elements`: `transformer.elements` λ˜λŠ” `transformer.selection`의 λ‚΄μš©μ΄ 변경될 λ•Œ λ°œμƒν•©λ‹ˆλ‹€.

<br/>

## πŸ§‘β€πŸ’» 개발

### 개발 ν™˜κ²½ μ„ΈνŒ…

```sh
npm install # μ˜μ‘΄μ„± μ„€μΉ˜
npm run dev # 개발 μ„œλ²„ μ‹œμž‘
Expand All @@ -615,9 +669,12 @@ npm run lint:fix # μ½”λ“œ ν¬λ§·νŒ… μˆ˜μ •
```

### VSCode 톡합

μΌκ΄€λœ μ½”λ“œ ν¬λ§·νŒ…μ„ μœ„ν•΄ Biome을 μ„€μ •ν•˜μ„Έμš”.
1. [Biome ν™•μž₯](https://biomejs.dev/reference/vscode/)을 μ„€μΉ˜ν•˜μ„Έμš”.
2. VSCode 섀정을 μ—…λ°μ΄νŠΈν•˜μ„Έμš”:

1. [Biome ν™•μž₯](https://biomejs.dev/reference/vscode/)을 μ„€μΉ˜ν•˜μ„Έμš”.
2. VSCode 섀정을 μ—…λ°μ΄νŠΈν•˜μ„Έμš”:

```json
{
"editor.formatOnSave": true,
Expand Down
Loading