@fragiola/flow-react 0.0.0-stage → 0.0.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.
@@ -0,0 +1,365 @@
1
+ import * as React from "react";
2
+ // src/context.ts
3
+ const FlowContext = React.createContext(null);
4
+ const NodeContext = React.createContext(null);
5
+ const EdgeContext = React.createContext(null);
6
+ /**
7
+ * The HTML layer edge labels portal into (null until mounted): the `Flow.Edges` element with one
8
+ * render level, its level's `edges-layer` wrapper with several.
9
+ */
10
+ const EdgeLabelLayerContext = React.createContext(null);
11
+ function useFlowContext(part) {
12
+ const context = React.useContext(FlowContext);
13
+ if (!context) throw new Error(`Flow.${part} must be rendered inside Flow.Root`);
14
+ return context;
15
+ }
16
+ /** The node of `nodeId`, or the enclosing `Flow.Node`'s. */
17
+ function usePartNodeId(part, nodeId) {
18
+ const context = React.useContext(NodeContext);
19
+ const id = nodeId ?? context?.nodeId;
20
+ if (id === void 0) throw new Error(`Flow.${part} must be rendered inside Flow.Node (or be given a nodeId)`);
21
+ return id;
22
+ }
23
+ /** The edge of `edgeId`, or the enclosing `Flow.Edge`'s. */
24
+ function useEdgeId(part, edgeId) {
25
+ const context = React.useContext(EdgeContext);
26
+ const id = edgeId ?? context?.edgeId;
27
+ if (id === void 0) throw new Error(`Flow.${part} must be rendered inside Flow.Edge (or be given an edgeId)`);
28
+ return id;
29
+ }
30
+ /** A model of any registry and features, seen erased. */
31
+ function eraseModel(model) {
32
+ return model;
33
+ }
34
+ /** The erased model seen with the registry and features the caller declares. */
35
+ function typedModel(model) {
36
+ return model;
37
+ }
38
+ /** The erased engine seen with the registry and features the caller declares. */
39
+ function typedEngine(engine) {
40
+ return engine;
41
+ }
42
+ // src/utils/flow-store.ts
43
+ const stores = /* @__PURE__ */ new WeakMap();
44
+ /**
45
+ * @internal the store of a model and its engine (the model alone before the engine), made once
46
+ * and shared by every reader of the root. It listens to the engine from its creation on, and to
47
+ * the model while it has a reader (catching up on the lists when it starts again, or when read
48
+ * without one), so its versions are never stale and an unmounted root is not kept by its model.
49
+ */
50
+ function flowStoreOf(model, engine) {
51
+ const key = engine ?? model;
52
+ let store = stores.get(key);
53
+ if (!store) {
54
+ store = createFlowStore(model, engine);
55
+ stores.set(key, store);
56
+ }
57
+ return store;
58
+ }
59
+ function createFlowStore(model, engine) {
60
+ let stamp = 0;
61
+ let viewStamp = 0;
62
+ /** the last change of every node and edge (the lists, a gesture, several levels) */
63
+ let entityStamp = 0;
64
+ /** the last change that was only a measurement: what every reader without an entity hears */
65
+ let measureStamp = 0;
66
+ const listeners = {
67
+ view: /* @__PURE__ */ new Set(),
68
+ entity: /* @__PURE__ */ new Set()
69
+ };
70
+ const records = /* @__PURE__ */ new Map();
71
+ const keyOf = (entity) => `${entity.kind}\u0000${entity.id}`;
72
+ const tokenOf = ({ kind, id }) => !engine ? [] : kind === "node" ? [engine.get("node-rect-by", { nodeId: id }), engine.is("node-measured", { nodeId: id })] : [engine.get("edge-path-by", { edgeId: id })];
73
+ const call = (set) => {
74
+ for (const listener of [...set]) listener();
75
+ };
76
+ /** A change: of the view only, only a measurement, or of everything. */
77
+ const tell = (kind) => {
78
+ stamp += 1;
79
+ viewStamp = stamp;
80
+ call(listeners.view);
81
+ if (kind === "view") return;
82
+ if (kind === "entity") {
83
+ entityStamp = stamp;
84
+ call(listeners.entity);
85
+ for (const record of records.values()) {
86
+ record.token = void 0;
87
+ call(record.listeners);
88
+ }
89
+ return;
90
+ }
91
+ measureStamp = stamp;
92
+ call(listeners.entity);
93
+ const changed = [];
94
+ for (const record of records.values()) {
95
+ const token = tokenOf(record.entity);
96
+ const was = record.token;
97
+ if (was !== void 0 && token.length === was.length && token.every((value, i) => Object.is(value, was[i]))) continue;
98
+ record.token = token;
99
+ record.stamp = stamp;
100
+ changed.push(record);
101
+ }
102
+ for (const record of changed) call(record.listeners);
103
+ };
104
+ let nodes = model.get("all-nodes");
105
+ let edges = model.get("all-edges");
106
+ /** whether the lists changed since last seen, now seen */
107
+ const listsChanged = () => {
108
+ const nextNodes = model.get("all-nodes");
109
+ const nextEdges = model.get("all-edges");
110
+ if (nextNodes === nodes && nextEdges === edges) return false;
111
+ nodes = nextNodes;
112
+ edges = nextEdges;
113
+ return true;
114
+ };
115
+ /** the model's listener's remover, while there is a reader */
116
+ let stopModel;
117
+ let readers = 0;
118
+ /** a change of the lists seen with no one to tell: only the versions move */
119
+ const catchUp = () => {
120
+ if (!listsChanged()) return;
121
+ stamp += 1;
122
+ viewStamp = stamp;
123
+ entityStamp = stamp;
124
+ for (const record of records.values()) record.token = void 0;
125
+ };
126
+ const join = () => {
127
+ readers += 1;
128
+ if (stopModel) return;
129
+ catchUp();
130
+ stopModel = model.subscribe(() => {
131
+ if (listsChanged()) tell("entity");
132
+ });
133
+ };
134
+ const leave = () => {
135
+ readers -= 1;
136
+ if (readers > 0 || !stopModel) return;
137
+ stopModel();
138
+ stopModel = void 0;
139
+ };
140
+ if (engine) {
141
+ const layered = () => engine.get("render-layers").length > 1;
142
+ let wasLayered = layered();
143
+ engine.adapter.subscribe((change) => {
144
+ const isLayered = layered();
145
+ const levels = isLayered || wasLayered;
146
+ wasLayered = isLayered;
147
+ if (change.gesture || levels) tell("entity");
148
+ else if (change.measured) tell(change.viewport ? "entity" : "measured");
149
+ else tell("view");
150
+ });
151
+ }
152
+ return {
153
+ version: (scope, entity) => {
154
+ if (!stopModel) catchUp();
155
+ if (scope === "view") return viewStamp;
156
+ const record = entity ? records.get(keyOf(entity)) : void 0;
157
+ return Math.max(entityStamp, record ? record.stamp : measureStamp);
158
+ },
159
+ subscribe: (scope, listener, entity) => {
160
+ if (scope === "view" || !entity) {
161
+ const set = listeners[scope];
162
+ if (set.has(listener)) return () => {};
163
+ set.add(listener);
164
+ join();
165
+ return () => {
166
+ if (set.delete(listener)) leave();
167
+ };
168
+ }
169
+ const key = keyOf(entity);
170
+ let record = records.get(key);
171
+ if (!record) {
172
+ record = {
173
+ entity,
174
+ listeners: /* @__PURE__ */ new Set(),
175
+ stamp: measureStamp,
176
+ token: tokenOf(entity)
177
+ };
178
+ records.set(key, record);
179
+ }
180
+ const own = record;
181
+ if (own.listeners.has(listener)) return () => {};
182
+ own.listeners.add(listener);
183
+ join();
184
+ return () => {
185
+ if (!own.listeners.delete(listener)) return;
186
+ if (own.listeners.size === 0 && records.get(key) === own) records.delete(key);
187
+ leave();
188
+ };
189
+ }
190
+ };
191
+ }
192
+ // src/utils/shallow-equal.ts
193
+ function same(a, b) {
194
+ if (Object.is(a, b)) return true;
195
+ if (typeof a !== "object" || typeof b !== "object" || a === null || b === null || Array.isArray(a) !== Array.isArray(b)) return false;
196
+ const aRecord = a;
197
+ const bRecord = b;
198
+ const keys = Object.keys(aRecord);
199
+ return keys.length === Object.keys(bRecord).length && keys.every((key) => Object.hasOwn(bRecord, key) && Object.is(aRecord[key], bRecord[key]));
200
+ }
201
+ /**
202
+ * Whether two records (a part's state) hold the same values, a nested record or array compared by
203
+ * its own entries: what decides that a part does not re-render.
204
+ */
205
+ function shallowEqual(a, b) {
206
+ if (a === b) return true;
207
+ if (!a || !b) return false;
208
+ const keys = Object.keys(a);
209
+ return keys.length === Object.keys(b).length && keys.every((key) => Object.hasOwn(b, key) && same(a[key], b[key]));
210
+ }
211
+ // src/hooks/internal.ts
212
+ /** @internal `useLayoutEffect` in a browser, nothing on the server (where it would warn) */
213
+ const useIsomorphicLayoutEffect = typeof document === "undefined" ? () => {} : React.useLayoutEffect;
214
+ /** @internal two values the same for re-rendering: records compared by their entries */
215
+ function sameValue(a, b) {
216
+ if (Object.is(a, b)) return true;
217
+ if (typeof a === "object" && typeof b === "object" && a !== null && b !== null && !Array.isArray(a) && !Array.isArray(b)) return shallowEqual(a, b);
218
+ if (Array.isArray(a) && Array.isArray(b)) return a.length === b.length && a.every((value, i) => Object.is(value, b[i]));
219
+ return false;
220
+ }
221
+ /**
222
+ * @internal a value read from the model and the engine, re-rendering the component only when it
223
+ * changes (`isEqual`; records by their entries by default). It is read again on every change of
224
+ * the model's lists and every view change of the engine (`engine.adapter`: measurements, the
225
+ * viewport, a gesture) that may concern its `scope` (`entity`: a node's or an edge's own view, not
226
+ * read again on a viewport step; given its node or edge, not on a measurement that leaves it
227
+ * alone), and on every render (the reader may close over props); a value
228
+ * equal to the last one keeps the last object. Every reader of a root shares one subscription
229
+ * (`flowStoreOf`).
230
+ */
231
+ function useFlowValue(model, engine, read, isEqual = sameValue, scope = "view", entity) {
232
+ const latest = React.useRef({
233
+ read,
234
+ isEqual
235
+ });
236
+ latest.current = {
237
+ read,
238
+ isEqual
239
+ };
240
+ const cache = React.useRef(void 0);
241
+ const store = flowStoreOf(model, engine);
242
+ const kind = entity?.kind;
243
+ const id = entity?.id;
244
+ const subscribe = React.useCallback((onChange) => store.subscribe(scope, onChange, kind === void 0 || id === void 0 ? void 0 : {
245
+ kind,
246
+ id
247
+ }), [
248
+ store,
249
+ scope,
250
+ kind,
251
+ id
252
+ ]);
253
+ const getSnapshot = () => {
254
+ const version = store.version(scope, entity);
255
+ const previous = cache.current;
256
+ if (previous?.store === store && previous.version === version && previous.read === latest.current.read) return previous.value;
257
+ const value = latest.current.read();
258
+ const kept = previous !== void 0 && latest.current.isEqual(previous.value, value) ? previous.value : value;
259
+ cache.current = {
260
+ store,
261
+ version,
262
+ read: latest.current.read,
263
+ value: kept
264
+ };
265
+ return kept;
266
+ };
267
+ return React.useSyncExternalStore(subscribe, getSnapshot, getSnapshot);
268
+ }
269
+ // src/utils/merge-props.ts
270
+ function isHandler(key, value) {
271
+ return /^on[A-Z]/.test(key) && typeof value === "function";
272
+ }
273
+ /**
274
+ * Merges `external` props over `internal` ones: plain props from `external` win, event handlers
275
+ * are composed (internal first, then external) and class names are joined.
276
+ */
277
+ function mergeProps(internal, external) {
278
+ const merged = { ...internal };
279
+ for (const [key, value] of Object.entries(external)) {
280
+ const current = merged[key];
281
+ if (value === void 0) continue;
282
+ if (isHandler(key, value) && isHandler(key, current)) merged[key] = (...args) => {
283
+ current(...args);
284
+ value(...args);
285
+ };
286
+ else if (key === "className" && typeof current === "string" && typeof value === "string") merged.className = `${current} ${value}`;
287
+ else merged[key] = value;
288
+ }
289
+ return merged;
290
+ }
291
+ // src/utils/use-render.ts
292
+ /** A callback ref that forwards to every ref in `refs` (function refs and ref objects alike). */
293
+ function mergeRefs(...refs) {
294
+ return (value) => {
295
+ const cleanups = refs.map((ref) => {
296
+ if (typeof ref === "function") {
297
+ const cleanup = ref(value);
298
+ return typeof cleanup === "function" ? cleanup : () => ref(null);
299
+ }
300
+ if (ref) {
301
+ ref.current = value;
302
+ return () => {
303
+ ref.current = null;
304
+ };
305
+ }
306
+ });
307
+ return () => {
308
+ for (const cleanup of cleanups) cleanup?.();
309
+ };
310
+ };
311
+ }
312
+ /**
313
+ * A part's attributes from the engine (`engine.adapter.attributes`) as React props: the record
314
+ * holds DOM attribute names, and React takes `tabindex` as `tabIndex` (a number; it warns on the
315
+ * lowercase name). The one place an engine record becomes props.
316
+ */
317
+ function attributeProps(attributes) {
318
+ const { tabindex, ...rest } = attributes;
319
+ return tabindex === void 0 ? rest : {
320
+ ...rest,
321
+ tabIndex: Number(tabindex)
322
+ };
323
+ }
324
+ /**
325
+ * Renders a primitive's element: resolves `className`/`style` functions against the state,
326
+ * merges the consumer's props over the primitive's (handlers composed, internal first; structural
327
+ * style keys win), merges refs, and applies `render`.
328
+ */
329
+ function useRenderElement(tag, componentProps, options) {
330
+ const { render, className, style, ref: externalRef, ...external } = componentProps;
331
+ const internalRef = options.ref;
332
+ const renderElement = render && typeof render !== "function" ? render : void 0;
333
+ const elementRef = renderElement?.props.ref;
334
+ const consumerRefs = React.useRef([]);
335
+ consumerRefs.current = [externalRef, elementRef];
336
+ const hasConsumerRef = externalRef != null || elementRef != null;
337
+ const ref = React.useMemo(() => (element) => mergeRefs(internalRef, ...hasConsumerRef ? consumerRefs.current : [])(element), [internalRef, hasConsumerRef]);
338
+ const resolvedClassName = typeof className === "function" ? className(options.state) : className;
339
+ const resolvedStyle = typeof style === "function" ? style(options.state) : style;
340
+ const props = mergeProps(options.props, external);
341
+ if (resolvedClassName !== void 0) props.className = resolvedClassName;
342
+ if (resolvedStyle || options.style || options.baseStyle) props.style = {
343
+ ...options.baseStyle,
344
+ ...resolvedStyle,
345
+ ...options.style
346
+ };
347
+ props.ref = ref;
348
+ if (typeof render === "function") return render(props, options.state);
349
+ if (renderElement) {
350
+ const elementProps = renderElement.props;
351
+ const merged = mergeProps(props, elementProps);
352
+ if (elementProps.style || props.style) merged.style = {
353
+ ...options.baseStyle,
354
+ ...elementProps.style,
355
+ ...resolvedStyle,
356
+ ...options.style
357
+ };
358
+ merged.ref = ref;
359
+ return React.cloneElement(renderElement, merged);
360
+ }
361
+ return React.createElement(tag, props);
362
+ }
363
+ export { useIsomorphicLayoutEffect as a, EdgeLabelLayerContext as c, eraseModel as d, typedEngine as f, usePartNodeId as g, useFlowContext as h, useFlowValue as i, FlowContext as l, useEdgeId as m, useRenderElement as n, shallowEqual as o, typedModel as p, sameValue as r, EdgeContext as s, attributeProps as t, NodeContext as u };
364
+
365
+ //# sourceMappingURL=use-render-Dfsx9V4b.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-render-Dfsx9V4b.js","names":[],"sources":["../src/context.ts","../src/utils/flow-store.ts","../src/utils/shallow-equal.ts","../src/hooks/internal.ts","../src/utils/merge-props.ts","../src/utils/use-render.ts"],"sourcesContent":["// The contexts of the Flow primitives. The root's holds the model and the engine with the registry\n// erased (`AnyTypes`, any features): a child cannot infer the root's `T` through context, so the\n// typed surface is each part's props and type argument (`useFlow<Types, typeof features>()`).\nimport type {\n AnyTypes,\n FlowEngine,\n FlowFeatures,\n FlowModel,\n FlowTypes,\n StaticGeometry,\n} from \"@fragiola/flow\";\nimport * as React from \"react\";\n\n/** The model as the primitives see it: any registry, any features. */\nexport type AnyFlowModel = FlowModel<AnyTypes, FlowFeatures>;\n\n/** The engine as the primitives see it: any registry, every feature's keys. */\nexport type AnyFlowEngine = FlowEngine<AnyTypes, FlowFeatures>;\n\n/** The context of a `Flow.Root`. */\nexport interface FlowContextValue {\n readonly model: AnyFlowModel;\n /** the engine, once the root is mounted (null on the first render and on the server) */\n readonly engine: AnyFlowEngine | null;\n /** the engine as apps see it: always there, forwarding to the engine once it exists */\n readonly publicEngine: AnyFlowEngine;\n /** the root's element, once mounted: what renders outside the zoom portals into it */\n readonly rootElement: HTMLElement | null;\n /**\n * the flow's geometry from its document while there is no engine (the server render and the\n * first client render: `staticGeometry` with the root's options), null once the engine exists\n */\n readonly staticGeometry: StaticGeometry | null;\n /**\n * the root renders only what is in view (`onlyRenderVisible`): before the engine (which knows\n * the view) no node and no edge is rendered, rather than all of them for one render\n */\n readonly onlyRenderVisible: boolean;\n}\n\nexport const FlowContext = React.createContext<FlowContextValue | null>(null);\n\n/** The node a subtree renders (`Flow.Node`): its handles, resizer and toolbar belong to it. */\nexport interface NodeContextValue {\n readonly nodeId: string;\n}\n\nexport const NodeContext = React.createContext<NodeContextValue | null>(null);\n\n/** The edge a subtree renders (`Flow.Edge`) and the HTML layer its label portals into. */\nexport interface EdgeContextValue {\n readonly edgeId: string;\n}\n\nexport const EdgeContext = React.createContext<EdgeContextValue | null>(null);\n\n/**\n * The HTML layer edge labels portal into (null until mounted): the `Flow.Edges` element with one\n * render level, its level's `edges-layer` wrapper with several.\n */\nexport const EdgeLabelLayerContext = React.createContext<HTMLElement | null>(\n null,\n);\n\nexport function useFlowContext(part: string): FlowContextValue {\n const context = React.useContext(FlowContext);\n if (!context) {\n throw new Error(`Flow.${part} must be rendered inside Flow.Root`);\n }\n return context;\n}\n\n/** The node of `nodeId`, or the enclosing `Flow.Node`'s. */\nexport function usePartNodeId(part: string, nodeId?: string): string {\n const context = React.useContext(NodeContext);\n const id = nodeId ?? context?.nodeId;\n if (id === undefined) {\n throw new Error(\n `Flow.${part} must be rendered inside Flow.Node (or be given a nodeId)`,\n );\n }\n return id;\n}\n\n/** The edge of `edgeId`, or the enclosing `Flow.Edge`'s. */\nexport function useEdgeId(part: string, edgeId?: string): string {\n const context = React.useContext(EdgeContext);\n const id = edgeId ?? context?.edgeId;\n if (id === undefined) {\n throw new Error(\n `Flow.${part} must be rendered inside Flow.Edge (or be given an edgeId)`,\n );\n }\n return id;\n}\n\n/** A model of any registry and features, seen erased. */\nexport function eraseModel<T extends FlowTypes, F extends FlowFeatures>(\n model: FlowModel<T, F>,\n): AnyFlowModel {\n return model as unknown as AnyFlowModel;\n}\n\n/** The erased model seen with the registry and features the caller declares. */\nexport function typedModel<T extends FlowTypes, F extends FlowFeatures>(\n model: AnyFlowModel,\n): FlowModel<T, F> {\n return model as unknown as FlowModel<T, F>;\n}\n\n/** The erased engine seen with the registry and features the caller declares. */\nexport function typedEngine<T extends FlowTypes, F extends FlowFeatures>(\n engine: AnyFlowEngine | FlowEngine,\n): FlowEngine<T, F> {\n return engine as unknown as FlowEngine<T, F>;\n}\n","// One subscription to a flow's model and engine, shared by every value the primitives read\n// (`useFlowValue`): each change is told once, to the readers it may concern, instead of every\n// reader subscribing to both and checking the model's lists on every notification.\nimport type { ViewChange } from \"@fragiola/flow\";\nimport type { AnyFlowEngine, AnyFlowModel } from \"../context\";\n\n/**\n * @internal what a reader depends on:\n * - `view`: anything, the viewport included (the layers' lists, the background, toolbars);\n * - `entity`: one node's or edge's own view (its place, path, attributes, `z-index`), which a\n * viewport step leaves alone, so a pan or a zoom never reads it again. A viewport step does\n * change the nodes' `z-index` while there are several render levels (`node-z-index-by`, the\n * levels follow the drawn edges): then it counts as an entity change too.\n */\nexport type FlowValueScope = \"view\" | \"entity\";\n\n/**\n * @internal the node or the edge an `entity` reader shows: a change that is only a measurement\n * (nodes mounted, a node resized) tells it only when the measurement changed it (its node's box or\n * measured state, its edge's path), not every node and edge on screen\n */\nexport interface FlowEntity {\n readonly kind: \"node\" | \"edge\";\n readonly id: string;\n}\n\ntype Listener = () => void;\n\n/** @internal the shared subscription of one model (and engine, once there is one) */\nexport interface FlowStore {\n /** a number that changes whenever a value of `scope` (of `entity`) may have changed */\n readonly version: (scope: FlowValueScope, entity?: FlowEntity) => number;\n /** calls `listener` when a value of `scope` (of `entity`) may have changed; returns its remover */\n readonly subscribe: (\n scope: FlowValueScope,\n listener: Listener,\n entity?: FlowEntity,\n ) => () => void;\n}\n\nconst stores = new WeakMap<object, FlowStore>();\n\n/**\n * @internal the store of a model and its engine (the model alone before the engine), made once\n * and shared by every reader of the root. It listens to the engine from its creation on, and to\n * the model while it has a reader (catching up on the lists when it starts again, or when read\n * without one), so its versions are never stale and an unmounted root is not kept by its model.\n */\nexport function flowStoreOf(\n model: AnyFlowModel,\n engine: AnyFlowEngine | null,\n): FlowStore {\n const key: object = engine ?? model;\n let store = stores.get(key);\n if (!store) {\n store = createFlowStore(model, engine);\n stores.set(key, store);\n }\n return store;\n}\n\n/** One node's or edge's readers, and what a measurement may change of it. */\ninterface EntityRecord {\n readonly entity: FlowEntity;\n readonly listeners: Set<Listener>;\n /** the stamp of its last change told by a measurement */\n stamp: number;\n /**\n * its node's box and measured state, or its edge's path (frozen, the same until changed), as\n * of the last measurement; none after any other change (read again at the next measurement,\n * which then tells it)\n */\n token: readonly unknown[] | undefined;\n}\n\nfunction createFlowStore(\n model: AnyFlowModel,\n engine: AnyFlowEngine | null,\n): FlowStore {\n // every change takes the next stamp; a version is the stamp of the last change it covers\n let stamp = 0;\n let viewStamp = 0;\n /** the last change of every node and edge (the lists, a gesture, several levels) */\n let entityStamp = 0;\n /** the last change that was only a measurement: what every reader without an entity hears */\n let measureStamp = 0;\n const listeners: Record<FlowValueScope, Set<Listener>> = {\n view: new Set(),\n entity: new Set(),\n };\n const records = new Map<string, EntityRecord>();\n const keyOf = (entity: FlowEntity) => `${entity.kind}\\u0000${entity.id}`;\n const tokenOf = ({ kind, id }: FlowEntity): readonly unknown[] =>\n !engine\n ? []\n : kind === \"node\"\n ? [\n engine.get(\"node-rect-by\", { nodeId: id }),\n engine.is(\"node-measured\", { nodeId: id }),\n ]\n : [engine.get(\"edge-path-by\", { edgeId: id })];\n const call = (set: Iterable<Listener>) => {\n for (const listener of [...set]) listener();\n };\n\n /** A change: of the view only, only a measurement, or of everything. */\n const tell = (kind: \"view\" | \"measured\" | \"entity\") => {\n stamp += 1;\n viewStamp = stamp;\n call(listeners.view);\n if (kind === \"view\") return;\n if (kind === \"entity\") {\n entityStamp = stamp;\n call(listeners.entity);\n for (const record of records.values()) {\n record.token = undefined;\n call(record.listeners);\n }\n return;\n }\n measureStamp = stamp;\n call(listeners.entity);\n const changed: EntityRecord[] = [];\n for (const record of records.values()) {\n const token = tokenOf(record.entity);\n const was = record.token;\n const same =\n was !== undefined &&\n token.length === was.length &&\n token.every((value, i) => Object.is(value, was[i]));\n if (same) continue;\n record.token = token;\n record.stamp = stamp;\n changed.push(record);\n }\n for (const record of changed) call(record.listeners);\n };\n\n // a commit that keeps both lists changes nothing a reader reads. The store listens to the\n // model only while it has a reader, so that an unmounted root (its engine destroyed, an\n // app-owned model living on) is not kept alive by the model; when it listens again, a change\n // of the lists in between counts as a change, and so it does for a read in between.\n let nodes = model.get(\"all-nodes\");\n let edges = model.get(\"all-edges\");\n /** whether the lists changed since last seen, now seen */\n const listsChanged = () => {\n const nextNodes = model.get(\"all-nodes\");\n const nextEdges = model.get(\"all-edges\");\n if (nextNodes === nodes && nextEdges === edges) return false;\n nodes = nextNodes;\n edges = nextEdges;\n return true;\n };\n /** the model's listener's remover, while there is a reader */\n let stopModel: (() => void) | undefined;\n let readers = 0;\n /** a change of the lists seen with no one to tell: only the versions move */\n const catchUp = () => {\n if (!listsChanged()) return;\n stamp += 1;\n viewStamp = stamp;\n entityStamp = stamp;\n for (const record of records.values()) record.token = undefined;\n };\n const join = () => {\n readers += 1;\n if (stopModel) return;\n catchUp();\n stopModel = model.subscribe(() => {\n if (listsChanged()) tell(\"entity\");\n });\n };\n const leave = () => {\n readers -= 1;\n if (readers > 0 || !stopModel) return;\n stopModel();\n stopModel = undefined;\n };\n\n if (engine) {\n // several render levels give the nodes ranks that follow the drawn edges, so the view\n const layered = () => engine.get(\"render-layers\").length > 1;\n let wasLayered = layered();\n engine.adapter.subscribe((change: ViewChange) => {\n const isLayered = layered();\n const levels = isLayered || wasLayered;\n wasLayered = isLayered;\n if (change.gesture || levels) tell(\"entity\");\n else if (change.measured)\n tell(change.viewport ? \"entity\" : \"measured\");\n else tell(\"view\");\n });\n }\n\n return {\n version: (scope, entity) => {\n if (!stopModel) catchUp();\n if (scope === \"view\") return viewStamp;\n const record = entity ? records.get(keyOf(entity)) : undefined;\n return Math.max(entityStamp, record ? record.stamp : measureStamp);\n },\n subscribe: (scope, listener, entity) => {\n if (scope === \"view\" || !entity) {\n const set = listeners[scope];\n if (set.has(listener)) return () => {};\n set.add(listener);\n join();\n return () => {\n if (set.delete(listener)) leave();\n };\n }\n const key = keyOf(entity);\n let record = records.get(key);\n if (!record) {\n // the last measurement counts as its change: a reader that read before it\n // subscribed (its render) reads again if a measurement came in between\n record = {\n entity,\n listeners: new Set(),\n stamp: measureStamp,\n token: tokenOf(entity),\n };\n records.set(key, record);\n }\n const own = record;\n if (own.listeners.has(listener)) return () => {};\n own.listeners.add(listener);\n join();\n return () => {\n if (!own.listeners.delete(listener)) return;\n if (own.listeners.size === 0 && records.get(key) === own) {\n records.delete(key);\n }\n leave();\n };\n },\n };\n}\n","// From Splitter (fragiola/splitter, packages/react/src/utils/shallow-equal.ts), same author and\n// licence; nested records compared one level down (a part's attributes, its rect).\n\nfunction same(a: unknown, b: unknown): boolean {\n if (Object.is(a, b)) return true;\n if (\n typeof a !== \"object\" ||\n typeof b !== \"object\" ||\n a === null ||\n b === null ||\n Array.isArray(a) !== Array.isArray(b)\n ) {\n return false;\n }\n const aRecord = a as Readonly<Record<string, unknown>>;\n const bRecord = b as Readonly<Record<string, unknown>>;\n const keys = Object.keys(aRecord);\n return (\n keys.length === Object.keys(bRecord).length &&\n keys.every(\n (key) =>\n Object.hasOwn(bRecord, key) &&\n Object.is(aRecord[key], bRecord[key]),\n )\n );\n}\n\n/**\n * Whether two records (a part's state) hold the same values, a nested record or array compared by\n * its own entries: what decides that a part does not re-render.\n */\nexport function shallowEqual(\n a: Readonly<Record<string, unknown>> | undefined,\n b: Readonly<Record<string, unknown>> | undefined,\n): boolean {\n if (a === b) return true;\n if (!a || !b) return false;\n const keys = Object.keys(a);\n return (\n keys.length === Object.keys(b).length &&\n keys.every((key) => Object.hasOwn(b, key) && same(a[key], b[key]))\n );\n}\n","// The hooks and helpers only the primitives call.\nimport * as React from \"react\";\nimport type { AnyFlowEngine, AnyFlowModel } from \"../context\";\nimport {\n type FlowEntity,\n type FlowStore,\n type FlowValueScope,\n flowStoreOf,\n} from \"../utils/flow-store\";\nimport { shallowEqual } from \"../utils/shallow-equal\";\n\n/** @internal `useLayoutEffect` in a browser, nothing on the server (where it would warn) */\nexport const useIsomorphicLayoutEffect =\n typeof document === \"undefined\" ? () => {} : React.useLayoutEffect;\n\n/** @internal two values the same for re-rendering: records compared by their entries */\nexport function sameValue<S>(a: S, b: S): boolean {\n if (Object.is(a, b)) return true;\n if (\n typeof a === \"object\" &&\n typeof b === \"object\" &&\n a !== null &&\n b !== null &&\n !Array.isArray(a) &&\n !Array.isArray(b)\n ) {\n return shallowEqual(\n a as Readonly<Record<string, unknown>>,\n b as Readonly<Record<string, unknown>>,\n );\n }\n if (Array.isArray(a) && Array.isArray(b)) {\n return (\n a.length === b.length &&\n a.every((value, i) => Object.is(value, b[i]))\n );\n }\n return false;\n}\n\n/**\n * @internal a value read from the model and the engine, re-rendering the component only when it\n * changes (`isEqual`; records by their entries by default). It is read again on every change of\n * the model's lists and every view change of the engine (`engine.adapter`: measurements, the\n * viewport, a gesture) that may concern its `scope` (`entity`: a node's or an edge's own view, not\n * read again on a viewport step; given its node or edge, not on a measurement that leaves it\n * alone), and on every render (the reader may close over props); a value\n * equal to the last one keeps the last object. Every reader of a root shares one subscription\n * (`flowStoreOf`).\n */\nexport function useFlowValue<S>(\n model: AnyFlowModel,\n engine: AnyFlowEngine | null,\n read: () => S,\n isEqual: (a: S, b: S) => boolean = sameValue,\n scope: FlowValueScope = \"view\",\n entity?: FlowEntity,\n): S {\n const latest = React.useRef({ read, isEqual });\n latest.current = { read, isEqual };\n const cache = React.useRef<\n | {\n store: FlowStore;\n version: number;\n read: () => S;\n value: S;\n }\n | undefined\n >(undefined);\n const store = flowStoreOf(model, engine);\n const kind = entity?.kind;\n const id = entity?.id;\n const subscribe = React.useCallback(\n (onChange: () => void) =>\n store.subscribe(\n scope,\n onChange,\n kind === undefined || id === undefined\n ? undefined\n : { kind, id },\n ),\n [store, scope, kind, id],\n );\n const getSnapshot = (): S => {\n const version = store.version(scope, entity);\n const previous = cache.current;\n if (\n previous?.store === store &&\n previous.version === version &&\n previous.read === latest.current.read\n ) {\n return previous.value;\n }\n const value = latest.current.read();\n const kept =\n previous !== undefined &&\n latest.current.isEqual(previous.value, value)\n ? previous.value\n : value;\n cache.current = {\n store,\n version,\n read: latest.current.read,\n value: kept,\n };\n return kept;\n };\n return React.useSyncExternalStore(subscribe, getSnapshot, getSnapshot);\n}\n","// From Dockable (fragiola/dockable, packages/react/src/utils/merge-props.ts), same author and licence.\ntype AnyProps = Record<string, unknown>;\n\nfunction isHandler(\n key: string,\n value: unknown,\n): value is (...args: unknown[]) => void {\n return /^on[A-Z]/.test(key) && typeof value === \"function\";\n}\n\n/**\n * Merges `external` props over `internal` ones: plain props from `external` win, event handlers\n * are composed (internal first, then external) and class names are joined.\n */\nexport function mergeProps(internal: AnyProps, external: AnyProps): AnyProps {\n const merged: AnyProps = { ...internal };\n for (const [key, value] of Object.entries(external)) {\n const current = merged[key];\n if (value === undefined) {\n continue;\n }\n if (isHandler(key, value) && isHandler(key, current)) {\n merged[key] = (...args: unknown[]) => {\n current(...args);\n value(...args);\n };\n } else if (\n key === \"className\" &&\n typeof current === \"string\" &&\n typeof value === \"string\"\n ) {\n merged.className = `${current} ${value}`;\n } else {\n merged[key] = value;\n }\n }\n return merged;\n}\n","// From Splitter (fragiola/splitter, packages/react/src/utils/use-render.ts), same author and\n// licence; generic over the element (Flow's edges are SVG), with a default style the consumer's\n// overrides (`baseStyle`: a handle's place on its node's side).\nimport * as React from \"react\";\nimport { mergeProps } from \"./merge-props\";\n\n/** A callback ref that forwards to every ref in `refs` (function refs and ref objects alike). */\nfunction mergeRefs<T>(\n ...refs: (React.Ref<T> | undefined)[]\n): React.RefCallback<T> {\n return (value) => {\n const cleanups = refs.map((ref) => {\n if (typeof ref === \"function\") {\n const cleanup = ref(value);\n return typeof cleanup === \"function\"\n ? cleanup\n : () => ref(null);\n }\n if (ref) {\n ref.current = value;\n return () => {\n ref.current = null;\n };\n }\n return undefined;\n });\n return () => {\n for (const cleanup of cleanups) {\n cleanup?.();\n }\n };\n };\n}\n\n/**\n * Props a `render` function receives: spread them onto the element it returns. `ref` is a callback\n * ref, so it fits any element's `ref` (`render={(props) => <section {...props} />}` needs no cast).\n */\nexport type RenderedProps<E extends Element = HTMLElement> =\n (E extends SVGElement\n ? React.SVGAttributes<E>\n : React.HTMLAttributes<E>) & {\n ref: React.RefCallback<E>;\n [dataAttribute: `data-${string}`]: string | undefined;\n };\n\n/**\n * Replaces the element a primitive renders, Base UI style: either an element whose props are\n * merged with the primitive's (`render={<section />}`), or a function receiving the props and\n * the primitive's state (`render={(props, state) => <section {...props} />}`).\n */\nexport type RenderProp<State, E extends Element = HTMLElement> =\n | React.ReactElement\n | ((props: RenderedProps<E>, state: State) => React.ReactElement);\n\n/** The props every primitive accepts on top of the element's own. */\nexport interface PrimitiveProps<State, E extends Element = HTMLElement> {\n /** replaces the rendered element (never `asChild`) */\n render?: RenderProp<State, E> | undefined;\n /** a class name, or a function of the primitive's state returning one */\n className?: string | ((state: State) => string | undefined) | undefined;\n /**\n * a style, or a function of the primitive's state returning one. Structural keys the\n * primitive sets (position, its place, its size) always win.\n */\n style?:\n | React.CSSProperties\n | ((state: State) => React.CSSProperties | undefined)\n | undefined;\n ref?: React.Ref<E> | undefined;\n}\n\n/** The props of a primitive that renders a `div` by default. */\nexport type DivPrimitiveProps<State> = PrimitiveProps<State, HTMLDivElement> &\n Omit<React.HTMLAttributes<HTMLDivElement>, \"className\" | \"style\">;\n\n/** The props of a primitive that renders a `button` by default. */\nexport type ButtonPrimitiveProps<State> = PrimitiveProps<\n State,\n HTMLButtonElement\n> &\n Omit<React.ButtonHTMLAttributes<HTMLButtonElement>, \"className\" | \"style\">;\n\n/** The props of a primitive that renders an SVG element `E` by default. */\nexport type SvgPrimitiveProps<State, E extends SVGElement> = PrimitiveProps<\n State,\n E\n> &\n Omit<React.SVGAttributes<E>, \"className\" | \"style\">;\n\n/** A part's `data-*` attributes, as a hook's `props` carry them. */\nexport type DataAttributes = {\n readonly [name: `data-${string}`]: string | undefined;\n};\n\ntype AnyProps = Record<string, unknown>;\n\n/** A part's attributes as React props: its `data-*` and, when it takes focus, `tabIndex`. */\nexport type AttributeProps = DataAttributes & {\n readonly tabIndex?: number | undefined;\n};\n\n/**\n * A part's attributes from the engine (`engine.adapter.attributes`) as React props: the record\n * holds DOM attribute names, and React takes `tabindex` as `tabIndex` (a number; it warns on the\n * lowercase name). The one place an engine record becomes props.\n */\nexport function attributeProps(\n attributes: Readonly<Record<string, string | undefined>>,\n): AttributeProps {\n const { tabindex, ...rest } = attributes;\n return tabindex === undefined\n ? (rest as DataAttributes)\n : { ...(rest as DataAttributes), tabIndex: Number(tabindex) };\n}\n\ninterface RenderOptions<State> {\n state: State;\n /** the primitive's own props: ARIA, data-*, handlers, children */\n props: Record<string, unknown>;\n /** the primitive's ref, merged with the consumer's */\n ref?: React.Ref<Element> | undefined;\n /** structural style: always wins over the consumer's */\n style?: React.CSSProperties | undefined;\n /** a default style the consumer's overrides */\n baseStyle?: React.CSSProperties | undefined;\n}\n\n/**\n * Renders a primitive's element: resolves `className`/`style` functions against the state,\n * merges the consumer's props over the primitive's (handlers composed, internal first; structural\n * style keys win), merges refs, and applies `render`.\n */\nexport function useRenderElement<State, E extends Element>(\n tag: keyof React.JSX.IntrinsicElements,\n componentProps: PrimitiveProps<State, E>,\n options: RenderOptions<State>,\n): React.JSX.Element {\n const {\n render,\n className,\n style,\n ref: externalRef,\n ...external\n } = componentProps as PrimitiveProps<State, E> & AnyProps;\n const internalRef = options.ref as React.Ref<E> | undefined;\n // the render element's own ref joins the merge; memoized so React does not detach and\n // re-attach the refs (and the primitive's registrations) on every render\n const renderElement =\n render && typeof render !== \"function\"\n ? (render as React.ReactElement<AnyProps>)\n : undefined;\n const elementRef = renderElement?.props.ref as React.Ref<E> | undefined;\n // consumer refs are read when the element attaches, not memoized on their identity: an inline\n // callback ref (a new function each render) must not make React detach and re-attach the\n // primitive's own ref (and its registrations) on every render\n const consumerRefs = React.useRef<(React.Ref<E> | undefined)[]>([]);\n consumerRefs.current = [externalRef, elementRef];\n // (a consumer ref that appears later re-attaches once, so it is called)\n const hasConsumerRef = externalRef != null || elementRef != null;\n const ref = React.useMemo<React.RefCallback<E>>(\n () => (element: E | null) =>\n mergeRefs(\n internalRef,\n ...(hasConsumerRef ? consumerRefs.current : []),\n )(element),\n [internalRef, hasConsumerRef],\n );\n\n const resolvedClassName =\n typeof className === \"function\" ? className(options.state) : className;\n const resolvedStyle =\n typeof style === \"function\" ? style(options.state) : style;\n\n const props = mergeProps(options.props, external);\n if (resolvedClassName !== undefined) {\n props.className = resolvedClassName;\n }\n if (resolvedStyle || options.style || options.baseStyle) {\n props.style = {\n ...options.baseStyle,\n ...resolvedStyle,\n ...options.style,\n };\n }\n props.ref = ref;\n\n if (typeof render === \"function\") {\n return render(props as unknown as RenderedProps<E>, options.state);\n }\n if (renderElement) {\n const elementProps = renderElement.props;\n const merged = mergeProps(props, elementProps);\n if (elementProps.style || props.style) {\n merged.style = {\n ...options.baseStyle,\n ...(elementProps.style as React.CSSProperties),\n ...resolvedStyle,\n ...options.style,\n };\n }\n merged.ref = ref;\n return React.cloneElement(renderElement, merged);\n }\n return React.createElement(tag, props);\n}\n"],"mappings":";;AAwCA,MAAa,cAAc,MAAM,cAAuC,IA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HANGED
@@ -1,6 +1,109 @@
1
1
  {
2
2
  "name": "@fragiola/flow-react",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "version": "0.0.0",
4
+ "description": "Composable, unstyled React primitives for @fragiola/flow: node-based editors and diagrams (nodes, edges, handles, connections, a pannable and zoomable viewport) styled entirely by you.",
5
+ "keywords": [
6
+ "react",
7
+ "flow",
8
+ "node-editor",
9
+ "diagram",
10
+ "graph",
11
+ "headless"
12
+ ],
13
+ "license": "MIT",
14
+ "type": "module",
15
+ "author": {
16
+ "name": "Mauro de Souza",
17
+ "email": "maurodesouza.me@gmail.com",
18
+ "url": "https://github.com/maurodesouza"
19
+ },
20
+ "repository": {
21
+ "type": "git",
22
+ "url": "git+https://github.com/fragiola/flow.git",
23
+ "directory": "packages/react"
24
+ },
25
+ "homepage": "https://fragiola.com/flow",
26
+ "bugs": {
27
+ "url": "https://github.com/fragiola/flow/issues"
28
+ },
29
+ "sideEffects": false,
30
+ "exports": {
31
+ ".": {
32
+ "types": "./dist/index.d.ts",
33
+ "import": "./dist/index.js",
34
+ "default": "./dist/index.js"
35
+ },
36
+ "./selection": {
37
+ "types": "./dist/selection.d.ts",
38
+ "import": "./dist/selection.js",
39
+ "default": "./dist/selection.js"
40
+ },
41
+ "./subflows": {
42
+ "types": "./dist/subflows.d.ts",
43
+ "import": "./dist/subflows.js",
44
+ "default": "./dist/subflows.js"
45
+ },
46
+ "./drag": {
47
+ "types": "./dist/drag.d.ts",
48
+ "import": "./dist/drag.js",
49
+ "default": "./dist/drag.js"
50
+ },
51
+ "./resize": {
52
+ "types": "./dist/resize.d.ts",
53
+ "import": "./dist/resize.js",
54
+ "default": "./dist/resize.js"
55
+ },
56
+ "./connection": {
57
+ "types": "./dist/connection.d.ts",
58
+ "import": "./dist/connection.js",
59
+ "default": "./dist/connection.js"
60
+ },
61
+ "./reconnection": {
62
+ "types": "./dist/reconnection.d.ts",
63
+ "import": "./dist/reconnection.js",
64
+ "default": "./dist/reconnection.js"
65
+ },
66
+ "./keyboard": {
67
+ "types": "./dist/keyboard.d.ts",
68
+ "import": "./dist/keyboard.js",
69
+ "default": "./dist/keyboard.js"
70
+ },
71
+ "./minimap": {
72
+ "types": "./dist/minimap.d.ts",
73
+ "import": "./dist/minimap.js",
74
+ "default": "./dist/minimap.js"
75
+ },
76
+ "./package.json": "./package.json"
77
+ },
78
+ "files": [
79
+ "dist",
80
+ "README.md",
81
+ "LICENSE"
82
+ ],
83
+ "dependencies": {
84
+ "@fragiola/flow": "0.0.0"
85
+ },
86
+ "peerDependencies": {
87
+ "react": "^19.0.0",
88
+ "react-dom": "^19.0.0"
89
+ },
90
+ "devDependencies": {
91
+ "@testing-library/dom": "10.4.2",
92
+ "@testing-library/jest-dom": "7.0.1",
93
+ "@testing-library/react": "16.3.3",
94
+ "@types/react": "19.3.0",
95
+ "@types/react-dom": "19.3.0",
96
+ "jsdom": "30.1.1",
97
+ "react": "19.3.0",
98
+ "react-dom": "19.3.0",
99
+ "tsdown": "0.23.0",
100
+ "typescript": "7.0.2",
101
+ "vite": "8.3.1",
102
+ "vitest": "5.0.2"
103
+ },
104
+ "scripts": {
105
+ "build": "tsdown",
106
+ "typecheck": "tsc --noEmit",
107
+ "test": "vitest run"
108
+ }
6
109
  }