@gridui/resizable 1.0.3 → 1.0.4

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/dist/index.js CHANGED
@@ -24,10 +24,11 @@ var keyboardSize = (key, size, step, horizontal, reverse, min, max) => {
24
24
  };
25
25
 
26
26
  // src/resizable/resizable.tsx
27
- import { isComposingKeyEvent, listenForDragCancellation } from "@gridui/interaction";
27
+ import { isComposingKeyEvent } from "@gridui/interaction";
28
28
  import { useInteractionOutline } from "@gridui/overlay";
29
+ import { usePointerDrag } from "@gridui/react-utils";
29
30
  import { cn } from "@gridui/style-utils";
30
- import { useEffect, useId, useLayoutEffect, useRef, useState } from "react";
31
+ import { useId, useLayoutEffect, useState } from "react";
31
32
  import { jsx, jsxs } from "react/jsx-runtime";
32
33
  var Resizable = (props) => {
33
34
  const {
@@ -50,8 +51,6 @@ var Resizable = (props) => {
50
51
  local,
51
52
  setLocal
52
53
  ] = useState(defaultSize);
53
- const drag = useRef(null);
54
- const separator = useRef(null);
55
54
  const firstRef = useInteractionOutline({});
56
55
  const secondRef = useInteractionOutline({});
57
56
  const firstId = useId();
@@ -72,13 +71,7 @@ var Resizable = (props) => {
72
71
  onSizeChange?.(next);
73
72
  }
74
73
  };
75
- const cancel = () => {
76
- const active = drag.current;
77
- if (!active) {
78
- return;
79
- }
80
- drag.current = null;
81
- active.cleanup();
74
+ const drag = usePointerDrag((active) => {
82
75
  const next = constrainSize(active.size, minSize, maxSize);
83
76
  if (size === void 0) {
84
77
  setLocal(next);
@@ -86,20 +79,11 @@ var Resizable = (props) => {
86
79
  if (next !== current) {
87
80
  onSizeChange?.(next);
88
81
  }
89
- if (active.element.hasPointerCapture(active.pointerId)) {
90
- active.element.releasePointerCapture(active.pointerId);
91
- }
92
- };
93
- const cancelRef = useRef(cancel);
94
- cancelRef.current = cancel;
95
- useEffect(() => {
96
- return () => {
97
- cancelRef.current();
98
- };
99
- }, []);
82
+ });
100
83
  useLayoutEffect(() => {
101
- if (disabled || drag.current && drag.current.horizontal !== horizontal) {
102
- cancel();
84
+ const active = drag.get();
85
+ if (disabled || active && active.horizontal !== horizontal) {
86
+ drag.cancel();
103
87
  }
104
88
  });
105
89
  const tracks = `minmax(0, ${current}fr) var(--gridui-resizable-handle-size, 12px) minmax(0, ${100 - current}fr)`;
@@ -126,7 +110,6 @@ var Resizable = (props) => {
126
110
  /* @__PURE__ */ jsx(
127
111
  "div",
128
112
  {
129
- ref: separator,
130
113
  role: "separator",
131
114
  "aria-label": label,
132
115
  "aria-controls": `${firstId} ${secondId}`,
@@ -150,7 +133,7 @@ var Resizable = (props) => {
150
133
  }
151
134
  },
152
135
  onPointerDown: (event) => {
153
- if (disabled || event.button !== 0 || !event.isPrimary || drag.current) {
136
+ if (disabled) {
154
137
  return;
155
138
  }
156
139
  const handle = event.currentTarget;
@@ -159,46 +142,35 @@ var Resizable = (props) => {
159
142
  return;
160
143
  }
161
144
  const handleBounds = handle.getBoundingClientRect();
162
- drag.current = {
163
- pointerId: event.pointerId,
145
+ const started = drag.start(event, {
164
146
  start: horizontal ? event.clientX : event.clientY,
165
147
  size: current,
166
148
  extent: horizontal ? bounds.width - handleBounds.width : bounds.height - handleBounds.height,
167
149
  reverse: horizontal && getComputedStyle(handle).direction === "rtl",
168
- horizontal,
169
- element: handle,
170
- cleanup: listenForDragCancellation(handle, () => {
171
- cancelRef.current();
172
- })
173
- };
174
- handle.focus();
175
- handle.setPointerCapture(event.pointerId);
176
- event.preventDefault();
150
+ horizontal
151
+ });
152
+ if (started) {
153
+ handle.focus();
154
+ event.preventDefault();
155
+ }
177
156
  },
178
157
  onPointerMove: (event) => {
179
- const active = drag.current;
180
- if (!active || active.pointerId !== event.pointerId) {
158
+ const active = drag.get(event.pointerId);
159
+ if (!active) {
181
160
  return;
182
161
  }
183
162
  const coordinate = horizontal ? event.clientX : event.clientY;
184
163
  update(pointerSize(active.size, coordinate - active.start, active.extent, active.reverse, minSize, maxSize));
185
164
  },
186
165
  onPointerUp: (event) => {
187
- if (drag.current?.pointerId === event.pointerId) {
188
- const active = drag.current;
189
- drag.current = null;
190
- active.cleanup();
191
- if (event.currentTarget.hasPointerCapture(event.pointerId)) {
192
- event.currentTarget.releasePointerCapture(event.pointerId);
193
- }
194
- }
166
+ drag.finish(event.pointerId);
195
167
  },
196
168
  onPointerCancel: (event) => {
197
- if (drag.current?.pointerId === event.pointerId) {
198
- cancel();
199
- }
169
+ drag.cancel(event.pointerId);
200
170
  },
201
- onLostPointerCapture: cancel
171
+ onLostPointerCapture: (event) => {
172
+ drag.cancel(event.pointerId);
173
+ }
202
174
  }
203
175
  ),
204
176
  /* @__PURE__ */ jsx(
package/dist/index.js.map CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../src/resizable/size.ts", "../src/resizable/resizable.tsx"],
4
- "sourcesContent": ["/**\n * @author WMXPY\n * @package Resizable\n * @namespace Resizable\n * @description Size\n */\n\nexport const constrainSize = (size: number, min: number, max: number): number => {\n if (!Number.isFinite(size) || !Number.isFinite(min) || !Number.isFinite(max) || min < 0 || max > 100 || min > max) {\n throw new RangeError(\"Resizable requires finite percentages and 0 <= minSize <= maxSize <= 100.\");\n }\n return Math.min(max, Math.max(min, size));\n};\n\nexport const pointerSize = (size: number, delta: number, extent: number, reverse: boolean, min: number, max: number): number => {\n return constrainSize(extent > 0 ? size + delta / extent * 100 * (reverse ? -1 : 1) : size, min, max);\n};\n\nexport const keyboardSize = (key: string, size: number, step: number, horizontal: boolean, reverse: boolean, min: number, max: number): number | null => {\n if (key === \"Home\") {\n return min;\n }\n if (key === \"End\") {\n return max;\n }\n const positive = horizontal ? \"ArrowRight\" : \"ArrowDown\";\n const negative = horizontal ? \"ArrowLeft\" : \"ArrowUp\";\n if (key !== positive && key !== negative) {\n return null;\n }\n return constrainSize(size + (key === positive ? 1 : -1) * (horizontal && reverse ? -1 : 1) * step, min, max);\n};\n", "/**\n * @author WMXPY\n * @package Resizable\n * @namespace Resizable\n * @description Resizable\n */\n\nimport { constrainSize, keyboardSize, pointerSize } from \"./size\";\nimport { isComposingKeyEvent, listenForDragCancellation } from \"@gridui/interaction\";\nimport { useInteractionOutline } from \"@gridui/overlay\";\nimport { cn } from \"@gridui/style-utils\";\nimport { type ComponentPropsWithRef, type FC, type ReactNode, useEffect, useId, useLayoutEffect, useRef, useState } from \"react\";\n\nexport type ResizableProps = Omit<ComponentPropsWithRef<\"div\">, \"children\" | \"onChange\"> & {\n readonly first: ReactNode;\n readonly second: ReactNode;\n readonly label: string;\n readonly orientation?: \"horizontal\" | \"vertical\";\n readonly size?: number;\n readonly defaultSize?: number;\n readonly minSize?: number;\n readonly maxSize?: number;\n readonly step?: number;\n readonly disabled?: boolean;\n readonly onSizeChange?: (size: number) => void;\n};\n\ntype Drag = {\n readonly pointerId: number;\n readonly start: number;\n readonly size: number;\n readonly extent: number;\n readonly reverse: boolean;\n readonly horizontal: boolean;\n readonly element: HTMLDivElement;\n readonly cleanup: () => void;\n};\n\nexport const Resizable: FC<ResizableProps> = (props: ResizableProps) => {\n const { first, second, label, orientation = \"horizontal\", size, defaultSize = 50, minSize = 10, maxSize = 90,\n step = 1, disabled = false, onSizeChange, className, style, ...restProps } = props;\n const [\n local,\n setLocal,\n ] = useState(defaultSize);\n const drag = useRef<Drag | null>(null);\n const separator = useRef<HTMLDivElement>(null);\n const firstRef = useInteractionOutline<HTMLDivElement>({});\n const secondRef = useInteractionOutline<HTMLDivElement>({});\n const firstId = useId();\n const secondId = useId();\n const current = constrainSize(size ?? local, minSize, maxSize);\n if (!Number.isFinite(step) || step <= 0) {\n throw new RangeError(\"Resizable step must be a positive finite percentage.\");\n }\n const horizontal = orientation === \"horizontal\";\n const update = (next: number) => {\n if (disabled) {\n return;\n }\n if (size === undefined) {\n setLocal(next);\n }\n if (next !== current) {\n onSizeChange?.(next);\n }\n };\n const cancel = () => {\n const active = drag.current;\n if (!active) {\n return;\n }\n drag.current = null;\n active.cleanup();\n const next = constrainSize(active.size, minSize, maxSize);\n if (size === undefined) {\n setLocal(next);\n }\n if (next !== current) {\n onSizeChange?.(next);\n }\n if (active.element.hasPointerCapture(active.pointerId)) {\n active.element.releasePointerCapture(active.pointerId);\n }\n };\n const cancelRef = useRef(cancel);\n cancelRef.current = cancel;\n useEffect(() => {\n return () => {\n cancelRef.current();\n };\n }, []);\n useLayoutEffect(() => {\n if (disabled || (drag.current && drag.current.horizontal !== horizontal)) {\n cancel();\n }\n });\n const tracks = `minmax(0, ${current}fr) var(--gridui-resizable-handle-size, 12px) minmax(0, ${100 - current}fr)`;\n return (<div\n {...restProps}\n className={cn(\"gridui-resizable\", className)}\n data-orientation={orientation}\n style={{\n ...style,\n ...(horizontal ? { gridTemplateColumns: tracks } : { gridTemplateRows: tracks }),\n }}\n >\n <div\n id={firstId}\n ref={firstRef}\n className=\"gridui-resizable-panel\"\n >\n {first}\n </div>\n <div\n ref={separator}\n role=\"separator\"\n aria-label={label}\n aria-controls={`${firstId} ${secondId}`}\n aria-orientation={horizontal ? \"vertical\" : \"horizontal\"}\n aria-valuemin={minSize}\n aria-valuemax={maxSize}\n aria-valuenow={Math.round(current * 100) / 100}\n aria-valuetext={`${Math.round(current)}%`}\n aria-disabled={disabled || undefined}\n tabIndex={disabled ? -1 : 0}\n className=\"gridui-resizable-handle\"\n onKeyDown={(event) => {\n if (disabled || event.defaultPrevented || isComposingKeyEvent(event.nativeEvent)) {\n return;\n }\n const reverse = getComputedStyle(event.currentTarget).direction === \"rtl\";\n const next = keyboardSize(event.key, current, step * (event.shiftKey ? 10 : 1), horizontal, reverse, minSize, maxSize);\n if (next !== null) {\n event.preventDefault();\n update(next);\n }\n }}\n onPointerDown={(event) => {\n if (disabled || event.button !== 0 || !event.isPrimary || drag.current) {\n return;\n }\n const handle = event.currentTarget;\n const bounds = handle.parentElement?.getBoundingClientRect();\n if (!bounds) {\n return;\n }\n const handleBounds = handle.getBoundingClientRect();\n drag.current = {\n pointerId: event.pointerId,\n start: horizontal ? event.clientX : event.clientY,\n size: current,\n extent: horizontal ? bounds.width - handleBounds.width : bounds.height - handleBounds.height,\n reverse: horizontal && getComputedStyle(handle).direction === \"rtl\",\n horizontal,\n element: handle,\n cleanup: listenForDragCancellation(handle, () => {\n cancelRef.current();\n }),\n };\n handle.focus();\n handle.setPointerCapture(event.pointerId);\n event.preventDefault();\n }}\n onPointerMove={(event) => {\n const active = drag.current;\n if (!active || active.pointerId !== event.pointerId) {\n return;\n }\n const coordinate = horizontal ? event.clientX : event.clientY;\n update(pointerSize(active.size, coordinate - active.start, active.extent, active.reverse, minSize, maxSize));\n }}\n onPointerUp={(event) => {\n if (drag.current?.pointerId === event.pointerId) {\n const active = drag.current;\n drag.current = null;\n active.cleanup();\n if (event.currentTarget.hasPointerCapture(event.pointerId)) {\n event.currentTarget.releasePointerCapture(event.pointerId);\n }\n }\n }}\n onPointerCancel={(event) => {\n if (drag.current?.pointerId === event.pointerId) {\n cancel();\n }\n }}\n onLostPointerCapture={cancel}\n />\n <div\n id={secondId}\n ref={secondRef}\n className=\"gridui-resizable-panel\"\n >\n {second}\n </div>\n </div>);\n};\n"],
5
- "mappings": ";AAOO,IAAM,gBAAgB,CAAC,MAAc,KAAa,QAAwB;AAC7E,MAAI,CAAC,OAAO,SAAS,IAAI,KAAK,CAAC,OAAO,SAAS,GAAG,KAAK,CAAC,OAAO,SAAS,GAAG,KAAK,MAAM,KAAK,MAAM,OAAO,MAAM,KAAK;AAC/G,UAAM,IAAI,WAAW,2EAA2E;AAAA,EACpG;AACA,SAAO,KAAK,IAAI,KAAK,KAAK,IAAI,KAAK,IAAI,CAAC;AAC5C;AAEO,IAAM,cAAc,CAAC,MAAc,OAAe,QAAgB,SAAkB,KAAa,QAAwB;AAC5H,SAAO,cAAc,SAAS,IAAI,OAAO,QAAQ,SAAS,OAAO,UAAU,KAAK,KAAK,MAAM,KAAK,GAAG;AACvG;AAEO,IAAM,eAAe,CAAC,KAAa,MAAc,MAAc,YAAqB,SAAkB,KA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Q;AAAA,gBACtB,CAAC;AAAA,cACL;AACA,qBAAO,MAAM;AACb,qBAAO,kBAAkB,MAAM,SAAS;AACxC,oBAAM,eAAe;AAAA,YACzB;AAAA,YACA,eAAe,CAAC,UAAU;AACtB,oBAAM,SAAS,KAAK;AACpB,kBAAI,CAAC,UAAU,OAAO,cAAc,MAAM,WAAW;AACjD;AAAA,cACJ;AACA,oBAAM,aAAa,aAAa,MAAM,UAAU,MAAM;AACtD,qBAAO,YAAY,OAAO,MAAM,aAAa,OAAO,OAAO,OAAO,QAAQ,OAAO,SAAS,SAAS,OAAO,CAAC;AAAA,YAC/G;AAAA,YACA,aAAa,CAAC,UAAU;AACpB,kBAAI,KAAK,SAAS,cAAc,MAAM,WAAW;AAC7C,sBAAM,SAAS,KAAK;AACpB,qBAAK,UAAU;AACf,uBAAO,QAAQ;AACf,oBAAI,MAAM,cAAc,kBAAkB,MAAM,SAAS,GAAG;AACxD,wBAAM,cAAc,sBAAsB,MAAM,SAAS;AAAA,gBAC7D;AAAA,cACJ;AAAA,YACJ;AAAA,YACA,iBAAiB,CAAC,UAAU;AACxB,kBAAI,KAAK,SAAS,cAAc,MAAM,WAAW;AAC7C,uBAAO;AAAA,cACX;AAAA,YACJ;AAAA,YACA,sBAAsB;AAAA;AAAA,QAC1B;AAAA,QACA;AAAA,UAAC;AAAA;AAAA,YACG,IAAI;AAAA,YACJ,KAAK;AAAA,YACL,WAAU;AAAA,YAET;AAAA;AAAA,QACL;AAAA;AAAA;AAAA,EACJ;AACJ;",
4
+ "sourcesContent": ["/**\n * @author WMXPY\n * @package Resizable\n * @namespace Resizable\n * @description Size\n */\n\nexport const constrainSize = (size: number, min: number, max: number): number => {\n if (!Number.isFinite(size) || !Number.isFinite(min) || !Number.isFinite(max) || min < 0 || max > 100 || min > max) {\n throw new RangeError(\"Resizable requires finite percentages and 0 <= minSize <= maxSize <= 100.\");\n }\n return Math.min(max, Math.max(min, size));\n};\n\nexport const pointerSize = (size: number, delta: number, extent: number, reverse: boolean, min: number, max: number): number => {\n return constrainSize(extent > 0 ? size + delta / extent * 100 * (reverse ? -1 : 1) : size, min, max);\n};\n\nexport const keyboardSize = (key: string, size: number, step: number, horizontal: boolean, reverse: boolean, min: number, max: number): number | null => {\n if (key === \"Home\") {\n return min;\n }\n if (key === \"End\") {\n return max;\n }\n const positive = horizontal ? \"ArrowRight\" : \"ArrowDown\";\n const negative = horizontal ? \"ArrowLeft\" : \"ArrowUp\";\n if (key !== positive && key !== negative) {\n return null;\n }\n return constrainSize(size + (key === positive ? 1 : -1) * (horizontal && reverse ? -1 : 1) * step, min, max);\n};\n", "/**\n * @author WMXPY\n * @package Resizable\n * @namespace Resizable\n * @description Resizable\n */\n\nimport { constrainSize, keyboardSize, pointerSize } from \"./size\";\nimport { isComposingKeyEvent } from \"@gridui/interaction\";\nimport { useInteractionOutline } from \"@gridui/overlay\";\nimport { usePointerDrag } from \"@gridui/react-utils\";\nimport { cn } from \"@gridui/style-utils\";\nimport { type ComponentPropsWithRef, type FC, type ReactNode, useId, useLayoutEffect, useState } from \"react\";\n\nexport type ResizableProps = Omit<ComponentPropsWithRef<\"div\">, \"children\" | \"onChange\"> & {\n readonly first: ReactNode;\n readonly second: ReactNode;\n readonly label: string;\n readonly orientation?: \"horizontal\" | \"vertical\";\n readonly size?: number;\n readonly defaultSize?: number;\n readonly minSize?: number;\n readonly maxSize?: number;\n readonly step?: number;\n readonly disabled?: boolean;\n readonly onSizeChange?: (size: number) => void;\n};\n\ntype Drag = {\n readonly start: number;\n readonly size: number;\n readonly extent: number;\n readonly reverse: boolean;\n readonly horizontal: boolean;\n};\n\nexport const Resizable: FC<ResizableProps> = (props: ResizableProps) => {\n const { first, second, label, orientation = \"horizontal\", size, defaultSize = 50, minSize = 10, maxSize = 90,\n step = 1, disabled = false, onSizeChange, className, style, ...restProps } = props;\n const [\n local,\n setLocal,\n ] = useState(defaultSize);\n const firstRef = useInteractionOutline<HTMLDivElement>({});\n const secondRef = useInteractionOutline<HTMLDivElement>({});\n const firstId = useId();\n const secondId = useId();\n const current = constrainSize(size ?? local, minSize, maxSize);\n if (!Number.isFinite(step) || step <= 0) {\n throw new RangeError(\"Resizable step must be a positive finite percentage.\");\n }\n const horizontal = orientation === \"horizontal\";\n const update = (next: number) => {\n if (disabled) {\n return;\n }\n if (size === undefined) {\n setLocal(next);\n }\n if (next !== current) {\n onSizeChange?.(next);\n }\n };\n const drag = usePointerDrag<Drag>((active) => {\n const next = constrainSize(active.size, minSize, maxSize);\n if (size === undefined) {\n setLocal(next);\n }\n if (next !== current) {\n onSizeChange?.(next);\n }\n });\n useLayoutEffect(() => {\n const active = drag.get();\n if (disabled || (active && active.horizontal !== horizontal)) {\n drag.cancel();\n }\n });\n const tracks = `minmax(0, ${current}fr) var(--gridui-resizable-handle-size, 12px) minmax(0, ${100 - current}fr)`;\n return (<div\n {...restProps}\n className={cn(\"gridui-resizable\", className)}\n data-orientation={orientation}\n style={{\n ...style,\n ...(horizontal ? { gridTemplateColumns: tracks } : { gridTemplateRows: tracks }),\n }}\n >\n <div\n id={firstId}\n ref={firstRef}\n className=\"gridui-resizable-panel\"\n >\n {first}\n </div>\n <div\n role=\"separator\"\n aria-label={label}\n aria-controls={`${firstId} ${secondId}`}\n aria-orientation={horizontal ? \"vertical\" : \"horizontal\"}\n aria-valuemin={minSize}\n aria-valuemax={maxSize}\n aria-valuenow={Math.round(current * 100) / 100}\n aria-valuetext={`${Math.round(current)}%`}\n aria-disabled={disabled || undefined}\n tabIndex={disabled ? -1 : 0}\n className=\"gridui-resizable-handle\"\n onKeyDown={(event) => {\n if (disabled || event.defaultPrevented || isComposingKeyEvent(event.nativeEvent)) {\n return;\n }\n const reverse = getComputedStyle(event.currentTarget).direction === \"rtl\";\n const next = keyboardSize(event.key, current, step * (event.shiftKey ? 10 : 1), horizontal, reverse, minSize, maxSize);\n if (next !== null) {\n event.preventDefault();\n update(next);\n }\n }}\n onPointerDown={(event) => {\n if (disabled) {\n return;\n }\n const handle = event.currentTarget;\n const bounds = handle.parentElement?.getBoundingClientRect();\n if (!bounds) {\n return;\n }\n const handleBounds = handle.getBoundingClientRect();\n const started = drag.start(event, {\n start: horizontal ? event.clientX : event.clientY,\n size: current,\n extent: horizontal ? bounds.width - handleBounds.width : bounds.height - handleBounds.height,\n reverse: horizontal && getComputedStyle(handle).direction === \"rtl\",\n horizontal,\n });\n if (started) {\n handle.focus();\n event.preventDefault();\n }\n }}\n onPointerMove={(event) => {\n const active = drag.get(event.pointerId);\n if (!active) {\n return;\n }\n const coordinate = horizontal ? event.clientX : event.clientY;\n update(pointerSize(active.size, coordinate - active.start, active.extent, active.reverse, minSize, maxSize));\n }}\n onPointerUp={(event) => {\n drag.finish(event.pointerId);\n }}\n onPointerCancel={(event) => {\n drag.cancel(event.pointerId);\n }}\n onLostPointerCapture={(event) => {\n drag.cancel(event.pointerId);\n }}\n />\n <div\n id={secondId}\n ref={secondRef}\n className=\"gridui-resizable-panel\"\n >\n {second}\n </div>\n </div>);\n};\n"],
5
+ "mappings": ";AAOO,IAAM,gBAAgB,CAAC,MAAc,KAAa,QAAwB;AAC7E,MAAI,CAAC,OAAO,SAAS,IAAI,KAAK,CAAC,OAAO,SAAS,GAAG,KAAK,CAAC,OAAO,SAAS,GAAG,KAAK,MAAM,KAAK,MAAM,OAAO,MAAM,KAAK;AAC/G,UAAM,IAAI,WAAW,2EAA2E;AAAA,EACpG;AACA,SAAO,KAAK,IAAI,KAAK,KAAK,IAAI,KAAK,IAAI,CAAC;AAC5C;AAEO,IAAM,cAAc,CAAC,MAAc,OAAe,QAAgB,SAAkB,KAAa,QAAwB;AAC5H,SAAO,cAAc,SAAS,IAAI,OAAO,QAAQ,SAAS,OAAO,UAAU,KAAK,KAAK,MAAM,KAAK,GAAG;AACvG;AAEO,IAAM,eAAe,CAAC,KAAa,MAAc,MAAc,YAAqB,SAAkB,KAAa,QAA+B;AACrJ,MAAI,QAAQ,QAAQ;AAChB,WAAO;AAAA,EACX;AACA,MAAI,QAAQ,OA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A,QACJ;AAAA,QACA;AAAA,UAAC;AAAA;AAAA,YACG,IAAI;AAAA,YACJ,KAAK;AAAA,YACL,WAAU;AAAA,YAET;AAAA;AAAA,QACL;AAAA;AAAA;AAAA,EACJ;AACJ;",
6
6
  "names": []
7
7
  }
package/docs/catalog.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "schemaVersion": 1,
3
3
  "name": "@gridui/resizable",
4
- "version": "1.0.3",
4
+ "version": "1.0.4",
5
5
  "category": "layout",
6
6
  "description": "GridUI React resizable",
7
7
  "usage": "Two independently scrolling regions separated by a keyboard and pointer resizer. Resizable owns its separator; surrounding Grid regions continue to own outer seams.",
@@ -28,6 +28,7 @@
28
28
  "@gridui/resizable/styles.css"
29
29
  ],
30
30
  "examples": [
31
+ "https://github.com/sudo-ui/GridUI-React-Monorepo/blob/main/packages-layout/resizable/stories/getting-started.mdx",
31
32
  "https://github.com/sudo-ui/GridUI-React-Monorepo/blob/main/packages-layout/resizable/stories/regions.mdx",
32
33
  "https://github.com/sudo-ui/GridUI-React-Monorepo/blob/main/packages-layout/resizable/stories/resizable.stories.tsx"
33
34
  ]
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gridui/resizable",
3
- "version": "1.0.3",
3
+ "version": "1.0.4",
4
4
  "description": "GridUI React resizable",
5
5
  "license": "UNLICENSED",
6
6
  "type": "module",
@@ -28,9 +28,10 @@
28
28
  },
29
29
  "dependencies": {
30
30
  "@gridui/interaction": "^1.2.1",
31
- "@gridui/overlay": "^2.0.0",
31
+ "@gridui/overlay": "^2.1.0",
32
+ "@gridui/react-utils": "^1.0.0",
32
33
  "@gridui/style-utils": "^4.0.0",
33
- "@gridui/theme": "^2.5.3"
34
+ "@gridui/theme": "^2.5.4"
34
35
  },
35
36
  "devDependencies": {
36
37
  "@gridui-internal/configuration": "0.0.0-internal",