@fragiola/flow-react 0.0.0-stage → 0.1.0
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/CHANGELOG.md +18 -0
- package/LICENSE +21 -0
- package/README.md +19 -2
- package/dist/connection.d.ts +1 -0
- package/dist/connection.js +1 -0
- package/dist/drag.d.ts +1 -0
- package/dist/drag.js +1 -0
- package/dist/index.d.ts +713 -0
- package/dist/index.js +1678 -0
- package/dist/index.js.map +1 -0
- package/dist/keyboard.d.ts +1 -0
- package/dist/keyboard.js +1 -0
- package/dist/minimap.d.ts +68 -0
- package/dist/minimap.js +137 -0
- package/dist/minimap.js.map +1 -0
- package/dist/reconnection.d.ts +1 -0
- package/dist/reconnection.js +1 -0
- package/dist/resize.d.ts +73 -0
- package/dist/resize.js +168 -0
- package/dist/resize.js.map +1 -0
- package/dist/rolldown-runtime-D8jQpDG7.js +12 -0
- package/dist/selection.d.ts +1 -0
- package/dist/selection.js +1 -0
- package/dist/subflows.d.ts +1 -0
- package/dist/subflows.js +1 -0
- package/dist/use-render-BoW0zIae.d.ts +44 -0
- package/dist/use-render-Dfsx9V4b.js +365 -0
- package/dist/use-render-Dfsx9V4b.js.map +1 -0
- package/package.json +107 -3
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"minimap.js","names":[],"sources":["../src/minimap/mini-map-context.ts","../src/minimap/mini-map-mask.tsx","../src/minimap/mini-map-node.tsx","../src/minimap/mini-map.tsx"],"sourcesContent":["import type { MinimapView } from \"@fragiola/flow\";\nimport * as React from \"react\";\n\n/** The view of the enclosing `MiniMap`, for its nodes and its mask. */\nexport const MiniMapContext = React.createContext<MinimapView | null>(null);\n\nexport function useMiniMapView(part: string): MinimapView {\n const view = React.useContext(MiniMapContext);\n if (!view) throw new Error(`${part} must be rendered inside MiniMap`);\n return view;\n}\n","import { partAttributes } from \"@fragiola/flow\";\nimport { type SvgPrimitiveProps, useRenderElement } from \"../utils/use-render\";\nimport { useMiniMapView } from \"./mini-map-context\";\n\n/** The state of `MiniMapMask`: the root's view, in flow coordinates. */\nexport interface MiniMapMaskState {\n readonly view: { x: number; y: number; width: number; height: number };\n}\n\nexport interface MiniMapMaskProps\n extends SvgPrimitiveProps<MiniMapMaskState, SVGPathElement> {}\n\n/**\n * The `MiniMap`'s mask (`data-flow-part=\"minimap-mask\"`): an SVG path covering the map but what the\n * root shows (`fill-rule=\"evenodd\"`). Give it its fill.\n */\nexport function MiniMapMask(props: MiniMapMaskProps) {\n const view = useMiniMapView(\"MiniMapMask\");\n return useRenderElement(\"path\", props, {\n state: { view: view.view },\n props: {\n ...partAttributes(\"minimap-mask\"),\n d: view.maskPath,\n fillRule: \"evenodd\",\n },\n });\n}\n","import { partAttributes } from \"@fragiola/flow\";\nimport { useFlowContext } from \"../context\";\nimport { sameValue, useFlowValue } from \"../hooks/internal\";\nimport { type SvgPrimitiveProps, useRenderElement } from \"../utils/use-render\";\nimport { useMiniMapView } from \"./mini-map-context\";\n\nexport interface MiniMapNodeState {\n readonly nodeId: string;\n /** `data-selected` (`selection()`) */\n readonly selected: boolean;\n}\n\nexport interface MiniMapNodeProps\n extends SvgPrimitiveProps<MiniMapNodeState, SVGRectElement> {\n /** the node it stands for */\n nodeId: string;\n}\n\n/**\n * A node in the `MiniMap` (`data-flow-part=\"minimap-node\"`, `data-flow-id`): an SVG rectangle of\n * the node's box, in flow coordinates. Nothing when the node is not shown.\n */\nexport function MiniMapNode(props: MiniMapNodeProps) {\n const { nodeId, ...rest } = props;\n const view = useMiniMapView(\"MiniMapNode\");\n const { model, engine } = useFlowContext(\"MiniMapNode\");\n const attributes = useFlowValue(\n model,\n engine,\n () =>\n engine\n ? engine.adapter.attributes(\"minimap-node\", { nodeId })\n : partAttributes(\"minimap-node\", nodeId),\n sameValue,\n \"entity\",\n );\n const box = view.nodes.find((node) => node.nodeId === nodeId);\n const element = useRenderElement(\"rect\", rest, {\n state: { nodeId, selected: attributes[\"data-selected\"] !== undefined },\n props: {\n ...attributes,\n x: box?.x,\n y: box?.y,\n width: box?.width,\n height: box?.height,\n },\n });\n return box ? element : null;\n}\n","import { type MinimapView, partAttributes, type XY } from \"@fragiola/flow\";\nimport * as React from \"react\";\nimport { useFlowContext } from \"../context\";\nimport { useFlowValue, useIsomorphicLayoutEffect } from \"../hooks/internal\";\nimport { type SvgPrimitiveProps, useRenderElement } from \"../utils/use-render\";\nimport { MiniMapContext } from \"./mini-map-context\";\nimport { MiniMapMask } from \"./mini-map-mask\";\nimport { MiniMapNode } from \"./mini-map-node\";\n\nexport interface MiniMapState {\n /** what it draws: the nodes, the view and the mask, in flow coordinates */\n readonly view: MinimapView;\n}\n\nexport interface MiniMapProps\n extends Omit<\n SvgPrimitiveProps<MiniMapState, SVGSVGElement>,\n \"children\" | \"onClick\"\n > {\n /** its width, in pixels; default 200 */\n width?: number | undefined;\n /** its height, in pixels; default 150 */\n height?: number | undefined;\n /**\n * a drag on it moves the view the other way (as grabbing the flow), and a press does not\n * centre the view; default `minimap()`'s `inversePan`\n */\n inversePan?: boolean | undefined;\n /** how fast its wheel zooms: 10 is the flow's own wheel, 20 twice as fast; default `minimap()`'s `zoomStep` */\n zoomStep?: number | undefined;\n /**\n * a tap on it (`minimap-click`), with the flow point under the pointer on the minimap: center\n * the view there, add a node there\n */\n onClick?: ((event: MouseEvent, point: XY) => void) | undefined;\n /**\n * what it draws, in flow coordinates; default a `MiniMapNode` per node, then the `MiniMapMask`\n */\n children?: React.ReactNode | ((view: MinimapView) => React.ReactNode);\n}\n\nconst EMPTY_VIEW: MinimapView = Object.freeze({\n viewBox: Object.freeze({ x: 0, y: 0, width: 0, height: 0 }),\n viewBoxAttribute: \"0 0 0 0\",\n scale: 1,\n nodes: Object.freeze([]),\n view: Object.freeze({ x: 0, y: 0, width: 0, height: 0 }),\n maskPath: \"\",\n});\n\n/**\n * A small map of the flow (`data-flow-part=\"minimap\"`, `minimap()`): an SVG of `width` × `height`\n * pixels showing every node and what the root shows. With `minimap()`'s options, a drag on it pans\n * and its wheel zooms the flow. Inside `Flow.Root`, outside `Flow.Viewport`; place it with your\n * style.\n */\nexport function MiniMap(props: MiniMapProps) {\n const {\n width = 200,\n height = 150,\n inversePan,\n zoomStep,\n onClick,\n children,\n ...rest\n } = props;\n const { model, engine } = useFlowContext(\"MiniMap\");\n // its options over `minimap()`'s, one set for the root's minimaps (the engine's part options)\n useIsomorphicLayoutEffect(() => {\n if (!engine) return;\n const options = Object.fromEntries(\n Object.entries({ inversePan, zoomStep }).filter(\n ([, value]) => value !== undefined,\n ),\n );\n engine.adapter.setPartOptions(\"minimap\", \"\", options);\n return () => engine.adapter.setPartOptions(\"minimap\", \"\", null);\n }, [engine, inversePan, zoomStep]);\n const latestClick = React.useRef(onClick);\n latestClick.current = onClick;\n // its own element: the root may draw several minimaps, each keeps only its taps\n const own = React.useRef<SVGSVGElement | null>(null);\n React.useEffect(() => {\n if (!engine) return;\n return engine.subscribe((event) => {\n if (\n event.type === \"minimap-click\" &&\n event.element === own.current\n ) {\n latestClick.current?.(event.event, event.point);\n }\n });\n }, [engine]);\n const view = useFlowValue(\n model,\n engine,\n () => engine?.get(\"minimap-view\", { width, height }) ?? EMPTY_VIEW,\n (a, b) =>\n a === b ||\n (a.viewBoxAttribute === b.viewBoxAttribute &&\n a.maskPath === b.maskPath &&\n a.nodes.length === b.nodes.length &&\n a.nodes.every((node, i) => {\n const other = b.nodes[i];\n return (\n other !== undefined &&\n node.nodeId === other.nodeId &&\n node.x === other.x &&\n node.y === other.y &&\n node.width === other.width &&\n node.height === other.height\n );\n })),\n );\n const attributes = useFlowValue(model, engine, () =>\n engine\n ? engine.adapter.attributes(\"minimap\")\n : partAttributes(\"minimap\"),\n );\n const content =\n typeof children === \"function\"\n ? children(view)\n : (children ?? (\n <>\n {view.nodes.map((node) => (\n <MiniMapNode key={node.nodeId} nodeId={node.nodeId} />\n ))}\n <MiniMapMask />\n </>\n ));\n const element = useRenderElement(\"svg\", rest, {\n ref: own,\n state: { view },\n props: {\n ...attributes,\n viewBox: view.viewBoxAttribute,\n width,\n height,\n children: content,\n },\n style: { width, height },\n });\n return (\n <MiniMapContext.Provider value={view}>\n {element}\n </MiniMapContext.Provider>\n );\n}\n"],"mappings":";;;;;;;AAIA,MAAa,iBAAiB,MAAM,cAAkC,IAAI;AAE1E,SAAgB,eAAe,MAA2B;CACtD,MAAM,OAAO,MAAM,WAAW,cAAc;CAC5C,IAAI,CAAC,MAAM,MAAM,IAAI,MAAM,GAAG,KAAK,iCAAiC;CACpE,OAAO;AACX;;;;;;ACMA,SAAgB,YAAY,OAAyB;CACjD,MAAM,OAAO,eAAe,aAAa;CACzC,OAAO,iBAAiB,QAAQ,OAAO;EACnC,OAAO,EAAE,MAAM,KAAK,KAAK;EACzB,OAAO;GACH,GAAG,eAAe,cAAc;GAChC,GAAG,KAAK;GACR,UAAU;EACd;CACJ,CAAC;AACL;;;;;;ACJA,SAAgB,YAAY,OAAyB;CACjD,MAAM,EAAE,QAAQ,GAAG,SAAS;CAC5B,MAAM,OAAO,eAAe,aAAa;CACzC,MAAM,EAAE,OAAO,WAAW,eAAe,aAAa;CACtD,MAAM,aAAa,aACf,OACA,cAEI,SACM,OAAO,QAAQ,WAAW,gBAAgB,EAAE,OAAO,CAAC,IACpD,eAAe,gBAAgB,MAAM,GAC/C,WACA,QACJ;CACA,MAAM,MAAM,KAAK,MAAM,MAAM,SAAS,KAAK,WAAW,MAAM;CAC5D,MAAM,UAAU,iBAAiB,QAAQ,MAAM;EAC3C,OAAO;GAAE;GAAQ,UAAU,WAAW,qBAAqB,KAAA;EAAU;EACrE,OAAO;GACH,GAAG;GACH,GAAG,KAAK;GACR,GAAG,KAAK;GACR,OAAO,KAAK;GACZ,QAAQ,KAAK;EACjB;CACJ,CAAC;CACD,OAAO,MAAM,UAAU;AAC3B;;ACPA,MAAM,aAA0B,OAAO,OAAO;CAC1C,SAAS,OAAO,OAAO;EAAE,GAAG;EAAG,GAAG;EAAG,OAAO;EAAG,QAAQ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MAAM,UACtB,KAAK,MAAM,MAAM,KACjB,KAAK,MAAM,MAAM,KACjB,KAAK,UAAU,MAAM,SACrB,KAAK,WAAW,MAAM;CAE9B,CAAC,CACb;CACA,MAAM,aAAa,aAAa,OAAO,cACnC,SACM,OAAO,QAAQ,WAAW,SAAS,IACnC,eAAe,SAAS,CAClC;CACA,MAAM,UACF,OAAO,aAAa,aACd,SAAS,IAAI,IACZ,YACG,qBAAA,UAAA,EAAA,UAAA,CACK,KAAK,MAAM,KAAK,SACb,oBAAC,aAAD,EAA+B,QAAQ,KAAK,OAAS,GAAnC,KAAK,MAA8B,CACxD,GACD,oBAAC,aAAD,CAAc,CAAA,CAChB,EAAA,CAAA;CAEhB,MAAM,UAAU,iBAAiB,OAAO,MAAM;EAC1C,KAAK;EACL,OAAO,EAAE,KAAK;EACd,OAAO;GACH,GAAG;GACH,SAAS,KAAK;GACd;GACA;GACA,UAAU;EACd;EACA,OAAO;GAAE;GAAO;EAAO;CAC3B,CAAC;CACD,OACI,oBAAC,eAAe,UAAhB;EAAyB,OAAO;EAC3B,UAAA;CACoB,CAAA;AAEjC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "@fragiola/flow/reconnection";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "@fragiola/flow/reconnection";
|
package/dist/resize.d.ts
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { i as DivPrimitiveProps } from "./use-render-BoW0zIae.js";
|
|
2
|
+
import { ResizeHandleDirection, ResizeHandleVariant } from "@fragiola/flow";
|
|
3
|
+
import * as React from "react";
|
|
4
|
+
import { ResizeDirection } from "@fragiola/flow/resize";
|
|
5
|
+
export * from "@fragiola/flow/resize";
|
|
6
|
+
interface NodeResizerState {
|
|
7
|
+
readonly nodeId: string;
|
|
8
|
+
/** its node is being resized: `data-resizing` */
|
|
9
|
+
readonly resizing: boolean;
|
|
10
|
+
}
|
|
11
|
+
interface NodeResizerProps extends DivPrimitiveProps<NodeResizerState> {
|
|
12
|
+
/** its node; default the enclosing `Flow.Node`'s */
|
|
13
|
+
nodeId?: string | undefined;
|
|
14
|
+
/** this node's limits, over `resize()`'s (in flow units) */
|
|
15
|
+
minWidth?: number | undefined;
|
|
16
|
+
minHeight?: number | undefined;
|
|
17
|
+
maxWidth?: number | undefined;
|
|
18
|
+
maxHeight?: number | undefined;
|
|
19
|
+
/** this node keeps its aspect ratio, over `resize()`'s */
|
|
20
|
+
keepAspectRatio?: boolean | undefined;
|
|
21
|
+
/**
|
|
22
|
+
* the sides its handles move: `"horizontal"` only the width (and x), `"vertical"` only the
|
|
23
|
+
* height (and y); default both. A corner then moves its one dimension
|
|
24
|
+
*/
|
|
25
|
+
direction?: ResizeDirection | undefined;
|
|
26
|
+
/** its handles; default a `ResizeHandle` at each corner and side */
|
|
27
|
+
children?: React.ReactNode;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* A node's resizer (`data-flow-part="resizer"`, `resize()`), inside `Flow.Node`: a box over the
|
|
31
|
+
* node holding its `ResizeHandle`s; its limits are this node's own (`setPartOptions`). Render it
|
|
32
|
+
* only when the node should be resizable (while it is selected, say).
|
|
33
|
+
*/
|
|
34
|
+
export declare function NodeResizer(props: NodeResizerProps): React.JSX.Element;
|
|
35
|
+
/** A corner or a side of a node a `ResizeHandle` moves. */
|
|
36
|
+
type ResizePosition = "top-left" | "top" | "top-right" | "right" | "bottom-right" | "bottom" | "bottom-left" | "left";
|
|
37
|
+
/** Every position, corners then sides. */
|
|
38
|
+
export declare const RESIZE_POSITIONS: readonly ResizePosition[];
|
|
39
|
+
interface ResizeHandleState {
|
|
40
|
+
readonly nodeId: string;
|
|
41
|
+
readonly position: ResizePosition;
|
|
42
|
+
/** its own direction, over its resizer's (`data-direction`); none: the resizer's */
|
|
43
|
+
readonly direction: ResizeHandleDirection | undefined;
|
|
44
|
+
/** how it is drawn (`data-variant`): a corner is always a `handle` */
|
|
45
|
+
readonly variant: ResizeHandleVariant;
|
|
46
|
+
}
|
|
47
|
+
interface ResizeHandleProps extends DivPrimitiveProps<ResizeHandleState> {
|
|
48
|
+
/** the corner or side it moves */
|
|
49
|
+
position: ResizePosition;
|
|
50
|
+
/** its node; default the enclosing `Flow.Node`'s */
|
|
51
|
+
nodeId?: string | undefined;
|
|
52
|
+
/**
|
|
53
|
+
* the sides it moves, over its resizer's `direction` (`data-direction`): `"horizontal"` only
|
|
54
|
+
* the width (and x), `"vertical"` only the height (and y); default the resizer's
|
|
55
|
+
*/
|
|
56
|
+
direction?: ResizeHandleDirection | undefined;
|
|
57
|
+
/**
|
|
58
|
+
* how it is drawn (`data-variant`, for your styles): `"handle"` (default) or `"line"`, a
|
|
59
|
+
* side's whole length; a corner's `"line"` is ignored
|
|
60
|
+
*/
|
|
61
|
+
variant?: ResizeHandleVariant | undefined;
|
|
62
|
+
children?: React.ReactNode;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* A grab area of a `NodeResizer` (`data-flow-part="resize-handle"`, `data-position`): a press on
|
|
66
|
+
* it resizes its node from that corner or side (`resize()`); with `keyboard()` too it takes focus
|
|
67
|
+
* and the arrows move that corner or side. Placed on its corner (centred) or
|
|
68
|
+
* along its side; give it its size (a side's thickness) and look. Its `direction` overrides its
|
|
69
|
+
* resizer's; `variant="line"` marks a side's handle as a line for your styles.
|
|
70
|
+
*/
|
|
71
|
+
export declare function ResizeHandle(props: ResizeHandleProps): React.JSX.Element;
|
|
72
|
+
export type { NodeResizerProps, NodeResizerState, ResizeHandleProps, ResizeHandleState, ResizePosition };
|
|
73
|
+
//# sourceMappingURL=resize.d.ts.map
|
package/dist/resize.js
ADDED
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
import { a as useIsomorphicLayoutEffect, g as usePartNodeId, h as useFlowContext, i as useFlowValue, n as useRenderElement, r as sameValue, t as attributeProps } from "./use-render-Dfsx9V4b.js";
|
|
2
|
+
import { resizeHandleAttributes } from "@fragiola/flow";
|
|
3
|
+
import { jsx } from "react/jsx-runtime";
|
|
4
|
+
export * from "@fragiola/flow/resize";
|
|
5
|
+
// src/resize/resize-handle.tsx
|
|
6
|
+
/** Every position, corners then sides. */
|
|
7
|
+
const RESIZE_POSITIONS = Object.freeze([
|
|
8
|
+
"top-left",
|
|
9
|
+
"top-right",
|
|
10
|
+
"bottom-right",
|
|
11
|
+
"bottom-left",
|
|
12
|
+
"top",
|
|
13
|
+
"right",
|
|
14
|
+
"bottom",
|
|
15
|
+
"left"
|
|
16
|
+
]);
|
|
17
|
+
/**
|
|
18
|
+
* Where a handle sits: a corner's centre on the corner, a side's along the side. A corner is above
|
|
19
|
+
* the two sides it joins (`zIndex`), so a press on it resizes both dimensions, whatever the order
|
|
20
|
+
* of the handles.
|
|
21
|
+
*/
|
|
22
|
+
const PLACE = {
|
|
23
|
+
"top-left": {
|
|
24
|
+
top: 0,
|
|
25
|
+
left: 0,
|
|
26
|
+
transform: "translate(-50%, -50%)",
|
|
27
|
+
zIndex: 1
|
|
28
|
+
},
|
|
29
|
+
"top-right": {
|
|
30
|
+
top: 0,
|
|
31
|
+
left: "100%",
|
|
32
|
+
transform: "translate(-50%, -50%)",
|
|
33
|
+
zIndex: 1
|
|
34
|
+
},
|
|
35
|
+
"bottom-right": {
|
|
36
|
+
top: "100%",
|
|
37
|
+
left: "100%",
|
|
38
|
+
transform: "translate(-50%, -50%)",
|
|
39
|
+
zIndex: 1
|
|
40
|
+
},
|
|
41
|
+
"bottom-left": {
|
|
42
|
+
top: "100%",
|
|
43
|
+
left: 0,
|
|
44
|
+
transform: "translate(-50%, -50%)",
|
|
45
|
+
zIndex: 1
|
|
46
|
+
},
|
|
47
|
+
top: {
|
|
48
|
+
top: 0,
|
|
49
|
+
left: 0,
|
|
50
|
+
width: "100%",
|
|
51
|
+
transform: "translateY(-50%)"
|
|
52
|
+
},
|
|
53
|
+
bottom: {
|
|
54
|
+
top: "100%",
|
|
55
|
+
left: 0,
|
|
56
|
+
width: "100%",
|
|
57
|
+
transform: "translateY(-50%)"
|
|
58
|
+
},
|
|
59
|
+
left: {
|
|
60
|
+
top: 0,
|
|
61
|
+
left: 0,
|
|
62
|
+
height: "100%",
|
|
63
|
+
transform: "translateX(-50%)"
|
|
64
|
+
},
|
|
65
|
+
right: {
|
|
66
|
+
top: 0,
|
|
67
|
+
left: "100%",
|
|
68
|
+
height: "100%",
|
|
69
|
+
transform: "translateX(-50%)"
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
/**
|
|
73
|
+
* A grab area of a `NodeResizer` (`data-flow-part="resize-handle"`, `data-position`): a press on
|
|
74
|
+
* it resizes its node from that corner or side (`resize()`); with `keyboard()` too it takes focus
|
|
75
|
+
* and the arrows move that corner or side. Placed on its corner (centred) or
|
|
76
|
+
* along its side; give it its size (a side's thickness) and look. Its `direction` overrides its
|
|
77
|
+
* resizer's; `variant="line"` marks a side's handle as a line for your styles.
|
|
78
|
+
*/
|
|
79
|
+
function ResizeHandle(props) {
|
|
80
|
+
const { position, nodeId: nodeIdProp, direction, variant, children, ...rest } = props;
|
|
81
|
+
const nodeId = usePartNodeId("ResizeHandle", nodeIdProp);
|
|
82
|
+
const { model, engine } = useFlowContext("ResizeHandle");
|
|
83
|
+
const attributes = useFlowValue(model, engine, () => engine ? engine.adapter.attributes("resize-handle", {
|
|
84
|
+
nodeId,
|
|
85
|
+
position,
|
|
86
|
+
direction,
|
|
87
|
+
variant
|
|
88
|
+
}) : resizeHandleAttributes(position, {
|
|
89
|
+
direction,
|
|
90
|
+
variant
|
|
91
|
+
}), sameValue, "entity");
|
|
92
|
+
return useRenderElement("div", rest, {
|
|
93
|
+
state: {
|
|
94
|
+
nodeId,
|
|
95
|
+
position,
|
|
96
|
+
direction: attributes["data-direction"],
|
|
97
|
+
variant: attributes["data-variant"]
|
|
98
|
+
},
|
|
99
|
+
props: {
|
|
100
|
+
...attributeProps(attributes),
|
|
101
|
+
children
|
|
102
|
+
},
|
|
103
|
+
style: {
|
|
104
|
+
position: "absolute",
|
|
105
|
+
pointerEvents: "auto",
|
|
106
|
+
...PLACE[position]
|
|
107
|
+
}
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
// src/resize/node-resizer.tsx
|
|
111
|
+
const RESIZER_STYLE = {
|
|
112
|
+
position: "absolute",
|
|
113
|
+
inset: 0,
|
|
114
|
+
pointerEvents: "none"
|
|
115
|
+
};
|
|
116
|
+
/**
|
|
117
|
+
* A node's resizer (`data-flow-part="resizer"`, `resize()`), inside `Flow.Node`: a box over the
|
|
118
|
+
* node holding its `ResizeHandle`s; its limits are this node's own (`setPartOptions`). Render it
|
|
119
|
+
* only when the node should be resizable (while it is selected, say).
|
|
120
|
+
*/
|
|
121
|
+
function NodeResizer(props) {
|
|
122
|
+
const { nodeId: nodeIdProp, minWidth, minHeight, maxWidth, maxHeight, keepAspectRatio, direction, children, ...rest } = props;
|
|
123
|
+
const nodeId = usePartNodeId("NodeResizer", nodeIdProp);
|
|
124
|
+
const { model, engine } = useFlowContext("NodeResizer");
|
|
125
|
+
useIsomorphicLayoutEffect(() => {
|
|
126
|
+
if (!engine) return;
|
|
127
|
+
const options = Object.fromEntries(Object.entries({
|
|
128
|
+
minWidth,
|
|
129
|
+
minHeight,
|
|
130
|
+
maxWidth,
|
|
131
|
+
maxHeight,
|
|
132
|
+
keepAspectRatio,
|
|
133
|
+
direction
|
|
134
|
+
}).filter(([, value]) => value !== void 0));
|
|
135
|
+
engine.adapter.setPartOptions("resizer", nodeId, options);
|
|
136
|
+
return () => engine.adapter.setPartOptions("resizer", nodeId, null);
|
|
137
|
+
}, [
|
|
138
|
+
engine,
|
|
139
|
+
nodeId,
|
|
140
|
+
minWidth,
|
|
141
|
+
minHeight,
|
|
142
|
+
maxWidth,
|
|
143
|
+
maxHeight,
|
|
144
|
+
keepAspectRatio,
|
|
145
|
+
direction
|
|
146
|
+
]);
|
|
147
|
+
const attributes = useFlowValue(model, engine, () => engine ? engine.adapter.attributes("resizer", { nodeId }) : {
|
|
148
|
+
"data-flow-part": "resizer",
|
|
149
|
+
"data-flow-id": nodeId
|
|
150
|
+
}, sameValue, "entity");
|
|
151
|
+
return useRenderElement("div", rest, {
|
|
152
|
+
state: {
|
|
153
|
+
nodeId,
|
|
154
|
+
resizing: attributes["data-resizing"] !== void 0
|
|
155
|
+
},
|
|
156
|
+
props: {
|
|
157
|
+
...attributes,
|
|
158
|
+
children: children ?? RESIZE_POSITIONS.map((position) => /* @__PURE__ */ jsx(ResizeHandle, {
|
|
159
|
+
position,
|
|
160
|
+
nodeId
|
|
161
|
+
}, position))
|
|
162
|
+
},
|
|
163
|
+
style: RESIZER_STYLE
|
|
164
|
+
});
|
|
165
|
+
}
|
|
166
|
+
export { NodeResizer, RESIZE_POSITIONS, ResizeHandle };
|
|
167
|
+
|
|
168
|
+
//# sourceMappingURL=resize.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resize.js","names":[],"sources":["../src/resize/resize-handle.tsx","../src/resize/node-resizer.tsx"],"sourcesContent":["import {\n type ResizeHandleDirection,\n type ResizeHandleVariant,\n resizeHandleAttributes,\n} from \"@fragiola/flow\";\nimport type * as React from \"react\";\nimport { useFlowContext, usePartNodeId } from \"../context\";\nimport { sameValue, useFlowValue } from \"../hooks/internal\";\nimport {\n attributeProps,\n type DivPrimitiveProps,\n useRenderElement,\n} from \"../utils/use-render\";\n\n/** A corner or a side of a node a `ResizeHandle` moves. */\nexport type ResizePosition =\n | \"top-left\"\n | \"top\"\n | \"top-right\"\n | \"right\"\n | \"bottom-right\"\n | \"bottom\"\n | \"bottom-left\"\n | \"left\";\n\n/** Every position, corners then sides. */\nexport const RESIZE_POSITIONS: readonly ResizePosition[] = Object.freeze([\n \"top-left\",\n \"top-right\",\n \"bottom-right\",\n \"bottom-left\",\n \"top\",\n \"right\",\n \"bottom\",\n \"left\",\n]);\n\nexport interface ResizeHandleState {\n readonly nodeId: string;\n readonly position: ResizePosition;\n /** its own direction, over its resizer's (`data-direction`); none: the resizer's */\n readonly direction: ResizeHandleDirection | undefined;\n /** how it is drawn (`data-variant`): a corner is always a `handle` */\n readonly variant: ResizeHandleVariant;\n}\n\nexport interface ResizeHandleProps\n extends DivPrimitiveProps<ResizeHandleState> {\n /** the corner or side it moves */\n position: ResizePosition;\n /** its node; default the enclosing `Flow.Node`'s */\n nodeId?: string | undefined;\n /**\n * the sides it moves, over its resizer's `direction` (`data-direction`): `\"horizontal\"` only\n * the width (and x), `\"vertical\"` only the height (and y); default the resizer's\n */\n direction?: ResizeHandleDirection | undefined;\n /**\n * how it is drawn (`data-variant`, for your styles): `\"handle\"` (default) or `\"line\"`, a\n * side's whole length; a corner's `\"line\"` is ignored\n */\n variant?: ResizeHandleVariant | undefined;\n children?: React.ReactNode;\n}\n\n/**\n * Where a handle sits: a corner's centre on the corner, a side's along the side. A corner is above\n * the two sides it joins (`zIndex`), so a press on it resizes both dimensions, whatever the order\n * of the handles.\n */\nconst PLACE: Record<ResizePosition, React.CSSProperties> = {\n \"top-left\": {\n top: 0,\n left: 0,\n transform: \"translate(-50%, -50%)\",\n zIndex: 1,\n },\n \"top-right\": {\n top: 0,\n left: \"100%\",\n transform: \"translate(-50%, -50%)\",\n zIndex: 1,\n },\n \"bottom-right\": {\n top: \"100%\",\n left: \"100%\",\n transform: \"translate(-50%, -50%)\",\n zIndex: 1,\n },\n \"bottom-left\": {\n top: \"100%\",\n left: 0,\n transform: \"translate(-50%, -50%)\",\n zIndex: 1,\n },\n top: { top: 0, left: 0, width: \"100%\", transform: \"translateY(-50%)\" },\n bottom: {\n top: \"100%\",\n left: 0,\n width: \"100%\",\n transform: \"translateY(-50%)\",\n },\n left: { top: 0, left: 0, height: \"100%\", transform: \"translateX(-50%)\" },\n right: {\n top: 0,\n left: \"100%\",\n height: \"100%\",\n transform: \"translateX(-50%)\",\n },\n};\n\n/**\n * A grab area of a `NodeResizer` (`data-flow-part=\"resize-handle\"`, `data-position`): a press on\n * it resizes its node from that corner or side (`resize()`); with `keyboard()` too it takes focus\n * and the arrows move that corner or side. Placed on its corner (centred) or\n * along its side; give it its size (a side's thickness) and look. Its `direction` overrides its\n * resizer's; `variant=\"line\"` marks a side's handle as a line for your styles.\n */\nexport function ResizeHandle(props: ResizeHandleProps) {\n const {\n position,\n nodeId: nodeIdProp,\n direction,\n variant,\n children,\n ...rest\n } = props;\n const nodeId = usePartNodeId(\"ResizeHandle\", nodeIdProp);\n const { model, engine } = useFlowContext(\"ResizeHandle\");\n // the engine's record: `data-position`, `data-variant`, `data-direction`, and `tabindex` with\n // `keyboard()` (arrows resize)\n const attributes = useFlowValue(\n model,\n engine,\n () =>\n engine\n ? engine.adapter.attributes(\"resize-handle\", {\n nodeId,\n position,\n direction,\n variant,\n })\n : resizeHandleAttributes(position, { direction, variant }),\n sameValue,\n \"entity\",\n );\n return useRenderElement(\"div\", rest, {\n state: {\n nodeId,\n position,\n direction: attributes[\"data-direction\"] as\n | ResizeHandleDirection\n | undefined,\n variant: attributes[\"data-variant\"] as ResizeHandleVariant,\n },\n props: { ...attributeProps(attributes), children },\n style: {\n position: \"absolute\",\n pointerEvents: \"auto\",\n ...PLACE[position],\n },\n });\n}\n","import type { ResizeDirection } from \"@fragiola/flow/resize\";\nimport type * as React from \"react\";\nimport { useFlowContext, usePartNodeId } from \"../context\";\nimport {\n sameValue,\n useFlowValue,\n useIsomorphicLayoutEffect,\n} from \"../hooks/internal\";\nimport { type DivPrimitiveProps, useRenderElement } from \"../utils/use-render\";\nimport { RESIZE_POSITIONS, ResizeHandle } from \"./resize-handle\";\n\nexport interface NodeResizerState {\n readonly nodeId: string;\n /** its node is being resized: `data-resizing` */\n readonly resizing: boolean;\n}\n\nexport interface NodeResizerProps extends DivPrimitiveProps<NodeResizerState> {\n /** its node; default the enclosing `Flow.Node`'s */\n nodeId?: string | undefined;\n /** this node's limits, over `resize()`'s (in flow units) */\n minWidth?: number | undefined;\n minHeight?: number | undefined;\n maxWidth?: number | undefined;\n maxHeight?: number | undefined;\n /** this node keeps its aspect ratio, over `resize()`'s */\n keepAspectRatio?: boolean | undefined;\n /**\n * the sides its handles move: `\"horizontal\"` only the width (and x), `\"vertical\"` only the\n * height (and y); default both. A corner then moves its one dimension\n */\n direction?: ResizeDirection | undefined;\n /** its handles; default a `ResizeHandle` at each corner and side */\n children?: React.ReactNode;\n}\n\nconst RESIZER_STYLE: React.CSSProperties = {\n position: \"absolute\",\n inset: 0,\n pointerEvents: \"none\",\n};\n\n/**\n * A node's resizer (`data-flow-part=\"resizer\"`, `resize()`), inside `Flow.Node`: a box over the\n * node holding its `ResizeHandle`s; its limits are this node's own (`setPartOptions`). Render it\n * only when the node should be resizable (while it is selected, say).\n */\nexport function NodeResizer(props: NodeResizerProps) {\n const {\n nodeId: nodeIdProp,\n minWidth,\n minHeight,\n maxWidth,\n maxHeight,\n keepAspectRatio,\n direction,\n children,\n ...rest\n } = props;\n const nodeId = usePartNodeId(\"NodeResizer\", nodeIdProp);\n const { model, engine } = useFlowContext(\"NodeResizer\");\n useIsomorphicLayoutEffect(() => {\n if (!engine) return;\n const options = Object.fromEntries(\n Object.entries({\n minWidth,\n minHeight,\n maxWidth,\n maxHeight,\n keepAspectRatio,\n direction,\n }).filter(([, value]) => value !== undefined),\n );\n engine.adapter.setPartOptions(\"resizer\", nodeId, options);\n return () => engine.adapter.setPartOptions(\"resizer\", nodeId, null);\n }, [\n engine,\n nodeId,\n minWidth,\n minHeight,\n maxWidth,\n maxHeight,\n keepAspectRatio,\n direction,\n ]);\n const attributes = useFlowValue(\n model,\n engine,\n () =>\n engine\n ? engine.adapter.attributes(\"resizer\", { nodeId })\n : { \"data-flow-part\": \"resizer\", \"data-flow-id\": nodeId },\n sameValue,\n \"entity\",\n );\n return useRenderElement(\"div\", rest, {\n state: { nodeId, resizing: attributes[\"data-resizing\"] !== undefined },\n props: {\n ...attributes,\n children:\n children ??\n RESIZE_POSITIONS.map((position) => (\n <ResizeHandle\n key={position}\n position={position}\n nodeId={nodeId}\n />\n )),\n },\n style: RESIZER_STYLE,\n });\n}\n"],"mappings":";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,eAAe;AACnB;;;;;;AAOA,SAAgB,YAAY,OAAyB;CACjD,MAAM,EACF,QAAQ,YACR,UACA,WACA,UACA,WACA,iBACA,WACA,UACA,GAAG,SACH;CACJ,MAAM,SAAS,cAAc,eAAe,UAAU;CACtD,MAAM,EAAE,OAAO,WAAW,eAAe,aAAa;CACtD,gCAAgC;EAC5B,IAAI,CAAC,QAAQ;EACb,MAAM,UAAU,OAAO,YACnB,OAAO,QAAQ;GACX;GACA;GACA;GACA;GACA;GACA;EACJ,CAAC,CAAC,CAAC,QAAQ,GAAG,WAAW,UAAU,KAAA,CAAS,CAChD;EACA,OAAO,QAAQ,eAAe,WAAW,QAAQ,OAAO;EACxD,aAAa,OAAO,QAAQ,eAAe,WAAW,QAAQ,IAAI;CACtE,GAAG;EACC;EACA;EACA;EACA;EACA;EACA;EACA;EACA;CACJ,CAAC;CACD,MAAM,aAAa,aACf,OACA,cAEI,SACM,OAAO,QAAQ,WAAW,WAAW,EAAE,OAAO,CAAC,IAC/C;EAAE,kBAAkB;EAAW,gBAAgB;CAAO,GAChE,WACA,QACJ;CACA,OAAO,iBAAiB,OAAO,MAAM;EACjC,OAAO;GAAE;GAAQ,UAAU,WAAW,qBAAqB,KAAA;EAAU;EACrE,OAAO;GACH,GAAG;GACH,UACI,YACA,iBAAiB,KAAK,aAClB,oBAAC,cAAD;IAEc;IACF;GACX,GAHQ,QAGR,CACJ;EACT;EACA,OAAO;CACX,CAAC;AACL"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
// \0rolldown/runtime.js
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __exportAll = (all, no_symbols) => {
|
|
4
|
+
let target = {};
|
|
5
|
+
for (var name in all) __defProp(target, name, {
|
|
6
|
+
get: all[name],
|
|
7
|
+
enumerable: true
|
|
8
|
+
});
|
|
9
|
+
if (!no_symbols) __defProp(target, Symbol.toStringTag, { value: "Module" });
|
|
10
|
+
return target;
|
|
11
|
+
};
|
|
12
|
+
export { __exportAll as t };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "@fragiola/flow/selection";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "@fragiola/flow/selection";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "@fragiola/flow/subflows";
|
package/dist/subflows.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "@fragiola/flow/subflows";
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
/**
|
|
3
|
+
* Props a `render` function receives: spread them onto the element it returns. `ref` is a callback
|
|
4
|
+
* ref, so it fits any element's `ref` (`render={(props) => <section {...props} />}` needs no cast).
|
|
5
|
+
*/
|
|
6
|
+
type RenderedProps<E extends Element = HTMLElement> = (E extends SVGElement ? React.SVGAttributes<E> : React.HTMLAttributes<E>) & {
|
|
7
|
+
ref: React.RefCallback<E>;
|
|
8
|
+
[dataAttribute: `data-${string}`]: string | undefined;
|
|
9
|
+
};
|
|
10
|
+
/**
|
|
11
|
+
* Replaces the element a primitive renders, Base UI style: either an element whose props are
|
|
12
|
+
* merged with the primitive's (`render={<section />}`), or a function receiving the props and
|
|
13
|
+
* the primitive's state (`render={(props, state) => <section {...props} />}`).
|
|
14
|
+
*/
|
|
15
|
+
type RenderProp<State, E extends Element = HTMLElement> = React.ReactElement | ((props: RenderedProps<E>, state: State) => React.ReactElement);
|
|
16
|
+
/** The props every primitive accepts on top of the element's own. */
|
|
17
|
+
interface PrimitiveProps<State, E extends Element = HTMLElement> {
|
|
18
|
+
/** replaces the rendered element (never `asChild`) */
|
|
19
|
+
render?: RenderProp<State, E> | undefined;
|
|
20
|
+
/** a class name, or a function of the primitive's state returning one */
|
|
21
|
+
className?: string | ((state: State) => string | undefined) | undefined;
|
|
22
|
+
/**
|
|
23
|
+
* a style, or a function of the primitive's state returning one. Structural keys the
|
|
24
|
+
* primitive sets (position, its place, its size) always win.
|
|
25
|
+
*/
|
|
26
|
+
style?: React.CSSProperties | ((state: State) => React.CSSProperties | undefined) | undefined;
|
|
27
|
+
ref?: React.Ref<E> | undefined;
|
|
28
|
+
}
|
|
29
|
+
/** The props of a primitive that renders a `div` by default. */
|
|
30
|
+
type DivPrimitiveProps<State> = PrimitiveProps<State, HTMLDivElement> & Omit<React.HTMLAttributes<HTMLDivElement>, "className" | "style">;
|
|
31
|
+
/** The props of a primitive that renders a `button` by default. */
|
|
32
|
+
type ButtonPrimitiveProps<State> = PrimitiveProps<State, HTMLButtonElement> & Omit<React.ButtonHTMLAttributes<HTMLButtonElement>, "className" | "style">;
|
|
33
|
+
/** The props of a primitive that renders an SVG element `E` by default. */
|
|
34
|
+
type SvgPrimitiveProps<State, E extends SVGElement> = PrimitiveProps<State, E> & Omit<React.SVGAttributes<E>, "className" | "style">;
|
|
35
|
+
/** A part's `data-*` attributes, as a hook's `props` carry them. */
|
|
36
|
+
type DataAttributes = {
|
|
37
|
+
readonly [name: `data-${string}`]: string | undefined;
|
|
38
|
+
};
|
|
39
|
+
/** A part's attributes as React props: its `data-*` and, when it takes focus, `tabIndex`. */
|
|
40
|
+
type AttributeProps = DataAttributes & {
|
|
41
|
+
readonly tabIndex?: number | undefined;
|
|
42
|
+
};
|
|
43
|
+
export { PrimitiveProps as a, SvgPrimitiveProps as c, DivPrimitiveProps as i, ButtonPrimitiveProps as n, RenderProp as o, DataAttributes as r, RenderedProps as s, AttributeProps as t };
|
|
44
|
+
//# sourceMappingURL=use-render-BoW0zIae.d.ts.map
|