@dxos/plugin-stack 0.6.12-staging.e11e696 → 0.6.12

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 (45) hide show
  1. package/dist/lib/browser/{StackMain-6GEK3XZ3.mjs → StackMain-XRQRNZ4I.mjs} +7 -9
  2. package/dist/lib/browser/StackMain-XRQRNZ4I.mjs.map +7 -0
  3. package/dist/lib/{node-esm/chunk-T42IEBEL.mjs → browser/chunk-AYDYMPJK.mjs} +5 -4
  4. package/dist/lib/browser/chunk-AYDYMPJK.mjs.map +7 -0
  5. package/dist/lib/browser/index.mjs +5 -7
  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-AMKQAQJ6.cjs → StackMain-XJGYFDDN.cjs} +15 -17
  10. package/dist/lib/node/StackMain-XJGYFDDN.cjs.map +7 -0
  11. package/dist/lib/node/{chunk-PGL7XDNJ.cjs → chunk-I42JKRXR.cjs} +18 -5
  12. package/dist/lib/node/chunk-I42JKRXR.cjs.map +7 -0
  13. package/dist/lib/node/index.cjs +43 -45
  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/types/src/StackPlugin.d.ts.map +1 -1
  19. package/dist/types/src/components/StackMain.d.ts +1 -2
  20. package/dist/types/src/components/StackMain.d.ts.map +1 -1
  21. package/dist/types/src/components/index.d.ts +1 -2
  22. package/dist/types/src/components/index.d.ts.map +1 -1
  23. package/dist/types/src/meta.d.ts +4 -1
  24. package/dist/types/src/meta.d.ts.map +1 -1
  25. package/package.json +29 -33
  26. package/src/StackPlugin.tsx +7 -16
  27. package/src/components/StackMain.tsx +44 -48
  28. package/src/meta.tsx +5 -1
  29. package/dist/lib/browser/StackMain-6GEK3XZ3.mjs.map +0 -7
  30. package/dist/lib/browser/chunk-H4O4KKLZ.mjs +0 -16
  31. package/dist/lib/browser/chunk-H4O4KKLZ.mjs.map +0 -7
  32. package/dist/lib/node/StackMain-AMKQAQJ6.cjs.map +0 -7
  33. package/dist/lib/node/chunk-PGL7XDNJ.cjs.map +0 -7
  34. package/dist/lib/node-esm/StackMain-BQ5KK6F4.mjs +0 -279
  35. package/dist/lib/node-esm/StackMain-BQ5KK6F4.mjs.map +0 -7
  36. package/dist/lib/node-esm/chunk-4ULAI3BI.mjs +0 -23
  37. package/dist/lib/node-esm/chunk-4ULAI3BI.mjs.map +0 -7
  38. package/dist/lib/node-esm/chunk-T42IEBEL.mjs.map +0 -7
  39. package/dist/lib/node-esm/index.mjs +0 -288
  40. package/dist/lib/node-esm/index.mjs.map +0 -7
  41. package/dist/lib/node-esm/meta.json +0 -1
  42. package/dist/lib/node-esm/meta.mjs +0 -12
  43. package/dist/lib/node-esm/meta.mjs.map +0 -7
  44. package/dist/lib/node-esm/types/index.mjs +0 -10
  45. package/dist/lib/node-esm/types/index.mjs.map +0 -7
@@ -1,279 +0,0 @@
1
- import { createRequire } from 'node:module';const require = createRequire(import.meta.url);
2
- import {
3
- SECTION_IDENTIFIER,
4
- STACK_PLUGIN
5
- } from "./chunk-T42IEBEL.mjs";
6
- import {
7
- StackViewType
8
- } from "./chunk-4ULAI3BI.mjs";
9
-
10
- // packages/plugins/plugin-stack/src/components/StackMain.tsx
11
- import { Plus } from "@phosphor-icons/react";
12
- import React2, { useEffect, useMemo, useState } from "react";
13
- import { LayoutAction, NavigationAction, parseMetadataResolverPlugin, Surface, useIntentDispatcher as useIntentDispatcher2, useResolvePlugin } from "@dxos/app-framework";
14
- import { create, getType, isReactiveObject } from "@dxos/echo-schema";
15
- import { useGraph } from "@dxos/plugin-graph";
16
- import { SpaceAction } from "@dxos/plugin-space";
17
- import { fullyQualifiedId } from "@dxos/react-client/echo";
18
- import { Button, toLocalizedString as toLocalizedString2, useTranslation as useTranslation2 } from "@dxos/react-ui";
19
- import { AttentionProvider } from "@dxos/react-ui-attention";
20
- import { Mosaic, Path } from "@dxos/react-ui-mosaic";
21
- import { Stack } from "@dxos/react-ui-stack";
22
- import { nonNullable } from "@dxos/util";
23
-
24
- // packages/plugins/plugin-stack/src/components/AddSection.tsx
25
- import { useArrowNavigationGroup } from "@fluentui/react-tabster";
26
- import React, { useCallback } from "react";
27
- import { usePlugin, useIntentDispatcher } from "@dxos/app-framework";
28
- import { toLocalizedString, useTranslation } from "@dxos/react-ui";
29
- import { getSize, mx } from "@dxos/react-ui-theme";
30
- var CreatorTile = ({ Icon, label, testId, handleAdd }) => {
31
- const onClick = useCallback((_) => handleAdd(), [
32
- handleAdd
33
- ]);
34
- const onKeyDown = useCallback((event) => {
35
- if (event.key === "Enter" || event.key === " ") {
36
- event.preventDefault();
37
- handleAdd();
38
- }
39
- }, [
40
- handleAdd
41
- ]);
42
- return /* @__PURE__ */ React.createElement("div", {
43
- role: "button",
44
- "aria-label": label,
45
- tabIndex: 0,
46
- className: mx("flex items-center w-[10rem] h-16 overflow-hidden", "border rounded-md border-separator shadow-sm hover:bg-hoverSurface cursor-pointer"),
47
- onClick,
48
- onKeyDown,
49
- "data-testid": testId
50
- }, /* @__PURE__ */ React.createElement("div", {
51
- className: "flex h-full w-12 items-center justify-center bg-scrim shrink-0 border-r border-separator"
52
- }, /* @__PURE__ */ React.createElement(Icon, {
53
- weight: "thin",
54
- className: getSize(6)
55
- })), /* @__PURE__ */ React.createElement("div", {
56
- className: "overflow-hidden items-center p-2 px-3"
57
- }, /* @__PURE__ */ React.createElement("span", {
58
- className: "capitalize"
59
- }, label)));
60
- };
61
- var AddSection = ({ collection }) => {
62
- const domAttributes = useArrowNavigationGroup({
63
- axis: "grid"
64
- });
65
- const dispatch = useIntentDispatcher();
66
- const { t } = useTranslation(STACK_PLUGIN);
67
- const stackPlugin = usePlugin(STACK_PLUGIN);
68
- const stackCreators = stackPlugin?.provides?.stack.creators ?? [];
69
- const handleAdd = useCallback(async (creator) => {
70
- const { data: section } = await dispatch(creator.intent) ?? {};
71
- collection.objects = [
72
- section
73
- ];
74
- const stack = collection.views[StackViewType.typename];
75
- if (stack) {
76
- stack.sections[section.id] = {};
77
- }
78
- }, [
79
- collection,
80
- dispatch
81
- ]);
82
- if (stackCreators.length === 0) {
83
- return null;
84
- }
85
- return /* @__PURE__ */ React.createElement("div", {
86
- ...domAttributes,
87
- role: "none",
88
- className: "flex flex-wrap items-center p-8 gap-4"
89
- }, stackCreators.map((creator) => {
90
- const { id, type, icon, testId } = creator;
91
- return /* @__PURE__ */ React.createElement(CreatorTile, {
92
- key: id,
93
- label: toLocalizedString(type, t),
94
- testId,
95
- Icon: icon,
96
- handleAdd: () => handleAdd(creator)
97
- });
98
- }));
99
- };
100
-
101
- // packages/plugins/plugin-stack/src/components/StackMain.tsx
102
- var SectionContent = ({ data }) => {
103
- return /* @__PURE__ */ React2.createElement(Surface, {
104
- role: "section",
105
- data: {
106
- object: data
107
- },
108
- limit: 1,
109
- placeholder: /* @__PURE__ */ React2.createElement(React2.Fragment, null)
110
- });
111
- };
112
- var StackMain = ({ id, collection, separation }) => {
113
- const dispatch = useIntentDispatcher2();
114
- const { graph } = useGraph();
115
- const { t } = useTranslation2(STACK_PLUGIN);
116
- const metadataPlugin = useResolvePlugin(parseMetadataResolverPlugin);
117
- const defaultStack = useMemo(() => create(StackViewType, {
118
- sections: {}
119
- }), [
120
- collection
121
- ]);
122
- const stack = collection.views[StackViewType.typename] ?? defaultStack;
123
- const [collapsedSections, setCollapsedSections] = useState({});
124
- useEffect(() => {
125
- if (!collection.views[StackViewType.typename]) {
126
- collection.views[StackViewType.typename] = stack;
127
- }
128
- }, [
129
- collection,
130
- stack
131
- ]);
132
- const items = collection.objects.filter(nonNullable).map((object) => {
133
- const metadata = metadataPlugin?.provides.metadata.resolver(getType(object)?.objectId ?? "never");
134
- const view = {
135
- ...stack.sections[object.id],
136
- collapsed: collapsedSections[fullyQualifiedId(object)],
137
- title: object?.title ?? toLocalizedString2(graph.findNode(fullyQualifiedId(object))?.properties.label, t)
138
- };
139
- return {
140
- id: fullyQualifiedId(object),
141
- object,
142
- metadata,
143
- view
144
- };
145
- }) ?? [];
146
- const handleOver = ({ active, over }) => {
147
- if (active.type !== SECTION_IDENTIFIER) {
148
- return "reject";
149
- }
150
- if (Path.parent(active.path) === Path.parent(over.path)) {
151
- return "rearrange";
152
- }
153
- const parseData = metadataPlugin?.provides.metadata.resolver(active.type)?.parse;
154
- const data = parseData ? parseData(active.item, "object") : active.item;
155
- if (!isReactiveObject(data)) {
156
- return "reject";
157
- }
158
- const exists = items.findIndex(({ id: id2 }) => id2 === active.item.id) >= 0;
159
- if (!exists) {
160
- return "transfer";
161
- } else {
162
- return "reject";
163
- }
164
- };
165
- const handleDrop = ({ operation, active, over }) => {
166
- 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)) {
167
- collection.objects.splice(active.position, 1);
168
- delete stack.sections[active.item.id];
169
- }
170
- const parseData = metadataPlugin?.provides.metadata.resolver(active.type)?.parse;
171
- const object = parseData?.(active.item, "object");
172
- if (object && over.path === Path.create(id, over.item.id)) {
173
- collection.objects.splice(over.position, 0, object);
174
- } else if (object && over.path === id) {
175
- collection.objects.push(object);
176
- }
177
- if (!stack.sections[object.id]) {
178
- stack.sections[object.id] = {};
179
- }
180
- };
181
- const handleDelete = async (path) => {
182
- const index = collection.objects.filter(nonNullable).findIndex((section) => fullyQualifiedId(section) === Path.last(path));
183
- if (index >= 0) {
184
- await dispatch({
185
- action: SpaceAction.REMOVE_OBJECT,
186
- data: {
187
- object: collection.objects[index],
188
- collection
189
- }
190
- });
191
- }
192
- };
193
- const handleNavigate = async (object) => {
194
- const toId = fullyQualifiedId(object);
195
- await dispatch([
196
- {
197
- action: NavigationAction.OPEN,
198
- data: {
199
- activeParts: {
200
- main: [
201
- toId
202
- ]
203
- }
204
- }
205
- },
206
- {
207
- action: LayoutAction.SCROLL_INTO_VIEW,
208
- data: {
209
- id: toId
210
- }
211
- }
212
- ]);
213
- };
214
- const handleAddSection = (path, position) => {
215
- void dispatch?.({
216
- action: LayoutAction.SET_LAYOUT,
217
- data: {
218
- element: "dialog",
219
- component: `${STACK_PLUGIN}/AddSectionDialog`,
220
- subject: {
221
- path,
222
- position,
223
- collection
224
- }
225
- }
226
- });
227
- };
228
- const handleCollapseSection = (id2, collapsed) => {
229
- setCollapsedSections((prev) => ({
230
- ...prev,
231
- [id2]: collapsed
232
- }));
233
- };
234
- return /* @__PURE__ */ React2.createElement(AttentionProvider, {
235
- id
236
- }, /* @__PURE__ */ React2.createElement(Mosaic.Root, null, /* @__PURE__ */ React2.createElement(Mosaic.DragOverlay, null), /* @__PURE__ */ React2.createElement(Stack, {
237
- id,
238
- "data-testid": "main.stack",
239
- SectionContent,
240
- type: SECTION_IDENTIFIER,
241
- items,
242
- separation,
243
- emptyComponent: /* @__PURE__ */ React2.createElement("span", {
244
- "data-testid": "stack.empty"
245
- }),
246
- onDrop: handleDrop,
247
- onOver: handleOver,
248
- onDeleteSection: handleDelete,
249
- onNavigateToSection: handleNavigate,
250
- onAddSection: handleAddSection,
251
- onCollapseSection: handleCollapseSection
252
- }), items.length === 0 ? /* @__PURE__ */ React2.createElement(AddSection, {
253
- collection
254
- }) : /* @__PURE__ */ React2.createElement("div", {
255
- role: "none",
256
- className: "flex mlb-2 pli-2 justify-center"
257
- }, /* @__PURE__ */ React2.createElement(Button, {
258
- "data-testid": "stack.createSection",
259
- classNames: "gap-2",
260
- onClick: () => dispatch?.({
261
- action: LayoutAction.SET_LAYOUT,
262
- data: {
263
- element: "dialog",
264
- component: "dxos.org/plugin/stack/AddSectionDialog",
265
- subject: {
266
- position: "afterAll",
267
- collection
268
- }
269
- }
270
- })
271
- }, /* @__PURE__ */ React2.createElement(Plus, null), /* @__PURE__ */ React2.createElement("span", {
272
- className: "sr-only"
273
- }, t("add section label"))))));
274
- };
275
- var StackMain_default = StackMain;
276
- export {
277
- StackMain_default as default
278
- };
279
- //# sourceMappingURL=StackMain-BQ5KK6F4.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 parseMetadataResolverPlugin,\n Surface,\n useIntentDispatcher,\n useResolvePlugin,\n} from '@dxos/app-framework';\nimport { create, getType, isReactiveObject } from '@dxos/echo-schema';\nimport { useGraph } from '@dxos/plugin-graph';\nimport { SpaceAction } from '@dxos/plugin-space';\nimport { type CollectionType } from '@dxos/plugin-space/types';\nimport { fullyQualifiedId } from '@dxos/react-client/echo';\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,6BACAC,SACAC,uBAAAA,sBACAC,wBACK;AACP,SAASC,QAAQC,SAASC,wBAAwB;AAClD,SAASC,gBAAgB;AACzB,SAASC,mBAAmB;AAE5B,SAASC,wBAAwB;AACjC,SAASC,QAAQC,qBAAAA,oBAAmBC,kBAAAA,uBAAsB;AAC1D,SAASC,yBAAyB;AAClC,SAA0EC,QAAQC,YAAY;AAC9F,SAGEC,aAGK;AACP,SAASC,mBAAmB;;;AC1B5B,SAASC,+BAA+B;AAExC,OAAOC,SAAuDC,mBAAmB;AAEjF,SAASC,WAAWC,2BAA2B;AAE/C,SAASC,mBAAmBC,sBAAsB;AAClD,SAASC,SAASC,UAAU;AAK5B,IAAMC,cAAc,CAAC,EACnBC,MACAC,OACAC,QACAC,UAAS,MAMV;AACC,QAAMC,UAAUC,YAAY,CAACC,MAAkCH,UAAAA,GAAa;IAACA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;MACrBtF,MAAM;QACJuF,SAAS;QACTC,WAAW,GAAGvE,YAAAA;QACdwE,SAAS;UAAE/B;UAAMU;UAAU3D;QAAW;MACxC;IACF,CAAA;EACF;AAEA,QAAMiF,wBAAwB,CAAClF,KAAYoC,cAAAA;AACzCd,yBAAqB,CAAC6D,UAAU;MAAE,GAAGA;MAAM,CAACnF,GAAAA,GAAKoC;IAAU,EAAA;EAC7D;AAEA,SACE,gBAAA3C,OAAA,cAAC2F,mBAAAA;IAAkBpF;KACjB,gBAAAP,OAAA,cAAC4F,OAAOC,MAAI,MACV,gBAAA7F,OAAA,cAAC4F,OAAOE,aAAW,IAAA,GACnB,gBAAA9F,OAAA,cAAC+F,OAAAA;IACCxF;IACAyF,eAAY;IACZlG;IACAuD,MAAMC;IACNtB;IACAvB;IACAwF,gBAAgB,gBAAAjG,OAAA,cAACkG,QAAAA;MAAKF,eAAY;;IAClCG,QAAQnC;IACRoC,QAAQlD;IACRmD,iBAAiBhC;IACjBiC,qBAAqB1B;IACrB2B,cAAcnB;IACdoB,mBAAmBf;MAGpBzD,MAAMyE,WAAW,IAChB,gBAAAzG,OAAA,cAAC0G,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", "parseMetadataResolverPlugin", "Surface", "useIntentDispatcher", "useResolvePlugin", "create", "getType", "isReactiveObject", "useGraph", "SpaceAction", "fullyQualifiedId", "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,23 +0,0 @@
1
- import { createRequire } from 'node:module';const require = createRequire(import.meta.url);
2
-
3
- // packages/plugins/plugin-stack/src/types/stack.ts
4
- import { S, TypedObject } from "@dxos/echo-schema";
5
- var SectionSchema = S.Struct({
6
- height: S.optional(S.Number),
7
- // Space for data that isn't stack-specific but is specific to this view instance.
8
- // e.g. cover/fill for an image
9
- custom: S.optional(S.Record(S.String, S.Any))
10
- });
11
- var StackViewType = class extends TypedObject({
12
- typename: "dxos.org/type/StackView",
13
- version: "0.1.0"
14
- })({
15
- sections: S.mutable(S.Record(S.String, SectionSchema))
16
- }) {
17
- };
18
-
19
- export {
20
- SectionSchema,
21
- StackViewType
22
- };
23
- //# sourceMappingURL=chunk-4ULAI3BI.mjs.map
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../../src/types/stack.ts"],
4
- "sourcesContent": ["//\n// Copyright 2024 DXOS.org\n//\n\nimport { S, TypedObject } from '@dxos/echo-schema';\n\n// All section metadata needs to be optional/have defaults.\n// Any objects added to the collection will start with the section defaults.\n// If an object is removed from the collection without removing the section metadata this is fine.\n// Stack component should cleanup the superfluous data on future edits.\n\nexport const SectionSchema = S.Struct({\n height: S.optional(S.Number),\n // Space for data that isn't stack-specific but is specific to this view instance.\n // e.g. cover/fill for an image\n custom: S.optional(S.Record(S.String, S.Any)),\n});\n\nexport class StackViewType extends TypedObject({ typename: 'dxos.org/type/StackView', version: '0.1.0' })({\n sections: S.mutable(S.Record(S.String, SectionSchema)),\n}) {}\n"],
5
- "mappings": ";;;AAIA,SAASA,GAAGC,mBAAmB;AAOxB,IAAMC,gBAAgBC,EAAEC,OAAO;EACpCC,QAAQF,EAAEG,SAASH,EAAEI,MAAM;;;EAG3BC,QAAQL,EAAEG,SAASH,EAAEM,OAAON,EAAEO,QAAQP,EAAEQ,GAAG,CAAA;AAC7C,CAAA;AAEO,IAAMC,gBAAN,cAA4BC,YAAY;EAAEC,UAAU;EAA2BC,SAAS;AAAQ,CAAA,EAAG;EACxGC,UAAUb,EAAEc,QAAQd,EAAEM,OAAON,EAAEO,QAAQR,aAAAA,CAAAA;AACzC,CAAA,EAAA;AAAI;",
6
- "names": ["S", "TypedObject", "SectionSchema", "S", "Struct", "height", "optional", "Number", "custom", "Record", "String", "Any", "StackViewType", "TypedObject", "typename", "version", "sections", "mutable"]
7
- }
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../../src/meta.tsx"],
4
- "sourcesContent": ["//\n// Copyright 2023 DXOS.org\n//\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};\n"],
5
- "mappings": ";;;AAIO,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,288 +0,0 @@
1
- import { createRequire } from 'node:module';const require = createRequire(import.meta.url);
2
- import {
3
- SECTION_IDENTIFIER,
4
- STACK_PLUGIN,
5
- meta_default
6
- } from "./chunk-T42IEBEL.mjs";
7
- import {
8
- SectionSchema,
9
- StackViewType
10
- } from "./chunk-4ULAI3BI.mjs";
11
-
12
- // packages/plugins/plugin-stack/src/StackPlugin.tsx
13
- import React4 from "react";
14
- import { create as create2 } from "@dxos/echo-schema";
15
- import { LocalStorageStore } from "@dxos/local-storage";
16
- import { CollectionType } from "@dxos/plugin-space/types";
17
- import { fullyQualifiedId } from "@dxos/react-client/echo";
18
- import { Main } from "@dxos/react-ui";
19
- import { baseSurface, topbarBlockPaddingStart, bottombarBlockPaddingEnd } from "@dxos/react-ui-theme";
20
-
21
- // packages/plugins/plugin-stack/src/components/index.ts
22
- import React3 from "react";
23
-
24
- // packages/plugins/plugin-stack/src/components/StackSettings.tsx
25
- import React from "react";
26
- import { SettingsValue } from "@dxos/plugin-settings";
27
- import { Input, useTranslation } from "@dxos/react-ui";
28
- var StackSettings = ({ settings }) => {
29
- const { t } = useTranslation(STACK_PLUGIN);
30
- return /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement(SettingsValue, {
31
- label: t("settings separation label")
32
- }, /* @__PURE__ */ React.createElement(Input.Switch, {
33
- checked: settings.separation,
34
- onCheckedChange: (checked) => settings.separation = !!checked
35
- })));
36
- };
37
-
38
- // packages/plugins/plugin-stack/src/components/AddSectionDialog.tsx
39
- import { FilePlus } from "@phosphor-icons/react";
40
- import React2, { useCallback, useRef, useState } from "react";
41
- import { usePlugin, useIntent, LayoutAction, useResolvePlugin, parseFileManagerPlugin } from "@dxos/app-framework";
42
- import { create } from "@dxos/echo-schema";
43
- import { FileType } from "@dxos/plugin-ipfs/types";
44
- import { getSpace } from "@dxos/react-client/echo";
45
- import { Dialog, toLocalizedString, useTranslation as useTranslation2 } from "@dxos/react-ui";
46
- import { Path } from "@dxos/react-ui-mosaic";
47
- import { SearchList } from "@dxos/react-ui-searchlist";
48
- import { getSize, mx } from "@dxos/react-ui-theme";
49
- import { nonNullable } from "@dxos/util";
50
- var dataHasAddSectionDialogProps = (data) => {
51
- return "subject" in data && typeof data.subject === "object" && !!data.subject && "position" in data.subject && typeof data.subject.position === "string" && "collection" in data.subject;
52
- };
53
- var AddSectionDialog = ({ path, position, collection }) => {
54
- const { t } = useTranslation2(STACK_PLUGIN);
55
- const stackPlugin = usePlugin(STACK_PLUGIN);
56
- const fileManagerPlugin = useResolvePlugin(parseFileManagerPlugin);
57
- const fileRef = useRef(null);
58
- const { dispatch } = useIntent();
59
- const space = getSpace(collection);
60
- const [pending, setPending] = useState(false);
61
- const [uploadError, setUploadError] = useState();
62
- const handleAdd = useCallback((sectionObject) => {
63
- const index = position === "beforeAll" ? 0 : position === "afterAll" ? collection.objects.length : collection.objects.filter(nonNullable).findIndex((section) => section.id === Path.last(path));
64
- collection.objects.splice(index + (position === "after" ? 1 : 0), 0, sectionObject);
65
- const stack = collection.views[StackViewType.typename];
66
- if (stack) {
67
- stack.sections[sectionObject.id] = {};
68
- }
69
- setPending(false);
70
- void dispatch?.({
71
- action: LayoutAction.SET_LAYOUT,
72
- data: {
73
- element: "dialog",
74
- state: false
75
- }
76
- });
77
- }, [
78
- collection,
79
- path,
80
- position,
81
- dispatch
82
- ]);
83
- const handleFileUpload = fileManagerPlugin?.provides.file.upload && space ? async (file) => {
84
- const filename = file.name.split(".")[0];
85
- try {
86
- const info = await fileManagerPlugin.provides.file.upload?.(file, space);
87
- if (info) {
88
- const obj = create(FileType, {
89
- type: file.type,
90
- name: filename,
91
- filename,
92
- cid: info.cid
93
- });
94
- handleAdd(obj);
95
- }
96
- } catch (err) {
97
- setUploadError(err);
98
- }
99
- } : void 0;
100
- return /* @__PURE__ */ React2.createElement(Dialog.Content, null, /* @__PURE__ */ React2.createElement(Dialog.Title, null, t(`add section ${position} dialog title`)), /* @__PURE__ */ React2.createElement(SearchList.Root, {
101
- label: t("add section input placeholder")
102
- }, /* @__PURE__ */ React2.createElement(SearchList.Input, {
103
- placeholder: t("add section input placeholder"),
104
- classNames: "pli-3",
105
- disabled: pending
106
- }), /* @__PURE__ */ React2.createElement(SearchList.Content, {
107
- classNames: "min-bs-24 bs-fit max-bs-64 overflow-auto",
108
- ...pending && {
109
- inert: "true"
110
- }
111
- }, stackPlugin?.provides?.stack.creators?.map(({ id, icon: Icon, label: propsLabel, testId, intent }) => {
112
- const label = toLocalizedString(propsLabel, t);
113
- return /* @__PURE__ */ React2.createElement(SearchList.Item, {
114
- value: label,
115
- key: id,
116
- onSelect: async () => {
117
- setPending(true);
118
- const { data: nextSection } = await dispatch({
119
- ...intent,
120
- data: {
121
- space
122
- }
123
- }) ?? {};
124
- handleAdd(nextSection);
125
- },
126
- classNames: "flex items-center gap-2 pli-2",
127
- "data-testid": testId
128
- }, Icon && /* @__PURE__ */ React2.createElement(Icon, {
129
- className: mx(getSize(4), "shrink-0")
130
- }), /* @__PURE__ */ React2.createElement("span", {
131
- className: "grow truncate"
132
- }, label));
133
- }), handleFileUpload && /* @__PURE__ */ React2.createElement(SearchList.Item, {
134
- value: t("upload file label"),
135
- classNames: "flex items-center gap-2 pli-2",
136
- onSelect: () => fileRef.current?.click()
137
- }, /* @__PURE__ */ React2.createElement(FilePlus, null), /* @__PURE__ */ React2.createElement("span", {
138
- className: "grow truncate"
139
- }, t("upload file label"))), uploadError && /* @__PURE__ */ React2.createElement("div", {
140
- className: "text-error-500"
141
- }, uploadError.message))), handleFileUpload && /* @__PURE__ */ React2.createElement("input", {
142
- type: "file",
143
- className: "sr-only",
144
- ref: fileRef,
145
- onChange: ({ target: { files } }) => files && handleFileUpload(files[0])
146
- }));
147
- };
148
-
149
- // packages/plugins/plugin-stack/src/components/index.ts
150
- var StackMain = React3.lazy(() => import("./StackMain-BQ5KK6F4.mjs"));
151
-
152
- // packages/plugins/plugin-stack/src/translations.ts
153
- import { translations as stackTranslations } from "@dxos/react-ui-stack";
154
- var translations_default = [
155
- {
156
- "en-US": {
157
- [STACK_PLUGIN]: {
158
- "plugin name": "Stacks",
159
- "settings separation label": "Separate sections",
160
- "add section beforeAll dialog title": "Add a section to the start",
161
- "add section afterAll dialog title": "Add a section to the end",
162
- "add section before dialog title": "Add a section",
163
- "add section after dialog title": "Add a section",
164
- "add section input placeholder": "Find the type of section to add",
165
- "upload file label": "Add file",
166
- "add section label": "Add section"
167
- }
168
- }
169
- },
170
- ...stackTranslations
171
- ];
172
-
173
- // packages/plugins/plugin-stack/src/StackPlugin.tsx
174
- var StackPlugin = () => {
175
- const settings = new LocalStorageStore(STACK_PLUGIN, {
176
- separation: true
177
- });
178
- const stackState = create2({
179
- creators: []
180
- });
181
- return {
182
- meta: meta_default,
183
- ready: async (plugins) => {
184
- settings.prop({
185
- key: "separation",
186
- type: LocalStorageStore.bool()
187
- });
188
- for (const plugin of plugins) {
189
- if (plugin.meta.id === STACK_PLUGIN) {
190
- continue;
191
- }
192
- if (Array.isArray(plugin.provides?.stack?.creators)) {
193
- stackState.creators.push(...plugin.provides.stack.creators ?? []);
194
- }
195
- }
196
- },
197
- provides: {
198
- settings: settings.values,
199
- metadata: {
200
- records: {
201
- [StackViewType.typename]: {
202
- placeholder: [
203
- "stack title placeholder",
204
- {
205
- ns: STACK_PLUGIN
206
- }
207
- ],
208
- icon: "ph--stack-simple--regular"
209
- },
210
- [SECTION_IDENTIFIER]: {
211
- parse: (section, type) => {
212
- switch (type) {
213
- case "node":
214
- return {
215
- id: section.object.id,
216
- label: section.object.title,
217
- data: section.object
218
- };
219
- case "object":
220
- return section.object;
221
- case "view-object":
222
- return section;
223
- }
224
- }
225
- }
226
- }
227
- },
228
- translations: translations_default,
229
- echo: {
230
- schema: [
231
- StackViewType
232
- ]
233
- },
234
- surface: {
235
- component: ({ data, role }) => {
236
- switch (data.component) {
237
- case `${STACK_PLUGIN}/AddSectionDialog`:
238
- return dataHasAddSectionDialogProps(data) ? /* @__PURE__ */ React4.createElement(AddSectionDialog, data.subject) : null;
239
- }
240
- const primary = data.active ?? data.object;
241
- const id = typeof data.id === "string" ? data.id : void 0;
242
- switch (role) {
243
- case "main":
244
- return primary instanceof CollectionType ? /* @__PURE__ */ React4.createElement(Main.Content, {
245
- bounce: true,
246
- classNames: [
247
- baseSurface,
248
- topbarBlockPaddingStart,
249
- bottombarBlockPaddingEnd
250
- ]
251
- }, /* @__PURE__ */ React4.createElement(StackMain, {
252
- id: id ?? fullyQualifiedId(primary),
253
- collection: primary,
254
- separation: settings.values.separation
255
- })) : null;
256
- case "article":
257
- return primary instanceof CollectionType ? /* @__PURE__ */ React4.createElement("div", {
258
- role: "none",
259
- className: "row-span-2 overflow-auto"
260
- }, /* @__PURE__ */ React4.createElement(StackMain, {
261
- id: id ?? fullyQualifiedId(primary),
262
- collection: primary,
263
- separation: settings.values.separation
264
- })) : null;
265
- case "settings": {
266
- return data.plugin === meta_default.id ? /* @__PURE__ */ React4.createElement(StackSettings, {
267
- settings: settings.values
268
- }) : null;
269
- }
270
- default:
271
- return null;
272
- }
273
- }
274
- },
275
- stack: stackState
276
- }
277
- };
278
- };
279
-
280
- // packages/plugins/plugin-stack/src/index.ts
281
- var src_default = StackPlugin;
282
- export {
283
- SectionSchema,
284
- StackPlugin,
285
- StackViewType,
286
- src_default as default
287
- };
288
- //# sourceMappingURL=index.mjs.map