@dxos/plugin-stack 0.6.14-main.8b352a0 → 0.6.14-staging.0f558a0

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 (64) hide show
  1. package/dist/lib/browser/StackMain-Z2DSTC42.mjs +390 -0
  2. package/dist/lib/browser/StackMain-Z2DSTC42.mjs.map +7 -0
  3. package/dist/lib/browser/{chunk-ONAKM24Z.mjs → chunk-DS5KGEJG.mjs} +5 -2
  4. package/dist/lib/browser/chunk-DS5KGEJG.mjs.map +7 -0
  5. package/dist/lib/browser/index.mjs +20 -10
  6. package/dist/lib/browser/index.mjs.map +3 -3
  7. package/dist/lib/browser/meta.json +1 -1
  8. package/dist/lib/browser/meta.mjs +1 -1
  9. package/dist/lib/node/StackMain-YK5QQBXA.cjs +402 -0
  10. package/dist/lib/node/StackMain-YK5QQBXA.cjs.map +7 -0
  11. package/dist/lib/node/{chunk-O5SQVKNW.cjs → chunk-PA5PRDM6.cjs} +8 -5
  12. package/dist/lib/node/chunk-PA5PRDM6.cjs.map +7 -0
  13. package/dist/lib/node/index.cjs +30 -20
  14. package/dist/lib/node/index.cjs.map +3 -3
  15. package/dist/lib/node/meta.cjs +4 -4
  16. package/dist/lib/node/meta.cjs.map +1 -1
  17. package/dist/lib/node/meta.json +1 -1
  18. package/dist/lib/node-esm/StackMain-GCZYK7GH.mjs +391 -0
  19. package/dist/lib/node-esm/StackMain-GCZYK7GH.mjs.map +7 -0
  20. package/dist/lib/node-esm/{chunk-J57BXQJY.mjs → chunk-JEQMG2E2.mjs} +5 -2
  21. package/dist/lib/node-esm/chunk-JEQMG2E2.mjs.map +7 -0
  22. package/dist/lib/node-esm/index.mjs +20 -10
  23. package/dist/lib/node-esm/index.mjs.map +3 -3
  24. package/dist/lib/node-esm/meta.json +1 -1
  25. package/dist/lib/node-esm/meta.mjs +1 -1
  26. package/dist/types/src/StackPlugin.d.ts.map +1 -1
  27. package/dist/types/src/components/AddSectionDialog.d.ts +1 -1
  28. package/dist/types/src/components/AddSectionDialog.d.ts.map +1 -1
  29. package/dist/types/src/components/CaretDownUp.d.ts +3 -0
  30. package/dist/types/src/components/CaretDownUp.d.ts.map +1 -0
  31. package/dist/types/src/components/StackContext.d.ts +10 -0
  32. package/dist/types/src/components/StackContext.d.ts.map +1 -0
  33. package/dist/types/src/components/StackMain.d.ts +1 -2
  34. package/dist/types/src/components/StackMain.d.ts.map +1 -1
  35. package/dist/types/src/components/StackSection.d.ts +4 -0
  36. package/dist/types/src/components/StackSection.d.ts.map +1 -0
  37. package/dist/types/src/components/index.d.ts +1 -2
  38. package/dist/types/src/components/index.d.ts.map +1 -1
  39. package/dist/types/src/meta.d.ts +2 -0
  40. package/dist/types/src/meta.d.ts.map +1 -1
  41. package/dist/types/src/translations.d.ts +17 -8
  42. package/dist/types/src/translations.d.ts.map +1 -1
  43. package/dist/types/src/types/types.d.ts +24 -0
  44. package/dist/types/src/types/types.d.ts.map +1 -1
  45. package/package.json +24 -23
  46. package/src/StackPlugin.tsx +3 -11
  47. package/src/components/AddSectionDialog.tsx +1 -2
  48. package/src/components/CaretDownUp.tsx +30 -0
  49. package/src/components/StackContext.tsx +23 -0
  50. package/src/components/StackMain.tsx +49 -111
  51. package/src/components/StackSection.tsx +118 -0
  52. package/src/components/StackSettings.tsx +3 -3
  53. package/src/meta.ts +3 -0
  54. package/src/translations.ts +9 -0
  55. package/src/types/types.ts +30 -0
  56. package/dist/lib/browser/StackMain-KKC3XIAY.mjs +0 -277
  57. package/dist/lib/browser/StackMain-KKC3XIAY.mjs.map +0 -7
  58. package/dist/lib/browser/chunk-ONAKM24Z.mjs.map +0 -7
  59. package/dist/lib/node/StackMain-ME6LYFGI.cjs +0 -296
  60. package/dist/lib/node/StackMain-ME6LYFGI.cjs.map +0 -7
  61. package/dist/lib/node/chunk-O5SQVKNW.cjs.map +0 -7
  62. package/dist/lib/node-esm/StackMain-D3P3PIMI.mjs +0 -278
  63. package/dist/lib/node-esm/StackMain-D3P3PIMI.mjs.map +0 -7
  64. package/dist/lib/node-esm/chunk-J57BXQJY.mjs.map +0 -7
@@ -1,277 +0,0 @@
1
- import {
2
- SECTION_IDENTIFIER,
3
- STACK_PLUGIN
4
- } from "./chunk-ONAKM24Z.mjs";
5
- import {
6
- StackViewType
7
- } from "./chunk-L34RFJ2L.mjs";
8
-
9
- // packages/plugins/plugin-stack/src/components/StackMain.tsx
10
- import { Plus } from "@phosphor-icons/react";
11
- import React2, { useEffect, useMemo, useState } from "react";
12
- import { LayoutAction, NavigationAction, Surface, parseMetadataResolverPlugin, useIntentDispatcher as useIntentDispatcher2, useResolvePlugin } from "@dxos/app-framework";
13
- import { create, getType, fullyQualifiedId, isReactiveObject } from "@dxos/client/echo";
14
- import { useGraph } from "@dxos/plugin-graph";
15
- import { SpaceAction } from "@dxos/plugin-space";
16
- import { Button, toLocalizedString as toLocalizedString2, useTranslation as useTranslation2 } from "@dxos/react-ui";
17
- import { AttentionProvider } from "@dxos/react-ui-attention";
18
- import { Mosaic, Path } from "@dxos/react-ui-mosaic";
19
- import { Stack } from "@dxos/react-ui-stack";
20
- import { nonNullable } from "@dxos/util";
21
-
22
- // packages/plugins/plugin-stack/src/components/AddSection.tsx
23
- import { useArrowNavigationGroup } from "@fluentui/react-tabster";
24
- import React, { useCallback } from "react";
25
- import { usePlugin, useIntentDispatcher } from "@dxos/app-framework";
26
- import { toLocalizedString, useTranslation } from "@dxos/react-ui";
27
- import { getSize, mx } from "@dxos/react-ui-theme";
28
- var CreatorTile = ({ Icon, label, testId, handleAdd }) => {
29
- const onClick = useCallback((_) => handleAdd(), [
30
- handleAdd
31
- ]);
32
- const onKeyDown = useCallback((event) => {
33
- if (event.key === "Enter" || event.key === " ") {
34
- event.preventDefault();
35
- handleAdd();
36
- }
37
- }, [
38
- handleAdd
39
- ]);
40
- return /* @__PURE__ */ React.createElement("div", {
41
- role: "button",
42
- "aria-label": label,
43
- tabIndex: 0,
44
- className: mx("flex items-center w-[10rem] h-16 overflow-hidden", "border rounded-md border-separator shadow-sm hover:bg-hoverSurface cursor-pointer"),
45
- onClick,
46
- onKeyDown,
47
- "data-testid": testId
48
- }, /* @__PURE__ */ React.createElement("div", {
49
- className: "flex h-full w-12 items-center justify-center bg-scrim shrink-0 border-r border-separator"
50
- }, /* @__PURE__ */ React.createElement(Icon, {
51
- weight: "thin",
52
- className: getSize(6)
53
- })), /* @__PURE__ */ React.createElement("div", {
54
- className: "overflow-hidden items-center p-2 px-3"
55
- }, /* @__PURE__ */ React.createElement("span", {
56
- className: "capitalize"
57
- }, label)));
58
- };
59
- var AddSection = ({ collection }) => {
60
- const domAttributes = useArrowNavigationGroup({
61
- axis: "grid"
62
- });
63
- const dispatch = useIntentDispatcher();
64
- const { t } = useTranslation(STACK_PLUGIN);
65
- const stackPlugin = usePlugin(STACK_PLUGIN);
66
- const stackCreators = stackPlugin?.provides?.stack.creators ?? [];
67
- const handleAdd = useCallback(async (creator) => {
68
- const { data: section } = await dispatch(creator.intent) ?? {};
69
- collection.objects = [
70
- section
71
- ];
72
- const stack = collection.views[StackViewType.typename];
73
- if (stack) {
74
- stack.sections[section.id] = {};
75
- }
76
- }, [
77
- collection,
78
- dispatch
79
- ]);
80
- if (stackCreators.length === 0) {
81
- return null;
82
- }
83
- return /* @__PURE__ */ React.createElement("div", {
84
- ...domAttributes,
85
- role: "none",
86
- className: "flex flex-wrap items-center p-8 gap-4"
87
- }, stackCreators.map((creator) => {
88
- const { id, type, icon, testId } = creator;
89
- return /* @__PURE__ */ React.createElement(CreatorTile, {
90
- key: id,
91
- label: toLocalizedString(type, t),
92
- testId,
93
- Icon: icon,
94
- handleAdd: () => handleAdd(creator)
95
- });
96
- }));
97
- };
98
-
99
- // packages/plugins/plugin-stack/src/components/StackMain.tsx
100
- var SectionContent = ({ data }) => {
101
- return /* @__PURE__ */ React2.createElement(Surface, {
102
- role: "section",
103
- data: {
104
- object: data
105
- },
106
- limit: 1,
107
- placeholder: /* @__PURE__ */ React2.createElement(React2.Fragment, null)
108
- });
109
- };
110
- var StackMain = ({ id, collection, separation }) => {
111
- const dispatch = useIntentDispatcher2();
112
- const { graph } = useGraph();
113
- const { t } = useTranslation2(STACK_PLUGIN);
114
- const metadataPlugin = useResolvePlugin(parseMetadataResolverPlugin);
115
- const defaultStack = useMemo(() => create(StackViewType, {
116
- sections: {}
117
- }), [
118
- collection
119
- ]);
120
- const stack = collection.views[StackViewType.typename] ?? defaultStack;
121
- const [collapsedSections, setCollapsedSections] = useState({});
122
- useEffect(() => {
123
- if (!collection.views[StackViewType.typename]) {
124
- collection.views[StackViewType.typename] = stack;
125
- }
126
- }, [
127
- collection,
128
- stack
129
- ]);
130
- const items = collection.objects.filter(nonNullable).map((object) => {
131
- const metadata = metadataPlugin?.provides.metadata.resolver(getType(object)?.objectId ?? "never");
132
- const view = {
133
- ...stack.sections[object.id],
134
- collapsed: collapsedSections[fullyQualifiedId(object)],
135
- title: object?.title ?? toLocalizedString2(graph.findNode(fullyQualifiedId(object))?.properties.label, t)
136
- };
137
- return {
138
- id: fullyQualifiedId(object),
139
- object,
140
- metadata,
141
- view
142
- };
143
- }) ?? [];
144
- const handleOver = ({ active, over }) => {
145
- if (active.type !== SECTION_IDENTIFIER) {
146
- return "reject";
147
- }
148
- if (Path.parent(active.path) === Path.parent(over.path)) {
149
- return "rearrange";
150
- }
151
- const parseData = metadataPlugin?.provides.metadata.resolver(active.type)?.parse;
152
- const data = parseData ? parseData(active.item, "object") : active.item;
153
- if (!isReactiveObject(data)) {
154
- return "reject";
155
- }
156
- const exists = items.findIndex(({ id: id2 }) => id2 === active.item.id) >= 0;
157
- if (!exists) {
158
- return "transfer";
159
- } else {
160
- return "reject";
161
- }
162
- };
163
- const handleDrop = ({ operation, active, over }) => {
164
- if ((active.path === Path.create(id, active.item.id) || active.path === id) && (operation !== "copy" || over.path === Path.create(id, over.item.id) || over.path === id)) {
165
- collection.objects.splice(active.position, 1);
166
- delete stack.sections[active.item.id];
167
- }
168
- const parseData = metadataPlugin?.provides.metadata.resolver(active.type)?.parse;
169
- const object = parseData?.(active.item, "object");
170
- if (object && over.path === Path.create(id, over.item.id)) {
171
- collection.objects.splice(over.position, 0, object);
172
- } else if (object && over.path === id) {
173
- collection.objects.push(object);
174
- }
175
- if (!stack.sections[object.id]) {
176
- stack.sections[object.id] = {};
177
- }
178
- };
179
- const handleDelete = async (path) => {
180
- const index = collection.objects.filter(nonNullable).findIndex((section) => fullyQualifiedId(section) === Path.last(path));
181
- if (index >= 0) {
182
- await dispatch({
183
- action: SpaceAction.REMOVE_OBJECT,
184
- data: {
185
- object: collection.objects[index],
186
- collection
187
- }
188
- });
189
- }
190
- };
191
- const handleNavigate = async (object) => {
192
- const toId = fullyQualifiedId(object);
193
- await dispatch([
194
- {
195
- action: NavigationAction.OPEN,
196
- data: {
197
- activeParts: {
198
- main: [
199
- toId
200
- ]
201
- }
202
- }
203
- },
204
- {
205
- action: LayoutAction.SCROLL_INTO_VIEW,
206
- data: {
207
- id: toId
208
- }
209
- }
210
- ]);
211
- };
212
- const handleAddSection = (path, position) => {
213
- void dispatch?.({
214
- action: LayoutAction.SET_LAYOUT,
215
- data: {
216
- element: "dialog",
217
- component: `${STACK_PLUGIN}/AddSectionDialog`,
218
- subject: {
219
- path,
220
- position,
221
- collection
222
- }
223
- }
224
- });
225
- };
226
- const handleCollapseSection = (id2, collapsed) => {
227
- setCollapsedSections((prev) => ({
228
- ...prev,
229
- [id2]: collapsed
230
- }));
231
- };
232
- return /* @__PURE__ */ React2.createElement(AttentionProvider, {
233
- id
234
- }, /* @__PURE__ */ React2.createElement(Mosaic.Root, null, /* @__PURE__ */ React2.createElement(Mosaic.DragOverlay, null), /* @__PURE__ */ React2.createElement(Stack, {
235
- id,
236
- "data-testid": "main.stack",
237
- SectionContent,
238
- type: SECTION_IDENTIFIER,
239
- items,
240
- separation,
241
- emptyComponent: /* @__PURE__ */ React2.createElement("span", {
242
- "data-testid": "stack.empty"
243
- }),
244
- onDrop: handleDrop,
245
- onOver: handleOver,
246
- onDeleteSection: handleDelete,
247
- onNavigateToSection: handleNavigate,
248
- onAddSection: handleAddSection,
249
- onCollapseSection: handleCollapseSection
250
- }), items.length === 0 ? /* @__PURE__ */ React2.createElement(AddSection, {
251
- collection
252
- }) : /* @__PURE__ */ React2.createElement("div", {
253
- role: "none",
254
- className: "flex mlb-2 pli-2 justify-center"
255
- }, /* @__PURE__ */ React2.createElement(Button, {
256
- "data-testid": "stack.createSection",
257
- classNames: "gap-2",
258
- onClick: () => dispatch?.({
259
- action: LayoutAction.SET_LAYOUT,
260
- data: {
261
- element: "dialog",
262
- component: "dxos.org/plugin/stack/AddSectionDialog",
263
- subject: {
264
- position: "afterAll",
265
- collection
266
- }
267
- }
268
- })
269
- }, /* @__PURE__ */ React2.createElement(Plus, null), /* @__PURE__ */ React2.createElement("span", {
270
- className: "sr-only"
271
- }, t("add section label"))))));
272
- };
273
- var StackMain_default = StackMain;
274
- export {
275
- StackMain_default as default
276
- };
277
- //# sourceMappingURL=StackMain-KKC3XIAY.mjs.map
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../../src/components/StackMain.tsx", "../../../src/components/AddSection.tsx"],
4
- "sourcesContent": ["//\n// Copyright 2023 DXOS.org\n//\n\nimport { Plus } from '@phosphor-icons/react';\nimport React, { useEffect, useMemo, useState } from 'react';\n\nimport {\n LayoutAction,\n NavigationAction,\n Surface,\n parseMetadataResolverPlugin,\n useIntentDispatcher,\n useResolvePlugin,\n} from '@dxos/app-framework';\nimport { create, getType, fullyQualifiedId, isReactiveObject } from '@dxos/client/echo';\nimport { useGraph } from '@dxos/plugin-graph';\nimport { SpaceAction } from '@dxos/plugin-space';\nimport { type CollectionType } from '@dxos/plugin-space/types';\nimport { Button, toLocalizedString, useTranslation } from '@dxos/react-ui';\nimport { AttentionProvider } from '@dxos/react-ui-attention';\nimport { type MosaicDataItem, type MosaicDropEvent, type MosaicMoveEvent, Mosaic, Path } from '@dxos/react-ui-mosaic';\nimport {\n type AddSectionPosition,\n type CollapsedSections,\n Stack,\n type StackProps,\n type StackSectionItem,\n} from '@dxos/react-ui-stack';\nimport { nonNullable } from '@dxos/util';\n\nimport { AddSection } from './AddSection';\nimport { SECTION_IDENTIFIER, STACK_PLUGIN } from '../meta';\nimport { StackViewType } from '../types';\n\nconst SectionContent: StackProps['SectionContent'] = ({ data }) => {\n // TODO(wittjosiah): Better section placeholder.\n return <Surface role='section' data={{ object: data }} limit={1} placeholder={<></>} />;\n};\n\ntype StackMainProps = {\n id: string;\n collection: CollectionType;\n separation?: boolean;\n};\n\nconst StackMain = ({ id, collection, separation }: StackMainProps) => {\n const dispatch = useIntentDispatcher();\n const { graph } = useGraph();\n const { t } = useTranslation(STACK_PLUGIN);\n const metadataPlugin = useResolvePlugin(parseMetadataResolverPlugin);\n const defaultStack = useMemo(() => create(StackViewType, { sections: {} }), [collection]);\n const stack = (collection.views[StackViewType.typename] as StackViewType) ?? defaultStack;\n const [collapsedSections, setCollapsedSections] = useState<CollapsedSections>({});\n\n useEffect(() => {\n if (!collection.views[StackViewType.typename]) {\n collection.views[StackViewType.typename] = stack;\n }\n }, [collection, stack]);\n\n const items =\n collection.objects\n // TODO(wittjosiah): Should the database handle this differently?\n // TODO(wittjosiah): Render placeholders for missing objects so they can be removed from the stack?\n .filter(nonNullable)\n .map((object) => {\n const metadata = metadataPlugin?.provides.metadata.resolver(\n getType(object)?.objectId ?? 'never',\n ) as StackSectionItem['metadata'];\n const view = {\n ...stack.sections[object.id],\n collapsed: collapsedSections[fullyQualifiedId(object)],\n title:\n (object as any)?.title ?? toLocalizedString(graph.findNode(fullyQualifiedId(object))?.properties.label, t),\n } as StackSectionItem['view'];\n return { id: fullyQualifiedId(object), object, metadata, view };\n }) ?? [];\n\n const handleOver = ({ active, over }: MosaicMoveEvent<number>) => {\n // TODO(thure): Eventually Stack should handle foreign draggables.\n if (active.type !== SECTION_IDENTIFIER) {\n return 'reject';\n }\n if (Path.parent(active.path) === Path.parent(over.path)) {\n return 'rearrange';\n }\n\n const parseData = metadataPlugin?.provides.metadata.resolver(active.type)?.parse;\n const data = parseData ? parseData(active.item, 'object') : active.item;\n\n // TODO(wittjosiah): Prevent dropping items which don't have a section renderer?\n // Perhaps stack plugin should just provide a fallback section renderer.\n if (!isReactiveObject(data)) {\n return 'reject';\n }\n\n const exists = items.findIndex(({ id }) => id === active.item.id) >= 0;\n if (!exists) {\n return 'transfer';\n } else {\n return 'reject';\n }\n };\n\n const handleDrop = ({ operation, active, over }: MosaicDropEvent<number>) => {\n if (\n (active.path === Path.create(id, active.item.id) || active.path === id) &&\n (operation !== 'copy' || over.path === Path.create(id, over.item.id) || over.path === id)\n ) {\n collection.objects.splice(active.position!, 1);\n delete stack.sections[active.item.id];\n }\n\n const parseData = metadataPlugin?.provides.metadata.resolver(active.type)?.parse;\n const object = parseData?.(active.item, 'object');\n if (object && over.path === Path.create(id, over.item.id)) {\n collection.objects.splice(over.position!, 0, object);\n } else if (object && over.path === id) {\n collection.objects.push(object);\n }\n\n if (!stack.sections[object.id]) {\n stack.sections[object.id] = {};\n }\n };\n\n const handleDelete = async (path: string) => {\n const index = collection.objects\n .filter(nonNullable)\n .findIndex((section) => fullyQualifiedId(section) === Path.last(path));\n if (index >= 0) {\n await dispatch({\n action: SpaceAction.REMOVE_OBJECT,\n data: { object: collection.objects[index], collection },\n });\n\n // TODO(wittjosiah): The section should also be removed, but needs to be restored if the action is undone.\n // delete stack.sections[Path.last(path)];\n }\n };\n\n // TODO(wittjosiah): Factor out.\n\n const handleNavigate = async (object: MosaicDataItem) => {\n const toId = fullyQualifiedId(object);\n await dispatch([\n {\n action: NavigationAction.OPEN,\n data: { activeParts: { main: [toId] } },\n },\n {\n action: LayoutAction.SCROLL_INTO_VIEW,\n data: { id: toId },\n },\n ]);\n };\n\n const handleAddSection = (path: string, position: AddSectionPosition) => {\n void dispatch?.({\n action: LayoutAction.SET_LAYOUT,\n data: {\n element: 'dialog',\n component: `${STACK_PLUGIN}/AddSectionDialog`,\n subject: { path, position, collection },\n },\n });\n };\n\n const handleCollapseSection = (id: string, collapsed: boolean) => {\n setCollapsedSections((prev) => ({ ...prev, [id]: collapsed }));\n };\n\n return (\n <AttentionProvider id={id}>\n <Mosaic.Root>\n <Mosaic.DragOverlay />\n <Stack\n id={id}\n data-testid='main.stack'\n SectionContent={SectionContent}\n type={SECTION_IDENTIFIER}\n items={items}\n separation={separation}\n emptyComponent={<span data-testid='stack.empty'></span>}\n onDrop={handleDrop}\n onOver={handleOver}\n onDeleteSection={handleDelete}\n onNavigateToSection={handleNavigate}\n onAddSection={handleAddSection}\n onCollapseSection={handleCollapseSection}\n />\n\n {items.length === 0 ? (\n <AddSection collection={collection} />\n ) : (\n <div role='none' className='flex mlb-2 pli-2 justify-center'>\n <Button\n data-testid='stack.createSection'\n classNames='gap-2'\n onClick={() =>\n dispatch?.({\n action: LayoutAction.SET_LAYOUT,\n data: {\n element: 'dialog',\n component: 'dxos.org/plugin/stack/AddSectionDialog',\n subject: { position: 'afterAll', collection },\n },\n })\n }\n >\n <Plus />\n <span className='sr-only'>{t('add section label')}</span>\n </Button>\n </div>\n )}\n </Mosaic.Root>\n </AttentionProvider>\n );\n};\n\nexport default StackMain;\n", "//\n// Copyright 2024 DXOS.org\n//\n\nimport { useArrowNavigationGroup } from '@fluentui/react-tabster';\nimport { type IconProps } from '@phosphor-icons/react';\nimport React, { type FC, type KeyboardEvent, type MouseEvent, useCallback } from 'react';\n\nimport { usePlugin, useIntentDispatcher } from '@dxos/app-framework';\nimport { type CollectionType } from '@dxos/plugin-space/types';\nimport { toLocalizedString, useTranslation } from '@dxos/react-ui';\nimport { getSize, mx } from '@dxos/react-ui-theme';\n\nimport { STACK_PLUGIN } from '../meta';\nimport { StackViewType, type StackSectionCreator, type StackPluginProvides } from '../types';\n\nconst CreatorTile = ({\n Icon,\n label,\n testId,\n handleAdd,\n}: {\n Icon: FC<IconProps>;\n testId: string;\n label: string;\n handleAdd: () => void;\n}) => {\n const onClick = useCallback((_: MouseEvent<HTMLDivElement>) => handleAdd(), [handleAdd]);\n const onKeyDown = useCallback(\n (event: KeyboardEvent<HTMLDivElement>) => {\n if (event.key === 'Enter' || event.key === ' ') {\n event.preventDefault();\n handleAdd();\n }\n },\n [handleAdd],\n );\n\n return (\n <div\n role='button'\n aria-label={label}\n tabIndex={0}\n className={mx(\n 'flex items-center w-[10rem] h-16 overflow-hidden',\n 'border rounded-md border-separator shadow-sm hover:bg-hoverSurface cursor-pointer',\n )}\n onClick={onClick}\n onKeyDown={onKeyDown}\n data-testid={testId}\n >\n <div className='flex h-full w-12 items-center justify-center bg-scrim shrink-0 border-r border-separator'>\n <Icon weight='thin' className={getSize(6)} />\n </div>\n <div className='overflow-hidden items-center p-2 px-3'>\n <span className='capitalize'>{label}</span>\n </div>\n </div>\n );\n};\n\nexport const AddSection = ({ collection }: { collection: CollectionType }) => {\n const domAttributes = useArrowNavigationGroup({ axis: 'grid' });\n const dispatch = useIntentDispatcher();\n const { t } = useTranslation(STACK_PLUGIN);\n\n const stackPlugin = usePlugin<StackPluginProvides>(STACK_PLUGIN);\n const stackCreators = stackPlugin?.provides?.stack.creators ?? [];\n\n const handleAdd = useCallback(\n async (creator: StackSectionCreator) => {\n const { data: section } = (await dispatch(creator.intent)) ?? {};\n collection.objects = [section];\n const stack = collection.views[StackViewType.typename];\n if (stack) {\n stack.sections[section.id] = {};\n }\n },\n [collection, dispatch],\n );\n\n if (stackCreators.length === 0) {\n return null;\n }\n\n return (\n <div {...domAttributes} role='none' className='flex flex-wrap items-center p-8 gap-4'>\n {stackCreators.map((creator) => {\n const { id, type, icon, testId } = creator;\n return (\n <CreatorTile\n key={id}\n label={toLocalizedString(type, t)}\n testId={testId}\n Icon={icon}\n handleAdd={() => handleAdd(creator)}\n />\n );\n })}\n </div>\n );\n};\n"],
5
- "mappings": ";;;;;;;;;AAIA,SAASA,YAAY;AACrB,OAAOC,UAASC,WAAWC,SAASC,gBAAgB;AAEpD,SACEC,cACAC,kBACAC,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0G,YAAAA;IAAWlG;OAEZ,gBAAAR,OAAA,cAAC2G,OAAAA;IAAIzG,MAAK;IAAO0G,WAAU;KACzB,gBAAA5G,OAAA,cAAC6G,QAAAA;IACCb,eAAY;IACZc,YAAW;IACXC,SAAS,MACPrG,WAAW;MACT+D,QAAQS,aAAaG;MACrBtF,MAAM;QACJuF,SAAS;QACTC,WAAW;QACXC,SAAS;UAAErB,UAAU;UAAY3D;QAAW;MAC9C;IACF,CAAA;KAGF,gBAAAR,OAAA,cAACgH,MAAAA,IAAAA,GACD,gBAAAhH,OAAA,cAACkG,QAAAA;IAAKU,WAAU;KAAW9F,EAAE,mBAAA,CAAA,CAAA,CAAA,CAAA,CAAA;AAO3C;AAEA,IAAA,oBAAeR;",
6
- "names": ["Plus", "React", "useEffect", "useMemo", "useState", "LayoutAction", "NavigationAction", "Surface", "parseMetadataResolverPlugin", "useIntentDispatcher", "useResolvePlugin", "create", "getType", "fullyQualifiedId", "isReactiveObject", "useGraph", "SpaceAction", "Button", "toLocalizedString", "useTranslation", "AttentionProvider", "Mosaic", "Path", "Stack", "nonNullable", "useArrowNavigationGroup", "React", "useCallback", "usePlugin", "useIntentDispatcher", "toLocalizedString", "useTranslation", "getSize", "mx", "CreatorTile", "Icon", "label", "testId", "handleAdd", "onClick", "useCallback", "_", "onKeyDown", "event", "key", "preventDefault", "div", "role", "aria-label", "tabIndex", "className", "mx", "data-testid", "weight", "getSize", "span", "AddSection", "collection", "domAttributes", "useArrowNavigationGroup", "axis", "dispatch", "useIntentDispatcher", "t", "useTranslation", "STACK_PLUGIN", "stackPlugin", "usePlugin", "stackCreators", "provides", "stack", "creators", "creator", "data", "section", "intent", "objects", "views", "StackViewType", "typename", "sections", "id", "length", "map", "type", "icon", "toLocalizedString", "SectionContent", "data", "React", "Surface", "role", "object", "limit", "placeholder", "StackMain", "id", "collection", "separation", "dispatch", "useIntentDispatcher", "graph", "useGraph", "t", "useTranslation", "STACK_PLUGIN", "metadataPlugin", "useResolvePlugin", "parseMetadataResolverPlugin", "defaultStack", "useMemo", "create", "StackViewType", "sections", "stack", "views", "typename", "collapsedSections", "setCollapsedSections", "useState", "useEffect", "items", "objects", "filter", "nonNullable", "map", "metadata", "provides", "resolver", "getType", "objectId", "view", "collapsed", "fullyQualifiedId", "title", "toLocalizedString", "findNode", "properties", "label", "handleOver", "active", "over", "type", "SECTION_IDENTIFIER", "Path", "parent", "path", "parseData", "parse", "item", "isReactiveObject", "exists", "findIndex", "handleDrop", "operation", "splice", "position", "push", "handleDelete", "index", "section", "last", "action", "SpaceAction", "REMOVE_OBJECT", "handleNavigate", "toId", "NavigationAction", "OPEN", "activeParts", "main", "LayoutAction", "SCROLL_INTO_VIEW", "handleAddSection", "SET_LAYOUT", "element", "component", "subject", "handleCollapseSection", "prev", "AttentionProvider", "Mosaic", "Root", "DragOverlay", "Stack", "data-testid", "emptyComponent", "span", "onDrop", "onOver", "onDeleteSection", "onNavigateToSection", "onAddSection", "onCollapseSection", "length", "AddSection", "div", "className", "Button", "classNames", "onClick", "Plus"]
7
- }
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../../src/meta.ts"],
4
- "sourcesContent": ["//\n// Copyright 2023 DXOS.org\n//\n\nimport { type PluginMeta } from '@dxos/app-framework';\n\nexport const STACK_PLUGIN = 'dxos.org/plugin/stack';\nexport const SECTION_IDENTIFIER = 'dxos.org/type/StackSection';\n\nexport default {\n id: STACK_PLUGIN,\n // TODO(wittjosiah): Prevents \"stacks\" language from being exposed to users in settings panel.\n name: 'Collections',\n icon: 'ph--stack-simple--regular',\n} satisfies PluginMeta;\n"],
5
- "mappings": ";AAMO,IAAMA,eAAe;AACrB,IAAMC,qBAAqB;AAElC,IAAA,eAAe;EACbC,IAAIF;;EAEJG,MAAM;EACNC,MAAM;AACR;",
6
- "names": ["STACK_PLUGIN", "SECTION_IDENTIFIER", "id", "name", "icon"]
7
- }
@@ -1,296 +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_ME6LYFGI_exports = {};
30
- __export(StackMain_ME6LYFGI_exports, {
31
- default: () => StackMain_default
32
- });
33
- module.exports = __toCommonJS(StackMain_ME6LYFGI_exports);
34
- var import_chunk_O5SQVKNW = require("./chunk-O5SQVKNW.cjs");
35
- var import_chunk_6IPBX635 = require("./chunk-6IPBX635.cjs");
36
- var import_react = require("@phosphor-icons/react");
37
- var import_react2 = __toESM(require("react"));
38
- var import_app_framework = require("@dxos/app-framework");
39
- var import_echo = require("@dxos/client/echo");
40
- var import_plugin_graph = require("@dxos/plugin-graph");
41
- var import_plugin_space = require("@dxos/plugin-space");
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_mosaic = require("@dxos/react-ui-mosaic");
45
- var import_react_ui_stack = require("@dxos/react-ui-stack");
46
- var import_util = require("@dxos/util");
47
- var import_react_tabster = require("@fluentui/react-tabster");
48
- var import_react3 = __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_theme = require("@dxos/react-ui-theme");
52
- var CreatorTile = ({ Icon, label, testId, handleAdd }) => {
53
- const onClick = (0, import_react3.useCallback)((_) => handleAdd(), [
54
- handleAdd
55
- ]);
56
- const onKeyDown = (0, import_react3.useCallback)((event) => {
57
- if (event.key === "Enter" || event.key === " ") {
58
- event.preventDefault();
59
- handleAdd();
60
- }
61
- }, [
62
- handleAdd
63
- ]);
64
- return /* @__PURE__ */ import_react3.default.createElement("div", {
65
- role: "button",
66
- "aria-label": label,
67
- tabIndex: 0,
68
- className: (0, import_react_ui_theme.mx)("flex items-center w-[10rem] h-16 overflow-hidden", "border rounded-md border-separator shadow-sm hover:bg-hoverSurface cursor-pointer"),
69
- onClick,
70
- onKeyDown,
71
- "data-testid": testId
72
- }, /* @__PURE__ */ import_react3.default.createElement("div", {
73
- className: "flex h-full w-12 items-center justify-center bg-scrim shrink-0 border-r border-separator"
74
- }, /* @__PURE__ */ import_react3.default.createElement(Icon, {
75
- weight: "thin",
76
- className: (0, import_react_ui_theme.getSize)(6)
77
- })), /* @__PURE__ */ import_react3.default.createElement("div", {
78
- className: "overflow-hidden items-center p-2 px-3"
79
- }, /* @__PURE__ */ import_react3.default.createElement("span", {
80
- className: "capitalize"
81
- }, label)));
82
- };
83
- var AddSection = ({ collection }) => {
84
- const domAttributes = (0, import_react_tabster.useArrowNavigationGroup)({
85
- axis: "grid"
86
- });
87
- const dispatch = (0, import_app_framework2.useIntentDispatcher)();
88
- const { t } = (0, import_react_ui2.useTranslation)(import_chunk_O5SQVKNW.STACK_PLUGIN);
89
- const stackPlugin = (0, import_app_framework2.usePlugin)(import_chunk_O5SQVKNW.STACK_PLUGIN);
90
- const stackCreators = stackPlugin?.provides?.stack.creators ?? [];
91
- const handleAdd = (0, import_react3.useCallback)(async (creator) => {
92
- const { data: section } = await dispatch(creator.intent) ?? {};
93
- collection.objects = [
94
- section
95
- ];
96
- const stack = collection.views[import_chunk_6IPBX635.StackViewType.typename];
97
- if (stack) {
98
- stack.sections[section.id] = {};
99
- }
100
- }, [
101
- collection,
102
- dispatch
103
- ]);
104
- if (stackCreators.length === 0) {
105
- return null;
106
- }
107
- return /* @__PURE__ */ import_react3.default.createElement("div", {
108
- ...domAttributes,
109
- role: "none",
110
- className: "flex flex-wrap items-center p-8 gap-4"
111
- }, stackCreators.map((creator) => {
112
- const { id, type, icon, testId } = creator;
113
- return /* @__PURE__ */ import_react3.default.createElement(CreatorTile, {
114
- key: id,
115
- label: (0, import_react_ui2.toLocalizedString)(type, t),
116
- testId,
117
- Icon: icon,
118
- handleAdd: () => handleAdd(creator)
119
- });
120
- }));
121
- };
122
- var SectionContent = ({ data }) => {
123
- return /* @__PURE__ */ import_react2.default.createElement(import_app_framework.Surface, {
124
- role: "section",
125
- data: {
126
- object: data
127
- },
128
- limit: 1,
129
- placeholder: /* @__PURE__ */ import_react2.default.createElement(import_react2.default.Fragment, null)
130
- });
131
- };
132
- var StackMain = ({ id, collection, separation }) => {
133
- const dispatch = (0, import_app_framework.useIntentDispatcher)();
134
- const { graph } = (0, import_plugin_graph.useGraph)();
135
- const { t } = (0, import_react_ui.useTranslation)(import_chunk_O5SQVKNW.STACK_PLUGIN);
136
- const metadataPlugin = (0, import_app_framework.useResolvePlugin)(import_app_framework.parseMetadataResolverPlugin);
137
- const defaultStack = (0, import_react2.useMemo)(() => (0, import_echo.create)(import_chunk_6IPBX635.StackViewType, {
138
- sections: {}
139
- }), [
140
- collection
141
- ]);
142
- const stack = collection.views[import_chunk_6IPBX635.StackViewType.typename] ?? defaultStack;
143
- const [collapsedSections, setCollapsedSections] = (0, import_react2.useState)({});
144
- (0, import_react2.useEffect)(() => {
145
- if (!collection.views[import_chunk_6IPBX635.StackViewType.typename]) {
146
- collection.views[import_chunk_6IPBX635.StackViewType.typename] = stack;
147
- }
148
- }, [
149
- collection,
150
- stack
151
- ]);
152
- const items = collection.objects.filter(import_util.nonNullable).map((object) => {
153
- const metadata = metadataPlugin?.provides.metadata.resolver((0, import_echo.getType)(object)?.objectId ?? "never");
154
- const view = {
155
- ...stack.sections[object.id],
156
- collapsed: collapsedSections[(0, import_echo.fullyQualifiedId)(object)],
157
- title: object?.title ?? (0, import_react_ui.toLocalizedString)(graph.findNode((0, import_echo.fullyQualifiedId)(object))?.properties.label, t)
158
- };
159
- return {
160
- id: (0, import_echo.fullyQualifiedId)(object),
161
- object,
162
- metadata,
163
- view
164
- };
165
- }) ?? [];
166
- const handleOver = ({ active, over }) => {
167
- if (active.type !== import_chunk_O5SQVKNW.SECTION_IDENTIFIER) {
168
- return "reject";
169
- }
170
- if (import_react_ui_mosaic.Path.parent(active.path) === import_react_ui_mosaic.Path.parent(over.path)) {
171
- return "rearrange";
172
- }
173
- const parseData = metadataPlugin?.provides.metadata.resolver(active.type)?.parse;
174
- const data = parseData ? parseData(active.item, "object") : active.item;
175
- if (!(0, import_echo.isReactiveObject)(data)) {
176
- return "reject";
177
- }
178
- const exists = items.findIndex(({ id: id2 }) => id2 === active.item.id) >= 0;
179
- if (!exists) {
180
- return "transfer";
181
- } else {
182
- return "reject";
183
- }
184
- };
185
- const handleDrop = ({ operation, active, over }) => {
186
- if ((active.path === import_react_ui_mosaic.Path.create(id, active.item.id) || active.path === id) && (operation !== "copy" || over.path === import_react_ui_mosaic.Path.create(id, over.item.id) || over.path === id)) {
187
- collection.objects.splice(active.position, 1);
188
- delete stack.sections[active.item.id];
189
- }
190
- const parseData = metadataPlugin?.provides.metadata.resolver(active.type)?.parse;
191
- const object = parseData?.(active.item, "object");
192
- if (object && over.path === import_react_ui_mosaic.Path.create(id, over.item.id)) {
193
- collection.objects.splice(over.position, 0, object);
194
- } else if (object && over.path === id) {
195
- collection.objects.push(object);
196
- }
197
- if (!stack.sections[object.id]) {
198
- stack.sections[object.id] = {};
199
- }
200
- };
201
- const handleDelete = async (path) => {
202
- const index = collection.objects.filter(import_util.nonNullable).findIndex((section) => (0, import_echo.fullyQualifiedId)(section) === import_react_ui_mosaic.Path.last(path));
203
- if (index >= 0) {
204
- await dispatch({
205
- action: import_plugin_space.SpaceAction.REMOVE_OBJECT,
206
- data: {
207
- object: collection.objects[index],
208
- collection
209
- }
210
- });
211
- }
212
- };
213
- const handleNavigate = async (object) => {
214
- const toId = (0, import_echo.fullyQualifiedId)(object);
215
- await dispatch([
216
- {
217
- action: import_app_framework.NavigationAction.OPEN,
218
- data: {
219
- activeParts: {
220
- main: [
221
- toId
222
- ]
223
- }
224
- }
225
- },
226
- {
227
- action: import_app_framework.LayoutAction.SCROLL_INTO_VIEW,
228
- data: {
229
- id: toId
230
- }
231
- }
232
- ]);
233
- };
234
- const handleAddSection = (path, position) => {
235
- void dispatch?.({
236
- action: import_app_framework.LayoutAction.SET_LAYOUT,
237
- data: {
238
- element: "dialog",
239
- component: `${import_chunk_O5SQVKNW.STACK_PLUGIN}/AddSectionDialog`,
240
- subject: {
241
- path,
242
- position,
243
- collection
244
- }
245
- }
246
- });
247
- };
248
- const handleCollapseSection = (id2, collapsed) => {
249
- setCollapsedSections((prev) => ({
250
- ...prev,
251
- [id2]: collapsed
252
- }));
253
- };
254
- return /* @__PURE__ */ import_react2.default.createElement(import_react_ui_attention.AttentionProvider, {
255
- id
256
- }, /* @__PURE__ */ import_react2.default.createElement(import_react_ui_mosaic.Mosaic.Root, null, /* @__PURE__ */ import_react2.default.createElement(import_react_ui_mosaic.Mosaic.DragOverlay, null), /* @__PURE__ */ import_react2.default.createElement(import_react_ui_stack.Stack, {
257
- id,
258
- "data-testid": "main.stack",
259
- SectionContent,
260
- type: import_chunk_O5SQVKNW.SECTION_IDENTIFIER,
261
- items,
262
- separation,
263
- emptyComponent: /* @__PURE__ */ import_react2.default.createElement("span", {
264
- "data-testid": "stack.empty"
265
- }),
266
- onDrop: handleDrop,
267
- onOver: handleOver,
268
- onDeleteSection: handleDelete,
269
- onNavigateToSection: handleNavigate,
270
- onAddSection: handleAddSection,
271
- onCollapseSection: handleCollapseSection
272
- }), items.length === 0 ? /* @__PURE__ */ import_react2.default.createElement(AddSection, {
273
- collection
274
- }) : /* @__PURE__ */ import_react2.default.createElement("div", {
275
- role: "none",
276
- className: "flex mlb-2 pli-2 justify-center"
277
- }, /* @__PURE__ */ import_react2.default.createElement(import_react_ui.Button, {
278
- "data-testid": "stack.createSection",
279
- classNames: "gap-2",
280
- onClick: () => dispatch?.({
281
- action: import_app_framework.LayoutAction.SET_LAYOUT,
282
- data: {
283
- element: "dialog",
284
- component: "dxos.org/plugin/stack/AddSectionDialog",
285
- subject: {
286
- position: "afterAll",
287
- collection
288
- }
289
- }
290
- })
291
- }, /* @__PURE__ */ import_react2.default.createElement(import_react.Plus, null), /* @__PURE__ */ import_react2.default.createElement("span", {
292
- className: "sr-only"
293
- }, t("add section label"))))));
294
- };
295
- var StackMain_default = StackMain;
296
- //# sourceMappingURL=StackMain-ME6LYFGI.cjs.map