@ai-matrx/canvas 0.2.2 → 0.3.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 +8 -0
- package/README.md +11 -0
- package/dist/index.cjs +42 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +42 -1
- package/dist/index.js.map +1 -1
- package/dist/react.cjs +50 -0
- package/dist/react.cjs.map +1 -1
- package/dist/react.d.cts +12 -2
- package/dist/react.d.ts +12 -2
- package/dist/react.js +50 -0
- package/dist/react.js.map +1 -1
- package/dist/{controller-Dv6J6XZm.d.cts → toggleKind-A9v45oSb.d.cts} +30 -1
- package/dist/{controller-Dv6J6XZm.d.ts → toggleKind-A9v45oSb.d.ts} +30 -1
- package/package.json +1 -1
package/dist/react.d.cts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as react from 'react';
|
|
2
2
|
import { ComponentType, ReactNode, CSSProperties, ButtonHTMLAttributes, HTMLAttributes, ReactElement } from 'react';
|
|
3
|
-
import {
|
|
3
|
+
import { F as CanvasRect, d as CanvasPaneId, C as CanvasItemId, a as CanvasWindowId, b as CanvasJson, i as CanvasItem, h as CanvasController, I as CanvasSessionEvent, G as CanvasSessionAttachReason, H as CanvasSessionDetachReason, e as CanvasStoreBinding, E as CanvasPersistencePort, w as CanvasErrorSink, z as CanvasLayoutRules, T as ToggleKindInput, y as CanvasKindVisibility, f as CanvasState } from './toggleKind-A9v45oSb.cjs';
|
|
4
4
|
|
|
5
5
|
/** One floating thing. Plain data, so a host can draw it in another process. */
|
|
6
6
|
type CanvasFloating = {
|
|
@@ -230,6 +230,16 @@ declare function useCanvasState<T>(selector: (state: CanvasState) => T): T;
|
|
|
230
230
|
* embed). `fallback` must be referentially stable (a primitive or null).
|
|
231
231
|
*/
|
|
232
232
|
declare function useOptionalCanvasState<T>(selector: (state: CanvasState) => T, fallback: T): T;
|
|
233
|
+
/**
|
|
234
|
+
* A toolbar icon's view of one kind: "absent" | "background" | "visible"
|
|
235
|
+
* (a primitive, so it never loops), plus the click that toggles or focuses it.
|
|
236
|
+
*/
|
|
237
|
+
declare function useCanvasKindToggle(input: ToggleKindInput): {
|
|
238
|
+
readonly visibility: CanvasKindVisibility;
|
|
239
|
+
readonly isOpen: boolean;
|
|
240
|
+
readonly isVisible: boolean;
|
|
241
|
+
readonly toggle: () => CanvasKindVisibility;
|
|
242
|
+
};
|
|
233
243
|
/** Re-renders when kinds register, so late-registered kinds appear. */
|
|
234
244
|
declare function useCanvasKinds(): readonly AnyCanvasKind[];
|
|
235
245
|
declare function useCanvasKind(id: string): AnyCanvasKind | undefined;
|
|
@@ -372,4 +382,4 @@ interface BrowserBarProps {
|
|
|
372
382
|
/** A browser's back · forward · reload · address bar, for a kind's leading slot or its body. */
|
|
373
383
|
declare function BrowserBar({ url, canGoBack, canGoForward, onBack, onForward, onReload, onNavigate, trailing, className }: BrowserBarProps): react.JSX.Element;
|
|
374
384
|
|
|
375
|
-
export { type AnyCanvasKind, BrowserBar, type BrowserBarProps, type BrowserTab, BrowserTabs, type BrowserTabsProps, CanvasColumn, type CanvasColumnProps, type CanvasFloating, CanvasFrame, CanvasHeaderButton, type CanvasHeaderButtonProps, type CanvasHostPorts, type CanvasKind, type CanvasKindProps, type CanvasMenuEntry, type CanvasMenuItem, CanvasMenuTrigger, type CanvasNativeBodyFrame, type CanvasNativeBodyInfo, type CanvasNativeRect, type CanvasOverlayPort, CanvasPaneView, CanvasPanel, CanvasPanelEmpty, type CanvasPanelProps, CanvasProvider, type CanvasProviderProps, type CanvasShowMenu, CanvasTab, type CanvasTabProps, type CanvasTabStripMode, CanvasToggle, CanvasWindowScope, canvasSessionKey, defineCanvasKind, getCanvasKind, itemTitle, listCanvasKinds, registerCanvasKind, registerCanvasKinds, useCanvas, useCanvasColumnWidth, useCanvasHostPorts, useCanvasIsPresented, useCanvasKind, useCanvasKinds, useCanvasNativeBodies, useCanvasState, useCanvasWindowId, useOptionalCanvas, useOptionalCanvasState };
|
|
385
|
+
export { type AnyCanvasKind, BrowserBar, type BrowserBarProps, type BrowserTab, BrowserTabs, type BrowserTabsProps, CanvasColumn, type CanvasColumnProps, type CanvasFloating, CanvasFrame, CanvasHeaderButton, type CanvasHeaderButtonProps, type CanvasHostPorts, type CanvasKind, type CanvasKindProps, type CanvasMenuEntry, type CanvasMenuItem, CanvasMenuTrigger, type CanvasNativeBodyFrame, type CanvasNativeBodyInfo, type CanvasNativeRect, type CanvasOverlayPort, CanvasPaneView, CanvasPanel, CanvasPanelEmpty, type CanvasPanelProps, CanvasProvider, type CanvasProviderProps, type CanvasShowMenu, CanvasTab, type CanvasTabProps, type CanvasTabStripMode, CanvasToggle, CanvasWindowScope, canvasSessionKey, defineCanvasKind, getCanvasKind, itemTitle, listCanvasKinds, registerCanvasKind, registerCanvasKinds, useCanvas, useCanvasColumnWidth, useCanvasHostPorts, useCanvasIsPresented, useCanvasKind, useCanvasKindToggle, useCanvasKinds, useCanvasNativeBodies, useCanvasState, useCanvasWindowId, useOptionalCanvas, useOptionalCanvasState };
|
package/dist/react.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as react from 'react';
|
|
2
2
|
import { ComponentType, ReactNode, CSSProperties, ButtonHTMLAttributes, HTMLAttributes, ReactElement } from 'react';
|
|
3
|
-
import {
|
|
3
|
+
import { F as CanvasRect, d as CanvasPaneId, C as CanvasItemId, a as CanvasWindowId, b as CanvasJson, i as CanvasItem, h as CanvasController, I as CanvasSessionEvent, G as CanvasSessionAttachReason, H as CanvasSessionDetachReason, e as CanvasStoreBinding, E as CanvasPersistencePort, w as CanvasErrorSink, z as CanvasLayoutRules, T as ToggleKindInput, y as CanvasKindVisibility, f as CanvasState } from './toggleKind-A9v45oSb.js';
|
|
4
4
|
|
|
5
5
|
/** One floating thing. Plain data, so a host can draw it in another process. */
|
|
6
6
|
type CanvasFloating = {
|
|
@@ -230,6 +230,16 @@ declare function useCanvasState<T>(selector: (state: CanvasState) => T): T;
|
|
|
230
230
|
* embed). `fallback` must be referentially stable (a primitive or null).
|
|
231
231
|
*/
|
|
232
232
|
declare function useOptionalCanvasState<T>(selector: (state: CanvasState) => T, fallback: T): T;
|
|
233
|
+
/**
|
|
234
|
+
* A toolbar icon's view of one kind: "absent" | "background" | "visible"
|
|
235
|
+
* (a primitive, so it never loops), plus the click that toggles or focuses it.
|
|
236
|
+
*/
|
|
237
|
+
declare function useCanvasKindToggle(input: ToggleKindInput): {
|
|
238
|
+
readonly visibility: CanvasKindVisibility;
|
|
239
|
+
readonly isOpen: boolean;
|
|
240
|
+
readonly isVisible: boolean;
|
|
241
|
+
readonly toggle: () => CanvasKindVisibility;
|
|
242
|
+
};
|
|
233
243
|
/** Re-renders when kinds register, so late-registered kinds appear. */
|
|
234
244
|
declare function useCanvasKinds(): readonly AnyCanvasKind[];
|
|
235
245
|
declare function useCanvasKind(id: string): AnyCanvasKind | undefined;
|
|
@@ -372,4 +382,4 @@ interface BrowserBarProps {
|
|
|
372
382
|
/** A browser's back · forward · reload · address bar, for a kind's leading slot or its body. */
|
|
373
383
|
declare function BrowserBar({ url, canGoBack, canGoForward, onBack, onForward, onReload, onNavigate, trailing, className }: BrowserBarProps): react.JSX.Element;
|
|
374
384
|
|
|
375
|
-
export { type AnyCanvasKind, BrowserBar, type BrowserBarProps, type BrowserTab, BrowserTabs, type BrowserTabsProps, CanvasColumn, type CanvasColumnProps, type CanvasFloating, CanvasFrame, CanvasHeaderButton, type CanvasHeaderButtonProps, type CanvasHostPorts, type CanvasKind, type CanvasKindProps, type CanvasMenuEntry, type CanvasMenuItem, CanvasMenuTrigger, type CanvasNativeBodyFrame, type CanvasNativeBodyInfo, type CanvasNativeRect, type CanvasOverlayPort, CanvasPaneView, CanvasPanel, CanvasPanelEmpty, type CanvasPanelProps, CanvasProvider, type CanvasProviderProps, type CanvasShowMenu, CanvasTab, type CanvasTabProps, type CanvasTabStripMode, CanvasToggle, CanvasWindowScope, canvasSessionKey, defineCanvasKind, getCanvasKind, itemTitle, listCanvasKinds, registerCanvasKind, registerCanvasKinds, useCanvas, useCanvasColumnWidth, useCanvasHostPorts, useCanvasIsPresented, useCanvasKind, useCanvasKinds, useCanvasNativeBodies, useCanvasState, useCanvasWindowId, useOptionalCanvas, useOptionalCanvasState };
|
|
385
|
+
export { type AnyCanvasKind, BrowserBar, type BrowserBarProps, type BrowserTab, BrowserTabs, type BrowserTabsProps, CanvasColumn, type CanvasColumnProps, type CanvasFloating, CanvasFrame, CanvasHeaderButton, type CanvasHeaderButtonProps, type CanvasHostPorts, type CanvasKind, type CanvasKindProps, type CanvasMenuEntry, type CanvasMenuItem, CanvasMenuTrigger, type CanvasNativeBodyFrame, type CanvasNativeBodyInfo, type CanvasNativeRect, type CanvasOverlayPort, CanvasPaneView, CanvasPanel, CanvasPanelEmpty, type CanvasPanelProps, CanvasProvider, type CanvasProviderProps, type CanvasShowMenu, CanvasTab, type CanvasTabProps, type CanvasTabStripMode, CanvasToggle, CanvasWindowScope, canvasSessionKey, defineCanvasKind, getCanvasKind, itemTitle, listCanvasKinds, registerCanvasKind, registerCanvasKinds, useCanvas, useCanvasColumnWidth, useCanvasHostPorts, useCanvasIsPresented, useCanvasKind, useCanvasKindToggle, useCanvasKinds, useCanvasNativeBodies, useCanvasState, useCanvasWindowId, useOptionalCanvas, useOptionalCanvasState };
|
package/dist/react.js
CHANGED
|
@@ -1220,6 +1220,44 @@ function selectCanvasWindowItemCount(s, windowId) {
|
|
|
1220
1220
|
}
|
|
1221
1221
|
var NO_WINDOWS = Object.freeze({});
|
|
1222
1222
|
|
|
1223
|
+
// src/core/toggleKind.ts
|
|
1224
|
+
var CANVAS_DEFAULT_KEY = "default";
|
|
1225
|
+
function selectCanvasKindVisibility(state, kind, key = CANVAS_DEFAULT_KEY) {
|
|
1226
|
+
const itemId = canvasItemId(kind, key);
|
|
1227
|
+
if (!state.items[itemId]) return "absent";
|
|
1228
|
+
const windowId = canvasWindowOfItem(state, itemId);
|
|
1229
|
+
if (!windowId) return "background";
|
|
1230
|
+
const isOpen = canvasWindowFrame(state, windowId)?.isOpen ?? false;
|
|
1231
|
+
const pane = Object.values(state.panes).find((p) => p.itemIds.includes(itemId));
|
|
1232
|
+
return isOpen && pane?.activeItemId === itemId ? "visible" : "background";
|
|
1233
|
+
}
|
|
1234
|
+
function toggleKind(controller, input) {
|
|
1235
|
+
const key = input.key ?? CANVAS_DEFAULT_KEY;
|
|
1236
|
+
const itemId = canvasItemId(input.kind, key);
|
|
1237
|
+
const before = selectCanvasKindVisibility(controller.getState(), input.kind, key);
|
|
1238
|
+
if (before === "visible") {
|
|
1239
|
+
if ((input.whenVisible ?? "close") === "close") {
|
|
1240
|
+
controller.close(itemId);
|
|
1241
|
+
} else {
|
|
1242
|
+
controller.hide(canvasWindowOfItem(controller.getState(), itemId) ?? void 0);
|
|
1243
|
+
}
|
|
1244
|
+
return selectCanvasKindVisibility(controller.getState(), input.kind, key);
|
|
1245
|
+
}
|
|
1246
|
+
if (before === "background") {
|
|
1247
|
+
controller.open({ kind: input.kind, key });
|
|
1248
|
+
const windowId = canvasWindowOfItem(controller.getState(), itemId);
|
|
1249
|
+
if (windowId) controller.show(windowId);
|
|
1250
|
+
return selectCanvasKindVisibility(controller.getState(), input.kind, key);
|
|
1251
|
+
}
|
|
1252
|
+
const opened = controller.open({
|
|
1253
|
+
kind: input.kind,
|
|
1254
|
+
key,
|
|
1255
|
+
...input.data !== void 0 ? { data: input.data } : {},
|
|
1256
|
+
...input.title !== void 0 ? { title: input.title } : {}
|
|
1257
|
+
});
|
|
1258
|
+
return opened ? selectCanvasKindVisibility(controller.getState(), input.kind, key) : "absent";
|
|
1259
|
+
}
|
|
1260
|
+
|
|
1223
1261
|
// src/react/layer.tsx
|
|
1224
1262
|
import { useEffect, useLayoutEffect, useRef, useState, useSyncExternalStore } from "react";
|
|
1225
1263
|
import { createPortal } from "react-dom";
|
|
@@ -1519,6 +1557,17 @@ function useOptionalCanvasState(selector, fallback) {
|
|
|
1519
1557
|
const read = () => store ? selector(store.getState()) : fallback;
|
|
1520
1558
|
return useSyncExternalStore2(store ? store.subscribe : NO_SUBSCRIPTION, read, read);
|
|
1521
1559
|
}
|
|
1560
|
+
function useCanvasKindToggle(input) {
|
|
1561
|
+
const controller = useCanvasContext().controller;
|
|
1562
|
+
const key = input.key ?? CANVAS_DEFAULT_KEY;
|
|
1563
|
+
const visibility = useCanvasState((s) => selectCanvasKindVisibility(s, input.kind, key));
|
|
1564
|
+
return {
|
|
1565
|
+
visibility,
|
|
1566
|
+
isOpen: visibility !== "absent",
|
|
1567
|
+
isVisible: visibility === "visible",
|
|
1568
|
+
toggle: () => toggleKind(controller, input)
|
|
1569
|
+
};
|
|
1570
|
+
}
|
|
1522
1571
|
function useCanvasKinds() {
|
|
1523
1572
|
useSyncExternalStore2(subscribeCanvasKinds, getCanvasKindsVersion, getCanvasKindsVersion);
|
|
1524
1573
|
return listCanvasKinds();
|
|
@@ -2534,6 +2583,7 @@ export {
|
|
|
2534
2583
|
useCanvasHostPorts,
|
|
2535
2584
|
useCanvasIsPresented,
|
|
2536
2585
|
useCanvasKind,
|
|
2586
|
+
useCanvasKindToggle,
|
|
2537
2587
|
useCanvasKinds,
|
|
2538
2588
|
useCanvasNativeBodies,
|
|
2539
2589
|
useCanvasState,
|