@dxos/plugin-stack 0.8.2-main.fbd8ed0 → 0.8.2-staging.42af850

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.
Files changed (33) hide show
  1. package/dist/lib/browser/StackMain-RIX67KLY.mjs +315 -0
  2. package/dist/lib/{node-esm/StackMain-HAQNUG2W.mjs.map → browser/StackMain-RIX67KLY.mjs.map} +1 -1
  3. package/dist/lib/browser/index.mjs +10 -38
  4. package/dist/lib/browser/index.mjs.map +4 -4
  5. package/dist/lib/browser/meta.json +1 -1
  6. package/dist/lib/browser/react-surface-ED2DI7B5.mjs +46 -0
  7. package/dist/lib/browser/react-surface-ED2DI7B5.mjs.map +7 -0
  8. package/dist/lib/node/StackMain-4DMJWHZ3.cjs +329 -0
  9. package/dist/lib/node/{StackMain-ZTTXMOHM.cjs.map → StackMain-4DMJWHZ3.cjs.map} +1 -1
  10. package/dist/lib/node/index.cjs +4 -28
  11. package/dist/lib/node/index.cjs.map +4 -4
  12. package/dist/lib/node/meta.json +1 -1
  13. package/dist/lib/node/react-surface-L52YERMX.cjs +64 -0
  14. package/dist/lib/node/react-surface-L52YERMX.cjs.map +7 -0
  15. package/dist/lib/node-esm/StackMain-7FHYHLK6.mjs +316 -0
  16. package/dist/lib/{browser/StackMain-FRVJIEZU.mjs.map → node-esm/StackMain-7FHYHLK6.mjs.map} +1 -1
  17. package/dist/lib/node-esm/index.mjs +10 -38
  18. package/dist/lib/node-esm/index.mjs.map +4 -4
  19. package/dist/lib/node-esm/meta.json +1 -1
  20. package/dist/lib/node-esm/react-surface-6WUOGQY6.mjs +47 -0
  21. package/dist/lib/node-esm/react-surface-6WUOGQY6.mjs.map +7 -0
  22. package/dist/types/src/StackPlugin.d.ts.map +1 -1
  23. package/dist/types/src/capabilities/index.d.ts +2 -0
  24. package/dist/types/src/capabilities/index.d.ts.map +1 -0
  25. package/dist/types/src/capabilities/react-surface.d.ts +4 -0
  26. package/dist/types/src/capabilities/react-surface.d.ts.map +1 -0
  27. package/package.json +25 -24
  28. package/src/{StackPlugin.tsx → StackPlugin.ts} +5 -28
  29. package/src/capabilities/index.ts +7 -0
  30. package/src/capabilities/react-surface.tsx +33 -0
  31. package/dist/lib/browser/StackMain-FRVJIEZU.mjs +0 -297
  32. package/dist/lib/node/StackMain-ZTTXMOHM.cjs +0 -311
  33. package/dist/lib/node-esm/StackMain-HAQNUG2W.mjs +0 -298
@@ -1,297 +0,0 @@
1
- import {
2
- STACK_PLUGIN
3
- } from "./chunk-XHZTILS3.mjs";
4
- import {
5
- StackViewType
6
- } from "./chunk-XOUJQIK6.mjs";
7
-
8
- // packages/plugins/plugin-stack/src/components/StackMain.tsx
9
- import { Plus } from "@phosphor-icons/react";
10
- import { Option } from "effect";
11
- import React3, { useCallback, useEffect, useMemo, useState as useState2 } from "react";
12
- import { Capabilities, createIntent, LayoutAction, useAppGraph, useCapabilities, useIntentDispatcher } from "@dxos/app-framework";
13
- import { fullyQualifiedId, getTypename, isLiveObject, live, makeRef } from "@dxos/client/echo";
14
- import { SpaceAction } from "@dxos/plugin-space/types";
15
- import { Button, toLocalizedString, useTranslation as useTranslation2 } from "@dxos/react-ui";
16
- import { AttentionProvider } from "@dxos/react-ui-attention";
17
- import { Stack } from "@dxos/react-ui-stack";
18
- import { isNonNullable } from "@dxos/util";
19
-
20
- // packages/plugins/plugin-stack/src/components/StackContext.tsx
21
- import { createContext, useContext } from "react";
22
- var StackContext = /* @__PURE__ */ createContext({
23
- onCollapse: () => {
24
- },
25
- onNavigate: async () => {
26
- },
27
- onDelete: async () => {
28
- },
29
- onAdd: () => {
30
- }
31
- });
32
- var useStack = () => useContext(StackContext);
33
-
34
- // packages/plugins/plugin-stack/src/components/StackSection.tsx
35
- import * as CollapsiblePrimitive from "@radix-ui/react-collapsible";
36
- import React2, { useState } from "react";
37
- import { Surface } from "@dxos/app-framework";
38
- import { DropdownMenu, Icon, useTranslation, IconButton } from "@dxos/react-ui";
39
- import { useAttendableAttributes } from "@dxos/react-ui-attention";
40
- import { StackItem } from "@dxos/react-ui-stack";
41
- import { mx, getSize, textBlockWidth } from "@dxos/react-ui-theme";
42
-
43
- // packages/plugins/plugin-stack/src/components/CaretDownUp.tsx
44
- import React from "react";
45
- var CaretDownUp = ({ children, ...props }) => {
46
- return /* @__PURE__ */ React.createElement("svg", {
47
- xmlns: "http://www.w3.org/2000/svg",
48
- viewBox: "0 0 256 256",
49
- ...props
50
- }, /* @__PURE__ */ React.createElement("rect", {
51
- width: "256",
52
- height: "256",
53
- fill: "none"
54
- }), /* @__PURE__ */ React.createElement("polyline", {
55
- points: "80 224 128 176 176 224",
56
- fill: "none",
57
- stroke: "currentColor",
58
- strokeLinecap: "round",
59
- strokeLinejoin: "round",
60
- strokeWidth: "16"
61
- }), /* @__PURE__ */ React.createElement("polyline", {
62
- points: "80 32 128 80 176 32",
63
- fill: "none",
64
- stroke: "currentColor",
65
- strokeLinecap: "round",
66
- strokeLinejoin: "round",
67
- strokeWidth: "16"
68
- }), children);
69
- };
70
-
71
- // packages/plugins/plugin-stack/src/components/StackSection.tsx
72
- var sectionActionDimensions = "p-1 mlb-1 shrink-0 min-bs-0 is-[--rail-action] bs-min";
73
- var StackSection = ({ id, view, object, metadata: { icon = "ph--placeholder--regular" } }) => {
74
- const { t } = useTranslation(STACK_PLUGIN);
75
- const { onNavigate, onAdd, onCollapse, onDelete } = useStack();
76
- const [optionsMenuOpen, setOptionsMenuOpen] = useState(false);
77
- const attendableAttrs = useAttendableAttributes(id);
78
- return /* @__PURE__ */ React2.createElement(CollapsiblePrimitive.Root, {
79
- asChild: true,
80
- open: !view.collapsed,
81
- onOpenChange: (nextOpen) => onCollapse?.(id, !nextOpen)
82
- }, /* @__PURE__ */ React2.createElement(StackItem.Root, {
83
- item: {
84
- id
85
- },
86
- role: "section",
87
- ...attendableAttrs,
88
- classNames: "border-be border-separator"
89
- }, /* @__PURE__ */ React2.createElement(StackItem.Heading, {
90
- classNames: "attention-surface border-ie !border-separator"
91
- }, /* @__PURE__ */ React2.createElement("span", {
92
- className: "sr-only"
93
- }, view.title), /* @__PURE__ */ React2.createElement("div", {
94
- role: "none",
95
- className: "sticky -block-start-px bg-[--sticky-bg] p-1 is-full"
96
- }, /* @__PURE__ */ React2.createElement(DropdownMenu.Root, {
97
- open: optionsMenuOpen,
98
- onOpenChange: setOptionsMenuOpen
99
- }, /* @__PURE__ */ React2.createElement(DropdownMenu.Trigger, {
100
- asChild: true
101
- }, /* @__PURE__ */ React2.createElement(StackItem.SigilButton, null, /* @__PURE__ */ React2.createElement(Icon, {
102
- icon,
103
- size: 5,
104
- classNames: "transition-opacity"
105
- }))), /* @__PURE__ */ React2.createElement(DropdownMenu.Portal, null, /* @__PURE__ */ React2.createElement(DropdownMenu.Content, null, /* @__PURE__ */ React2.createElement(DropdownMenu.Viewport, null, view.collapsed ? /* @__PURE__ */ React2.createElement(DropdownMenu.Item, {
106
- onClick: () => onNavigate(id),
107
- "data-testid": "section.navigate-to"
108
- }, /* @__PURE__ */ React2.createElement(Icon, {
109
- icon: "ph--arrow-right--regular",
110
- size: 5
111
- }), /* @__PURE__ */ React2.createElement("span", {
112
- className: "mis-2 grow"
113
- }, t("navigate to section label"))) : /* @__PURE__ */ React2.createElement(CollapsiblePrimitive.Trigger, {
114
- asChild: true
115
- }, /* @__PURE__ */ React2.createElement(DropdownMenu.Item, null, /* @__PURE__ */ React2.createElement(CaretDownUp, {
116
- className: getSize(5)
117
- }), /* @__PURE__ */ React2.createElement("span", {
118
- className: "mis-2 grow"
119
- }, t("collapse label")))), /* @__PURE__ */ React2.createElement(DropdownMenu.Item, {
120
- onClick: () => onAdd(id, "before"),
121
- "data-testid": "section.add-before"
122
- }, /* @__PURE__ */ React2.createElement(Icon, {
123
- icon: "ph--arrow-line-up--regular",
124
- size: 5
125
- }), /* @__PURE__ */ React2.createElement("span", {
126
- className: "mis-2 grow"
127
- }, t("add section before label"))), /* @__PURE__ */ React2.createElement(DropdownMenu.Item, {
128
- onClick: () => onAdd(id, "after"),
129
- "data-testid": "section.add-after"
130
- }, /* @__PURE__ */ React2.createElement(Icon, {
131
- icon: "ph--arrow-line-down--regular",
132
- size: 5
133
- }), /* @__PURE__ */ React2.createElement("span", {
134
- className: "mis-2 grow"
135
- }, t("add section after label"))), /* @__PURE__ */ React2.createElement(DropdownMenu.Item, {
136
- onClick: () => onDelete(id),
137
- "data-testid": "section.remove"
138
- }, /* @__PURE__ */ React2.createElement(Icon, {
139
- icon: "ph--trash--regular",
140
- size: 5
141
- }), /* @__PURE__ */ React2.createElement("span", {
142
- className: "mis-2 grow"
143
- }, t("remove section label")))), /* @__PURE__ */ React2.createElement(DropdownMenu.Arrow, null)))), view.collapsed ? /* @__PURE__ */ React2.createElement(CollapsiblePrimitive.Trigger, {
144
- asChild: true
145
- }, /* @__PURE__ */ React2.createElement(IconButton, {
146
- iconOnly: true,
147
- variant: "ghost",
148
- label: t("expand label"),
149
- icon: "ph--caret-up-down--regular",
150
- classNames: sectionActionDimensions
151
- })) : /* @__PURE__ */ React2.createElement(IconButton, {
152
- iconOnly: true,
153
- variant: "ghost",
154
- onClick: () => onNavigate(id),
155
- label: t("navigate to section label"),
156
- icon: "ph--arrow-right--regular",
157
- "data-testid": "section.navigate-to",
158
- classNames: sectionActionDimensions
159
- }))), /* @__PURE__ */ React2.createElement(CollapsiblePrimitive.Content, null, /* @__PURE__ */ React2.createElement(Surface, {
160
- role: "section",
161
- data: {
162
- subject: object
163
- },
164
- limit: 1,
165
- placeholder: /* @__PURE__ */ React2.createElement(React2.Fragment, null)
166
- })), view.collapsed && /* @__PURE__ */ React2.createElement(StackItem.Content, {
167
- classNames: "attention-surface"
168
- }, /* @__PURE__ */ React2.createElement("h2", {
169
- className: mx("flex items-center p-4 font-medium", textBlockWidth)
170
- }, view.title))));
171
- };
172
-
173
- // packages/plugins/plugin-stack/src/components/StackMain.tsx
174
- var StackMain = ({ id, collection }) => {
175
- const { dispatchPromise: dispatch } = useIntentDispatcher();
176
- const { graph } = useAppGraph();
177
- const { t } = useTranslation2(STACK_PLUGIN);
178
- const allMetadata = useCapabilities(Capabilities.Metadata);
179
- const defaultStack = useMemo(() => live(StackViewType, {
180
- sections: {}
181
- }), [
182
- collection
183
- ]);
184
- const stack = collection.views[StackViewType.typename]?.target ?? defaultStack;
185
- const [collapsedSections, setCollapsedSections] = useState2({});
186
- useEffect(() => {
187
- if (!collection.views[StackViewType.typename]) {
188
- collection.views[StackViewType.typename] = makeRef(stack);
189
- }
190
- }, [
191
- collection,
192
- stack
193
- ]);
194
- const items = collection.objects.map((object) => object.target).filter(isNonNullable).map((object) => {
195
- const metadata = allMetadata.find((m) => m.id === (getTypename(object) ?? "never"))?.metadata;
196
- const view = {
197
- ...stack.sections[object.id],
198
- collapsed: collapsedSections[fullyQualifiedId(object)],
199
- title: object?.title ?? // TODO(wittjosiah): `getNode` is not reactive.
200
- toLocalizedString(graph.getNode(fullyQualifiedId(object)).pipe(Option.getOrNull)?.properties.label, t)
201
- };
202
- return {
203
- id: fullyQualifiedId(object),
204
- object,
205
- metadata,
206
- view
207
- };
208
- }) ?? [];
209
- const handleDelete = useCallback(async (id2) => {
210
- const index = collection.objects.map((object2) => object2.target).filter(isNonNullable).findIndex((section) => fullyQualifiedId(section) === id2);
211
- const object = collection.objects[index].target;
212
- if (isLiveObject(object)) {
213
- await dispatch(createIntent(SpaceAction.RemoveObjects, {
214
- objects: [
215
- object
216
- ],
217
- target: collection
218
- }));
219
- }
220
- }, [
221
- collection,
222
- dispatch
223
- ]);
224
- const handleAdd = useCallback(async (id2, position) => {
225
- await dispatch?.(
226
- // TODO(wittjosiah): Use object creation dialog.
227
- createIntent(LayoutAction.UpdateDialog, {
228
- part: "dialog",
229
- subject: `${STACK_PLUGIN}/AddSectionDialog`,
230
- options: {
231
- blockAlign: "start",
232
- props: {
233
- path: id2,
234
- position,
235
- collection
236
- }
237
- }
238
- })
239
- );
240
- }, [
241
- collection,
242
- dispatch
243
- ]);
244
- const handleNavigate = useCallback(async (id2) => {
245
- await dispatch(createIntent(LayoutAction.Open, {
246
- part: "main",
247
- subject: [
248
- id2
249
- ]
250
- }));
251
- }, [
252
- dispatch
253
- ]);
254
- const handleCollapse = useCallback((id2, collapsed) => setCollapsedSections((prev) => ({
255
- ...prev,
256
- [id2]: collapsed
257
- })), []);
258
- const handleAddSection = useCallback(() => dispatch?.(createIntent(SpaceAction.OpenCreateObject, {
259
- target: collection,
260
- navigable: false
261
- })), [
262
- collection,
263
- dispatch
264
- ]);
265
- return /* @__PURE__ */ React3.createElement(AttentionProvider, {
266
- id
267
- }, /* @__PURE__ */ React3.createElement(StackContext.Provider, {
268
- value: {
269
- onCollapse: handleCollapse,
270
- onNavigate: handleNavigate,
271
- onDelete: handleDelete,
272
- onAdd: handleAdd
273
- }
274
- }, /* @__PURE__ */ React3.createElement(Stack, {
275
- orientation: "vertical",
276
- size: "intrinsic",
277
- id,
278
- "data-testid": "main.stack"
279
- }, items.map((item) => /* @__PURE__ */ React3.createElement(StackSection, {
280
- key: item.id,
281
- ...item
282
- }))), /* @__PURE__ */ React3.createElement("div", {
283
- role: "none",
284
- className: "flex mlb-2 pli-2 justify-center"
285
- }, /* @__PURE__ */ React3.createElement(Button, {
286
- "data-testid": "stack.createSection",
287
- classNames: "gap-2",
288
- onClick: handleAddSection
289
- }, /* @__PURE__ */ React3.createElement(Plus, null), /* @__PURE__ */ React3.createElement("span", {
290
- className: "sr-only"
291
- }, t("add section label"))))));
292
- };
293
- var StackMain_default = StackMain;
294
- export {
295
- StackMain_default as default
296
- };
297
- //# sourceMappingURL=StackMain-FRVJIEZU.mjs.map
@@ -1,311 +0,0 @@
1
- "use strict";
2
- var __create = Object.create;
3
- var __defProp = Object.defineProperty;
4
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
- var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __export = (target, all) => {
9
- for (var name in all)
10
- __defProp(target, name, { get: all[name], enumerable: true });
11
- };
12
- var __copyProps = (to, from, except, desc) => {
13
- if (from && typeof from === "object" || typeof from === "function") {
14
- for (let key of __getOwnPropNames(from))
15
- if (!__hasOwnProp.call(to, key) && key !== except)
16
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
- }
18
- return to;
19
- };
20
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
- // If the importer is in node compatibility mode or this is not an ESM
22
- // file that has been converted to a CommonJS file using a Babel-
23
- // compatible transform (i.e. "__esModule" has not been set), then set
24
- // "default" to the CommonJS "module.exports" for node compatibility.
25
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
- mod
27
- ));
28
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
- var StackMain_ZTTXMOHM_exports = {};
30
- __export(StackMain_ZTTXMOHM_exports, {
31
- default: () => StackMain_default
32
- });
33
- module.exports = __toCommonJS(StackMain_ZTTXMOHM_exports);
34
- var import_chunk_F7ZNJ53O = require("./chunk-F7ZNJ53O.cjs");
35
- var import_chunk_5QWZH22T = require("./chunk-5QWZH22T.cjs");
36
- var import_react = require("@phosphor-icons/react");
37
- var import_effect = require("effect");
38
- var import_react2 = __toESM(require("react"));
39
- var import_app_framework = require("@dxos/app-framework");
40
- var import_echo = require("@dxos/client/echo");
41
- var import_types = require("@dxos/plugin-space/types");
42
- var import_react_ui = require("@dxos/react-ui");
43
- var import_react_ui_attention = require("@dxos/react-ui-attention");
44
- var import_react_ui_stack = require("@dxos/react-ui-stack");
45
- var import_util = require("@dxos/util");
46
- var import_react3 = require("react");
47
- var CollapsiblePrimitive = __toESM(require("@radix-ui/react-collapsible"));
48
- var import_react4 = __toESM(require("react"));
49
- var import_app_framework2 = require("@dxos/app-framework");
50
- var import_react_ui2 = require("@dxos/react-ui");
51
- var import_react_ui_attention2 = require("@dxos/react-ui-attention");
52
- var import_react_ui_stack2 = require("@dxos/react-ui-stack");
53
- var import_react_ui_theme = require("@dxos/react-ui-theme");
54
- var import_react5 = __toESM(require("react"));
55
- var StackContext = /* @__PURE__ */ (0, import_react3.createContext)({
56
- onCollapse: () => {
57
- },
58
- onNavigate: async () => {
59
- },
60
- onDelete: async () => {
61
- },
62
- onAdd: () => {
63
- }
64
- });
65
- var useStack = () => (0, import_react3.useContext)(StackContext);
66
- var CaretDownUp = ({ children, ...props }) => {
67
- return /* @__PURE__ */ import_react5.default.createElement("svg", {
68
- xmlns: "http://www.w3.org/2000/svg",
69
- viewBox: "0 0 256 256",
70
- ...props
71
- }, /* @__PURE__ */ import_react5.default.createElement("rect", {
72
- width: "256",
73
- height: "256",
74
- fill: "none"
75
- }), /* @__PURE__ */ import_react5.default.createElement("polyline", {
76
- points: "80 224 128 176 176 224",
77
- fill: "none",
78
- stroke: "currentColor",
79
- strokeLinecap: "round",
80
- strokeLinejoin: "round",
81
- strokeWidth: "16"
82
- }), /* @__PURE__ */ import_react5.default.createElement("polyline", {
83
- points: "80 32 128 80 176 32",
84
- fill: "none",
85
- stroke: "currentColor",
86
- strokeLinecap: "round",
87
- strokeLinejoin: "round",
88
- strokeWidth: "16"
89
- }), children);
90
- };
91
- var sectionActionDimensions = "p-1 mlb-1 shrink-0 min-bs-0 is-[--rail-action] bs-min";
92
- var StackSection = ({ id, view, object, metadata: { icon = "ph--placeholder--regular" } }) => {
93
- const { t } = (0, import_react_ui2.useTranslation)(import_chunk_F7ZNJ53O.STACK_PLUGIN);
94
- const { onNavigate, onAdd, onCollapse, onDelete } = useStack();
95
- const [optionsMenuOpen, setOptionsMenuOpen] = (0, import_react4.useState)(false);
96
- const attendableAttrs = (0, import_react_ui_attention2.useAttendableAttributes)(id);
97
- return /* @__PURE__ */ import_react4.default.createElement(CollapsiblePrimitive.Root, {
98
- asChild: true,
99
- open: !view.collapsed,
100
- onOpenChange: (nextOpen) => onCollapse?.(id, !nextOpen)
101
- }, /* @__PURE__ */ import_react4.default.createElement(import_react_ui_stack2.StackItem.Root, {
102
- item: {
103
- id
104
- },
105
- role: "section",
106
- ...attendableAttrs,
107
- classNames: "border-be border-separator"
108
- }, /* @__PURE__ */ import_react4.default.createElement(import_react_ui_stack2.StackItem.Heading, {
109
- classNames: "attention-surface border-ie !border-separator"
110
- }, /* @__PURE__ */ import_react4.default.createElement("span", {
111
- className: "sr-only"
112
- }, view.title), /* @__PURE__ */ import_react4.default.createElement("div", {
113
- role: "none",
114
- className: "sticky -block-start-px bg-[--sticky-bg] p-1 is-full"
115
- }, /* @__PURE__ */ import_react4.default.createElement(import_react_ui2.DropdownMenu.Root, {
116
- open: optionsMenuOpen,
117
- onOpenChange: setOptionsMenuOpen
118
- }, /* @__PURE__ */ import_react4.default.createElement(import_react_ui2.DropdownMenu.Trigger, {
119
- asChild: true
120
- }, /* @__PURE__ */ import_react4.default.createElement(import_react_ui_stack2.StackItem.SigilButton, null, /* @__PURE__ */ import_react4.default.createElement(import_react_ui2.Icon, {
121
- icon,
122
- size: 5,
123
- classNames: "transition-opacity"
124
- }))), /* @__PURE__ */ import_react4.default.createElement(import_react_ui2.DropdownMenu.Portal, null, /* @__PURE__ */ import_react4.default.createElement(import_react_ui2.DropdownMenu.Content, null, /* @__PURE__ */ import_react4.default.createElement(import_react_ui2.DropdownMenu.Viewport, null, view.collapsed ? /* @__PURE__ */ import_react4.default.createElement(import_react_ui2.DropdownMenu.Item, {
125
- onClick: () => onNavigate(id),
126
- "data-testid": "section.navigate-to"
127
- }, /* @__PURE__ */ import_react4.default.createElement(import_react_ui2.Icon, {
128
- icon: "ph--arrow-right--regular",
129
- size: 5
130
- }), /* @__PURE__ */ import_react4.default.createElement("span", {
131
- className: "mis-2 grow"
132
- }, t("navigate to section label"))) : /* @__PURE__ */ import_react4.default.createElement(CollapsiblePrimitive.Trigger, {
133
- asChild: true
134
- }, /* @__PURE__ */ import_react4.default.createElement(import_react_ui2.DropdownMenu.Item, null, /* @__PURE__ */ import_react4.default.createElement(CaretDownUp, {
135
- className: (0, import_react_ui_theme.getSize)(5)
136
- }), /* @__PURE__ */ import_react4.default.createElement("span", {
137
- className: "mis-2 grow"
138
- }, t("collapse label")))), /* @__PURE__ */ import_react4.default.createElement(import_react_ui2.DropdownMenu.Item, {
139
- onClick: () => onAdd(id, "before"),
140
- "data-testid": "section.add-before"
141
- }, /* @__PURE__ */ import_react4.default.createElement(import_react_ui2.Icon, {
142
- icon: "ph--arrow-line-up--regular",
143
- size: 5
144
- }), /* @__PURE__ */ import_react4.default.createElement("span", {
145
- className: "mis-2 grow"
146
- }, t("add section before label"))), /* @__PURE__ */ import_react4.default.createElement(import_react_ui2.DropdownMenu.Item, {
147
- onClick: () => onAdd(id, "after"),
148
- "data-testid": "section.add-after"
149
- }, /* @__PURE__ */ import_react4.default.createElement(import_react_ui2.Icon, {
150
- icon: "ph--arrow-line-down--regular",
151
- size: 5
152
- }), /* @__PURE__ */ import_react4.default.createElement("span", {
153
- className: "mis-2 grow"
154
- }, t("add section after label"))), /* @__PURE__ */ import_react4.default.createElement(import_react_ui2.DropdownMenu.Item, {
155
- onClick: () => onDelete(id),
156
- "data-testid": "section.remove"
157
- }, /* @__PURE__ */ import_react4.default.createElement(import_react_ui2.Icon, {
158
- icon: "ph--trash--regular",
159
- size: 5
160
- }), /* @__PURE__ */ import_react4.default.createElement("span", {
161
- className: "mis-2 grow"
162
- }, t("remove section label")))), /* @__PURE__ */ import_react4.default.createElement(import_react_ui2.DropdownMenu.Arrow, null)))), view.collapsed ? /* @__PURE__ */ import_react4.default.createElement(CollapsiblePrimitive.Trigger, {
163
- asChild: true
164
- }, /* @__PURE__ */ import_react4.default.createElement(import_react_ui2.IconButton, {
165
- iconOnly: true,
166
- variant: "ghost",
167
- label: t("expand label"),
168
- icon: "ph--caret-up-down--regular",
169
- classNames: sectionActionDimensions
170
- })) : /* @__PURE__ */ import_react4.default.createElement(import_react_ui2.IconButton, {
171
- iconOnly: true,
172
- variant: "ghost",
173
- onClick: () => onNavigate(id),
174
- label: t("navigate to section label"),
175
- icon: "ph--arrow-right--regular",
176
- "data-testid": "section.navigate-to",
177
- classNames: sectionActionDimensions
178
- }))), /* @__PURE__ */ import_react4.default.createElement(CollapsiblePrimitive.Content, null, /* @__PURE__ */ import_react4.default.createElement(import_app_framework2.Surface, {
179
- role: "section",
180
- data: {
181
- subject: object
182
- },
183
- limit: 1,
184
- placeholder: /* @__PURE__ */ import_react4.default.createElement(import_react4.default.Fragment, null)
185
- })), view.collapsed && /* @__PURE__ */ import_react4.default.createElement(import_react_ui_stack2.StackItem.Content, {
186
- classNames: "attention-surface"
187
- }, /* @__PURE__ */ import_react4.default.createElement("h2", {
188
- className: (0, import_react_ui_theme.mx)("flex items-center p-4 font-medium", import_react_ui_theme.textBlockWidth)
189
- }, view.title))));
190
- };
191
- var StackMain = ({ id, collection }) => {
192
- const { dispatchPromise: dispatch } = (0, import_app_framework.useIntentDispatcher)();
193
- const { graph } = (0, import_app_framework.useAppGraph)();
194
- const { t } = (0, import_react_ui.useTranslation)(import_chunk_F7ZNJ53O.STACK_PLUGIN);
195
- const allMetadata = (0, import_app_framework.useCapabilities)(import_app_framework.Capabilities.Metadata);
196
- const defaultStack = (0, import_react2.useMemo)(() => (0, import_echo.live)(import_chunk_5QWZH22T.StackViewType, {
197
- sections: {}
198
- }), [
199
- collection
200
- ]);
201
- const stack = collection.views[import_chunk_5QWZH22T.StackViewType.typename]?.target ?? defaultStack;
202
- const [collapsedSections, setCollapsedSections] = (0, import_react2.useState)({});
203
- (0, import_react2.useEffect)(() => {
204
- if (!collection.views[import_chunk_5QWZH22T.StackViewType.typename]) {
205
- collection.views[import_chunk_5QWZH22T.StackViewType.typename] = (0, import_echo.makeRef)(stack);
206
- }
207
- }, [
208
- collection,
209
- stack
210
- ]);
211
- const items = collection.objects.map((object) => object.target).filter(import_util.isNonNullable).map((object) => {
212
- const metadata = allMetadata.find((m) => m.id === ((0, import_echo.getTypename)(object) ?? "never"))?.metadata;
213
- const view = {
214
- ...stack.sections[object.id],
215
- collapsed: collapsedSections[(0, import_echo.fullyQualifiedId)(object)],
216
- title: object?.title ?? // TODO(wittjosiah): `getNode` is not reactive.
217
- (0, import_react_ui.toLocalizedString)(graph.getNode((0, import_echo.fullyQualifiedId)(object)).pipe(import_effect.Option.getOrNull)?.properties.label, t)
218
- };
219
- return {
220
- id: (0, import_echo.fullyQualifiedId)(object),
221
- object,
222
- metadata,
223
- view
224
- };
225
- }) ?? [];
226
- const handleDelete = (0, import_react2.useCallback)(async (id2) => {
227
- const index = collection.objects.map((object2) => object2.target).filter(import_util.isNonNullable).findIndex((section) => (0, import_echo.fullyQualifiedId)(section) === id2);
228
- const object = collection.objects[index].target;
229
- if ((0, import_echo.isLiveObject)(object)) {
230
- await dispatch((0, import_app_framework.createIntent)(import_types.SpaceAction.RemoveObjects, {
231
- objects: [
232
- object
233
- ],
234
- target: collection
235
- }));
236
- }
237
- }, [
238
- collection,
239
- dispatch
240
- ]);
241
- const handleAdd = (0, import_react2.useCallback)(async (id2, position) => {
242
- await dispatch?.(
243
- // TODO(wittjosiah): Use object creation dialog.
244
- (0, import_app_framework.createIntent)(import_app_framework.LayoutAction.UpdateDialog, {
245
- part: "dialog",
246
- subject: `${import_chunk_F7ZNJ53O.STACK_PLUGIN}/AddSectionDialog`,
247
- options: {
248
- blockAlign: "start",
249
- props: {
250
- path: id2,
251
- position,
252
- collection
253
- }
254
- }
255
- })
256
- );
257
- }, [
258
- collection,
259
- dispatch
260
- ]);
261
- const handleNavigate = (0, import_react2.useCallback)(async (id2) => {
262
- await dispatch((0, import_app_framework.createIntent)(import_app_framework.LayoutAction.Open, {
263
- part: "main",
264
- subject: [
265
- id2
266
- ]
267
- }));
268
- }, [
269
- dispatch
270
- ]);
271
- const handleCollapse = (0, import_react2.useCallback)((id2, collapsed) => setCollapsedSections((prev) => ({
272
- ...prev,
273
- [id2]: collapsed
274
- })), []);
275
- const handleAddSection = (0, import_react2.useCallback)(() => dispatch?.((0, import_app_framework.createIntent)(import_types.SpaceAction.OpenCreateObject, {
276
- target: collection,
277
- navigable: false
278
- })), [
279
- collection,
280
- dispatch
281
- ]);
282
- return /* @__PURE__ */ import_react2.default.createElement(import_react_ui_attention.AttentionProvider, {
283
- id
284
- }, /* @__PURE__ */ import_react2.default.createElement(StackContext.Provider, {
285
- value: {
286
- onCollapse: handleCollapse,
287
- onNavigate: handleNavigate,
288
- onDelete: handleDelete,
289
- onAdd: handleAdd
290
- }
291
- }, /* @__PURE__ */ import_react2.default.createElement(import_react_ui_stack.Stack, {
292
- orientation: "vertical",
293
- size: "intrinsic",
294
- id,
295
- "data-testid": "main.stack"
296
- }, items.map((item) => /* @__PURE__ */ import_react2.default.createElement(StackSection, {
297
- key: item.id,
298
- ...item
299
- }))), /* @__PURE__ */ import_react2.default.createElement("div", {
300
- role: "none",
301
- className: "flex mlb-2 pli-2 justify-center"
302
- }, /* @__PURE__ */ import_react2.default.createElement(import_react_ui.Button, {
303
- "data-testid": "stack.createSection",
304
- classNames: "gap-2",
305
- onClick: handleAddSection
306
- }, /* @__PURE__ */ import_react2.default.createElement(import_react.Plus, null), /* @__PURE__ */ import_react2.default.createElement("span", {
307
- className: "sr-only"
308
- }, t("add section label"))))));
309
- };
310
- var StackMain_default = StackMain;
311
- //# sourceMappingURL=StackMain-ZTTXMOHM.cjs.map