@yorab/react-paint 0.11.0 → 0.11.1

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.
package/README.md CHANGED
@@ -82,7 +82,7 @@ const AdvancedUsage = () => {
82
82
  }
83
83
 
84
84
  useEffect(() => {
85
- const onDataChanged = (data: StateData) => {
85
+ const onDataChanged = (data: StateData, source: 'user' | 'remote') => {
86
86
  setShapes(data.shapes)
87
87
  }
88
88
  registerEvent('dataChanged', onDataChanged)
@@ -126,12 +126,32 @@ you will find other usages in <a href="https://github.com/YoRab/react-paint-edit
126
126
  | :--- | :--- | :--- |
127
127
  | `canvasProps` | `object` | Set of properties to forward to Canvas component |
128
128
  | `editorProps` | `object` | Set of properties to forward to Editor component |
129
- | `registerEvent` | `(event: "dataChanged", listener: (data: StateData) => void) => void` | registerEvent is used to register a listener for special events triggered by react-paint. The only currently available event is `dataChanged` |
130
- | `unregisterEvent` | `(event: "dataChanged", listener?: ((data: StateData) => void) \| undefined) => void` | unregisterEvent is used to unregister a listener previously registered. Omitting listener will result in unregistering every listeners for the the given event |
129
+ | `registerEvent` | `(event: "dataChanged", listener: (data: StateData, source: 'user' \| 'remote') => void) => void` | registerEvent is used to register a listener for special events triggered by react-paint. The only currently available event is `dataChanged`. `source` indicates the origin of the state update |
130
+ | `unregisterEvent` | `(event: "dataChanged", listener?: ((data: StateData, source: 'user' \| 'remote') => void) \| undefined) => void` | unregisterEvent is used to unregister a listener previously registered. Omitting listener will result in unregistering every listeners for the the given event |
131
131
  | `resetCanvas` | `(shapes: DrawableShape[], clearHistory?: boolean) => Promise<void>` | reset canvas with the given shapes. use `[]` or `undefined` to clear the canvas. Set `false` to `clearHistory` to prevent history stack to be cleared |
132
132
  | `getCurrentImage` | `() => string \| undefined` | Returns a data URL containing the content of the current canvas as a PNG image, or undefined if an error occured |
133
133
  | `getCurrentData` | `() => StateData` | Returns the current state of the canvas |
134
134
 
135
+ #### `OptionalOptions`
136
+
137
+ | Parameter | Type | Description | Default value |
138
+ | :--- | :--- | :--- | :--- |
139
+ | `layersManipulation` | `boolean` | *Optional*. Show panel to manipulate layers | `true` |
140
+ | `grid` | `number` | *Optional*. Size in px for grid cells. Set to 0 to hide grid | `0` |
141
+ | `canGrow` | `boolean` | *Optional*. Allow canvas to upscale and grow to fit container | `false` |
142
+ | `canShrink` | `boolean` | *Optional*. Allow canvas to downscale and shrink to fit container | `true` |
143
+ | `withExport` | `boolean` | *Optional*. Show button to manually export to PNG | `true` |
144
+ | `withLoadAndSave` | `boolean` | *Optional*.Show button to manually save or load data | `true` |
145
+ | `withUploadPicture` | `boolean` | *Optional*. Show button to add picture shape stored in base64 | `true` |
146
+ | `withUrlPicture` | `boolean` | *Optional*.Show button to add picture shape with only the url stored. Need connectivity to be displayed | `false` |
147
+ | `withFrameSelection` | `boolean` | *Optional*.Enable frame selection. **Currently, does not support multi shapes selection** | `false` |
148
+ | `withSkeleton` | `boolean` | *Optional*. Display skeleton when hovering shape | `false` |
149
+ | `clearCallback` | `'empty' \| 'defaultShapes' \| (() => DrawableShape[])` | *Optional*. Set clear button behavior. `empty` clear all shapes, `defaultShapes` uses shapes given in props. It is also possible to set a function returning an array of shapes | `empty` |
150
+ | `brushAlgo` | `'simple' \| 'quadratic'` | *Optional*. Choose which algorithm to display brush shape. `simple` displays path as is, `quadratic` uses quadratic bézier curves | `simple` |
151
+ | `isBrushShapeDoneOnMouseUp` | `boolean` | *Optional*. Choose whether drawing brush shape after releasing mouse should create a new shape or not | `true` |
152
+ | `canvasSelectionPadding` | `boolean` | *Optional*. Padding between shape and selection frame | `0` |
153
+
154
+
135
155
  #### Canvas
136
156
 
137
157
  ##### Parameters
@@ -141,7 +161,7 @@ you will find other usages in <a href="https://github.com/YoRab/react-paint-edit
141
161
  | `canvasProps` | `object` | **Required**. Set of properties coming from useReactPaint | |
142
162
  | `className` | `string` | *Optional*. Classname for canvas parent node | `undefined` |
143
163
  | `style` | `CSSProperties` | *Optional*. css properties to inject to canvas parent node | `undefined` |
144
- | `options` | `{canvasBackgroundColor?: string}` | *Optional*. Set of properties to use to customize canvas style | `{canvasBackgroundColor: 'white'}` |
164
+ | `options` | `{canvasBackgroundColor?: string; canvasSelectionColor?: string; canvasSelectionWidth?: number}` | *Optional*. Set of properties to use to customize canvas style | `{canvasBackgroundColor: 'white'; canvasSelectionColor: 'blue'; canvasSelectionWidth: 2}` |
145
165
 
146
166
 
147
167
  #### Editor
@@ -160,8 +180,6 @@ you will find other usages in <a href="https://github.com/YoRab/react-paint-edit
160
180
 
161
181
  #### `DrawableShape`
162
182
  #### `StateData`
163
- #### `OptionalOptions`
164
-
165
183
 
166
184
  ## Changelog
167
185
  https://github.com/YoRab/react-paint-editor/blob/main/Changelog.md
@@ -7,6 +7,7 @@ export declare const SELECTIONCANVAS_CLASSNAME = "react-paint-canvas-selectionca
7
7
  export type BrushAlgo = 'simple' | 'quadratic';
8
8
  export type UtilsSettings = {
9
9
  brushAlgo: BrushAlgo;
10
+ isBrushShapeDoneOnMouseUp: boolean;
10
11
  gridGap: number;
11
12
  canvasOffset: Point;
12
13
  canvasSize: {
@@ -30,15 +31,14 @@ type AppOptionsType = {
30
31
  withSkeleton: boolean;
31
32
  clearCallback: 'empty' | 'defaultShapes' | (() => DrawableShape[]);
32
33
  brushAlgo: BrushAlgo;
33
- selection: {
34
- canvasSelectionColor: string;
35
- canvasSelectionWidth: number;
36
- canvasSelectionPadding: number;
37
- };
34
+ isBrushShapeDoneOnMouseUp: boolean;
35
+ canvasSelectionPadding: number;
38
36
  };
39
37
  export type OptionalOptions = RecursivePartial<AppOptionsType>;
40
38
  export declare const DEFAULT_OPTIONS: AppOptionsType;
41
39
  export declare const DEFAULT_CANVAS_OPTIONS: {
42
40
  canvasBackgroundColor: string;
41
+ canvasSelectionColor: string;
42
+ canvasSelectionWidth: number;
43
43
  };
44
44
  export {};
@@ -10,7 +10,7 @@ type UseReactPaintProps = {
10
10
  disabled?: boolean;
11
11
  options?: OptionalOptions;
12
12
  };
13
- declare const useReactPaint: ({ width, height, shapes: shapesFromProps, mode, disabled, options }: UseReactPaintProps) => {
13
+ declare const useReactPaint: ({ width, height, shapes: defaultShapes, mode, disabled, options }: UseReactPaintProps) => {
14
14
  editorProps: {
15
15
  shapesRef: import("react").MutableRefObject<ShapeEntity[]>;
16
16
  addPictureShape: (fileOrUrl: string | File, maxWidth?: number, maxHeight?: number) => Promise<ShapeEntity<"picture">>;
@@ -53,13 +53,6 @@ declare const useReactPaint: ({ width, height, shapes: shapesFromProps, mode, di
53
53
  clearCanvas: () => void;
54
54
  settings: UtilsSettings;
55
55
  canvas: {
56
- selection: {
57
- canvasSelectionColor: string;
58
- canvasSelectionWidth: number;
59
- canvasSelectionPadding: number;
60
- };
61
- withSkeleton: boolean;
62
- withFrameSelection: boolean;
63
56
  canGrow: boolean;
64
57
  canShrink: boolean;
65
58
  layersManipulation: boolean;
@@ -67,7 +60,6 @@ declare const useReactPaint: ({ width, height, shapes: shapesFromProps, mode, di
67
60
  withLoadAndSave: boolean;
68
61
  withUploadPicture: boolean;
69
62
  withUrlPicture: boolean;
70
- clearCallback: "empty" | "defaultShapes" | (() => DrawableShape[]);
71
63
  };
72
64
  };
73
65
  canvasProps: {
@@ -111,19 +103,15 @@ declare const useReactPaint: ({ width, height, shapes: shapesFromProps, mode, di
111
103
  isEditMode: boolean;
112
104
  isDisabled: boolean;
113
105
  canvas: {
114
- selection: {
115
- canvasSelectionColor: string;
116
- canvasSelectionWidth: number;
117
- };
118
106
  withSkeleton: boolean;
119
107
  withFrameSelection: boolean;
120
108
  canGrow: boolean;
121
109
  canShrink: boolean;
122
110
  };
123
111
  };
124
- registerEvent: (event: "dataChanged", fn: (data: StateData) => void) => void;
125
- unregisterEvent: (event: "dataChanged", fn?: ((data: StateData) => void) | undefined) => void;
126
- resetCanvas: (json: DrawableShape[], clearHistory?: boolean) => Promise<void>;
112
+ registerEvent: (event: "dataChanged", fn: (data: StateData, source: "user" | "remote") => void) => void;
113
+ unregisterEvent: (event: "dataChanged", fn?: ((data: StateData, source: "user" | "remote") => void) | undefined) => void;
114
+ resetCanvas: (json?: DrawableShape[], clearHistory?: boolean) => void;
127
115
  getCurrentImage: () => string | undefined;
128
116
  getCurrentData: () => StateData;
129
117
  };
@@ -2,8 +2,8 @@
2
2
  import { type UtilsSettings } from './../../canvas/constants/app';
3
3
  import type { StateData, Point, ShapeEntity } from './../../common/types/Shapes';
4
4
  declare const useShapes: (settings: UtilsSettings) => {
5
- registerEvent: (event: 'dataChanged', fn: (data: StateData) => void) => void;
6
- unregisterEvent: (event: 'dataChanged', fn?: (data: StateData) => void) => void;
5
+ registerEvent: (event: 'dataChanged', fn: (data: StateData, source: 'user' | 'remote') => void) => void;
6
+ unregisterEvent: (event: 'dataChanged', fn?: (data: StateData, source: 'user' | 'remote') => void) => void;
7
7
  shapesRef: import("react").MutableRefObject<ShapeEntity[]>;
8
8
  selectedShape: ShapeEntity | undefined;
9
9
  hoveredShape: ShapeEntity | undefined;
@@ -22,7 +22,10 @@ declare const useShapes: (settings: UtilsSettings) => {
22
22
  updateShape: (updatedShape: ShapeEntity, withSave?: boolean) => void;
23
23
  backwardShape: () => void;
24
24
  forwardShape: () => void;
25
- clearShapes: (shapesToInit?: ShapeEntity[], clearHistory?: boolean) => void;
25
+ clearShapes: (shapesToInit: ShapeEntity[], options: {
26
+ clearHistory: boolean;
27
+ source: 'user' | 'remote';
28
+ }) => void;
26
29
  canGoBackward: boolean;
27
30
  canGoForward: boolean;
28
31
  canClear: boolean;
@@ -7,6 +7,8 @@ type AppProps = {
7
7
  style?: CSSProperties;
8
8
  options?: {
9
9
  canvasBackgroundColor?: string;
10
+ canvasSelectionColor?: string;
11
+ canvasSelectionWidth?: number;
10
12
  };
11
13
  };
12
14
  declare const App: ({ options, className, style, canvasProps }: AppProps) => import("react/jsx-runtime").JSX.Element;