@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.cjs
CHANGED
|
@@ -57,6 +57,7 @@ __export(react_exports, {
|
|
|
57
57
|
useCanvasHostPorts: () => useCanvasHostPorts,
|
|
58
58
|
useCanvasIsPresented: () => useCanvasIsPresented,
|
|
59
59
|
useCanvasKind: () => useCanvasKind,
|
|
60
|
+
useCanvasKindToggle: () => useCanvasKindToggle,
|
|
60
61
|
useCanvasKinds: () => useCanvasKinds,
|
|
61
62
|
useCanvasNativeBodies: () => useCanvasNativeBodies,
|
|
62
63
|
useCanvasState: () => useCanvasState,
|
|
@@ -1278,6 +1279,44 @@ function selectCanvasWindowItemCount(s, windowId) {
|
|
|
1278
1279
|
}
|
|
1279
1280
|
var NO_WINDOWS = Object.freeze({});
|
|
1280
1281
|
|
|
1282
|
+
// src/core/toggleKind.ts
|
|
1283
|
+
var CANVAS_DEFAULT_KEY = "default";
|
|
1284
|
+
function selectCanvasKindVisibility(state, kind, key = CANVAS_DEFAULT_KEY) {
|
|
1285
|
+
const itemId = canvasItemId(kind, key);
|
|
1286
|
+
if (!state.items[itemId]) return "absent";
|
|
1287
|
+
const windowId = canvasWindowOfItem(state, itemId);
|
|
1288
|
+
if (!windowId) return "background";
|
|
1289
|
+
const isOpen = canvasWindowFrame(state, windowId)?.isOpen ?? false;
|
|
1290
|
+
const pane = Object.values(state.panes).find((p) => p.itemIds.includes(itemId));
|
|
1291
|
+
return isOpen && pane?.activeItemId === itemId ? "visible" : "background";
|
|
1292
|
+
}
|
|
1293
|
+
function toggleKind(controller, input) {
|
|
1294
|
+
const key = input.key ?? CANVAS_DEFAULT_KEY;
|
|
1295
|
+
const itemId = canvasItemId(input.kind, key);
|
|
1296
|
+
const before = selectCanvasKindVisibility(controller.getState(), input.kind, key);
|
|
1297
|
+
if (before === "visible") {
|
|
1298
|
+
if ((input.whenVisible ?? "close") === "close") {
|
|
1299
|
+
controller.close(itemId);
|
|
1300
|
+
} else {
|
|
1301
|
+
controller.hide(canvasWindowOfItem(controller.getState(), itemId) ?? void 0);
|
|
1302
|
+
}
|
|
1303
|
+
return selectCanvasKindVisibility(controller.getState(), input.kind, key);
|
|
1304
|
+
}
|
|
1305
|
+
if (before === "background") {
|
|
1306
|
+
controller.open({ kind: input.kind, key });
|
|
1307
|
+
const windowId = canvasWindowOfItem(controller.getState(), itemId);
|
|
1308
|
+
if (windowId) controller.show(windowId);
|
|
1309
|
+
return selectCanvasKindVisibility(controller.getState(), input.kind, key);
|
|
1310
|
+
}
|
|
1311
|
+
const opened = controller.open({
|
|
1312
|
+
kind: input.kind,
|
|
1313
|
+
key,
|
|
1314
|
+
...input.data !== void 0 ? { data: input.data } : {},
|
|
1315
|
+
...input.title !== void 0 ? { title: input.title } : {}
|
|
1316
|
+
});
|
|
1317
|
+
return opened ? selectCanvasKindVisibility(controller.getState(), input.kind, key) : "absent";
|
|
1318
|
+
}
|
|
1319
|
+
|
|
1281
1320
|
// src/react/layer.tsx
|
|
1282
1321
|
var import_react = require("react");
|
|
1283
1322
|
var import_react_dom = require("react-dom");
|
|
@@ -1577,6 +1616,17 @@ function useOptionalCanvasState(selector, fallback) {
|
|
|
1577
1616
|
const read = () => store ? selector(store.getState()) : fallback;
|
|
1578
1617
|
return (0, import_react2.useSyncExternalStore)(store ? store.subscribe : NO_SUBSCRIPTION, read, read);
|
|
1579
1618
|
}
|
|
1619
|
+
function useCanvasKindToggle(input) {
|
|
1620
|
+
const controller = useCanvasContext().controller;
|
|
1621
|
+
const key = input.key ?? CANVAS_DEFAULT_KEY;
|
|
1622
|
+
const visibility = useCanvasState((s) => selectCanvasKindVisibility(s, input.kind, key));
|
|
1623
|
+
return {
|
|
1624
|
+
visibility,
|
|
1625
|
+
isOpen: visibility !== "absent",
|
|
1626
|
+
isVisible: visibility === "visible",
|
|
1627
|
+
toggle: () => toggleKind(controller, input)
|
|
1628
|
+
};
|
|
1629
|
+
}
|
|
1580
1630
|
function useCanvasKinds() {
|
|
1581
1631
|
(0, import_react2.useSyncExternalStore)(subscribeCanvasKinds, getCanvasKindsVersion, getCanvasKindsVersion);
|
|
1582
1632
|
return listCanvasKinds();
|