@dxos/plugin-stack 0.6.11-staging.e6894a4 → 0.6.12-main.15a606f
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/lib/browser/{StackMain-XRQRNZ4I.mjs → StackMain-QYF4ZDSX.mjs} +2 -2
- package/dist/lib/browser/{chunk-AYDYMPJK.mjs → chunk-H4O4KKLZ.mjs} +2 -5
- package/dist/lib/browser/chunk-H4O4KKLZ.mjs.map +7 -0
- package/dist/lib/browser/index.mjs +3 -5
- package/dist/lib/browser/index.mjs.map +3 -3
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/meta.mjs +1 -1
- package/dist/lib/node/{StackMain-XJGYFDDN.cjs → StackMain-X77PXUJ3.cjs} +11 -11
- package/dist/lib/node/{chunk-I42JKRXR.cjs → chunk-PGL7XDNJ.cjs} +5 -18
- package/dist/lib/node/chunk-PGL7XDNJ.cjs.map +7 -0
- package/dist/lib/node/index.cjs +39 -41
- package/dist/lib/node/index.cjs.map +3 -3
- package/dist/lib/node/meta.cjs +4 -4
- package/dist/lib/node/meta.cjs.map +1 -1
- package/dist/lib/node/meta.json +1 -1
- package/dist/lib/node-esm/StackMain-PJBETNMK.mjs +277 -0
- package/dist/lib/node-esm/StackMain-PJBETNMK.mjs.map +7 -0
- package/dist/lib/node-esm/chunk-4ULAI3BI.mjs +23 -0
- package/dist/lib/node-esm/chunk-4ULAI3BI.mjs.map +7 -0
- package/dist/lib/node-esm/chunk-T42IEBEL.mjs +18 -0
- package/dist/lib/node-esm/chunk-T42IEBEL.mjs.map +7 -0
- package/dist/lib/node-esm/index.mjs +284 -0
- package/dist/lib/node-esm/index.mjs.map +7 -0
- package/dist/lib/node-esm/meta.json +1 -0
- package/dist/lib/node-esm/meta.mjs +12 -0
- package/dist/lib/node-esm/meta.mjs.map +7 -0
- package/dist/lib/node-esm/types/index.mjs +10 -0
- package/dist/lib/node-esm/types/index.mjs.map +7 -0
- package/dist/types/src/StackPlugin.d.ts.map +1 -1
- package/dist/types/src/meta.d.ts +1 -4
- package/dist/types/src/meta.d.ts.map +1 -1
- package/package.json +30 -27
- package/src/StackPlugin.tsx +1 -3
- package/src/meta.tsx +1 -5
- package/dist/lib/browser/chunk-AYDYMPJK.mjs.map +0 -7
- package/dist/lib/node/chunk-I42JKRXR.cjs.map +0 -7
- /package/dist/lib/browser/{StackMain-XRQRNZ4I.mjs.map → StackMain-QYF4ZDSX.mjs.map} +0 -0
- /package/dist/lib/node/{StackMain-XJGYFDDN.cjs.map → StackMain-X77PXUJ3.cjs.map} +0 -0
|
@@ -0,0 +1,277 @@
|
|
|
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 { Path } from "@dxos/react-ui-mosaic";
|
|
20
|
+
import { Stack } from "@dxos/react-ui-stack";
|
|
21
|
+
import { nonNullable } from "@dxos/util";
|
|
22
|
+
|
|
23
|
+
// packages/plugins/plugin-stack/src/components/AddSection.tsx
|
|
24
|
+
import { useArrowNavigationGroup } from "@fluentui/react-tabster";
|
|
25
|
+
import React, { useCallback } from "react";
|
|
26
|
+
import { usePlugin, useIntentDispatcher } from "@dxos/app-framework";
|
|
27
|
+
import { toLocalizedString, useTranslation } from "@dxos/react-ui";
|
|
28
|
+
import { getSize, mx } from "@dxos/react-ui-theme";
|
|
29
|
+
var CreatorTile = ({ Icon, label, testId, handleAdd }) => {
|
|
30
|
+
const onClick = useCallback((_) => handleAdd(), [
|
|
31
|
+
handleAdd
|
|
32
|
+
]);
|
|
33
|
+
const onKeyDown = useCallback((event) => {
|
|
34
|
+
if (event.key === "Enter" || event.key === " ") {
|
|
35
|
+
event.preventDefault();
|
|
36
|
+
handleAdd();
|
|
37
|
+
}
|
|
38
|
+
}, [
|
|
39
|
+
handleAdd
|
|
40
|
+
]);
|
|
41
|
+
return /* @__PURE__ */ React.createElement("div", {
|
|
42
|
+
role: "button",
|
|
43
|
+
"aria-label": label,
|
|
44
|
+
tabIndex: 0,
|
|
45
|
+
className: mx("flex items-center w-[10rem] h-16 overflow-hidden", "border rounded-md border-separator shadow-sm hover:bg-hoverSurface cursor-pointer"),
|
|
46
|
+
onClick,
|
|
47
|
+
onKeyDown,
|
|
48
|
+
"data-testid": testId
|
|
49
|
+
}, /* @__PURE__ */ React.createElement("div", {
|
|
50
|
+
className: "flex h-full w-12 items-center justify-center bg-scrim shrink-0 border-r border-separator"
|
|
51
|
+
}, /* @__PURE__ */ React.createElement(Icon, {
|
|
52
|
+
weight: "thin",
|
|
53
|
+
className: getSize(6)
|
|
54
|
+
})), /* @__PURE__ */ React.createElement("div", {
|
|
55
|
+
className: "overflow-hidden items-center p-2 px-3"
|
|
56
|
+
}, /* @__PURE__ */ React.createElement("span", {
|
|
57
|
+
className: "capitalize"
|
|
58
|
+
}, label)));
|
|
59
|
+
};
|
|
60
|
+
var AddSection = ({ collection }) => {
|
|
61
|
+
const domAttributes = useArrowNavigationGroup({
|
|
62
|
+
axis: "grid"
|
|
63
|
+
});
|
|
64
|
+
const dispatch = useIntentDispatcher();
|
|
65
|
+
const { t } = useTranslation(STACK_PLUGIN);
|
|
66
|
+
const stackPlugin = usePlugin(STACK_PLUGIN);
|
|
67
|
+
const stackCreators = stackPlugin?.provides?.stack.creators ?? [];
|
|
68
|
+
const handleAdd = useCallback(async (creator) => {
|
|
69
|
+
const { data: section } = await dispatch(creator.intent) ?? {};
|
|
70
|
+
collection.objects = [
|
|
71
|
+
section
|
|
72
|
+
];
|
|
73
|
+
const stack = collection.views[StackViewType.typename];
|
|
74
|
+
if (stack) {
|
|
75
|
+
stack.sections[section.id] = {};
|
|
76
|
+
}
|
|
77
|
+
}, [
|
|
78
|
+
collection,
|
|
79
|
+
dispatch
|
|
80
|
+
]);
|
|
81
|
+
if (stackCreators.length === 0) {
|
|
82
|
+
return null;
|
|
83
|
+
}
|
|
84
|
+
return /* @__PURE__ */ React.createElement("div", {
|
|
85
|
+
...domAttributes,
|
|
86
|
+
role: "none",
|
|
87
|
+
className: "flex flex-wrap items-center p-8 gap-4"
|
|
88
|
+
}, stackCreators.map((creator) => {
|
|
89
|
+
const { id, type, icon, testId } = creator;
|
|
90
|
+
return /* @__PURE__ */ React.createElement(CreatorTile, {
|
|
91
|
+
key: id,
|
|
92
|
+
label: toLocalizedString(type, t),
|
|
93
|
+
testId,
|
|
94
|
+
Icon: icon,
|
|
95
|
+
handleAdd: () => handleAdd(creator)
|
|
96
|
+
});
|
|
97
|
+
}));
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
// packages/plugins/plugin-stack/src/components/StackMain.tsx
|
|
101
|
+
var SectionContent = ({ data }) => {
|
|
102
|
+
return /* @__PURE__ */ React2.createElement(Surface, {
|
|
103
|
+
role: "section",
|
|
104
|
+
data: {
|
|
105
|
+
object: data
|
|
106
|
+
},
|
|
107
|
+
limit: 1,
|
|
108
|
+
placeholder: /* @__PURE__ */ React2.createElement(React2.Fragment, null)
|
|
109
|
+
});
|
|
110
|
+
};
|
|
111
|
+
var StackMain = ({ collection, separation }) => {
|
|
112
|
+
const dispatch = useIntentDispatcher2();
|
|
113
|
+
const { graph } = useGraph();
|
|
114
|
+
const { t } = useTranslation2(STACK_PLUGIN);
|
|
115
|
+
const metadataPlugin = useResolvePlugin(parseMetadataResolverPlugin);
|
|
116
|
+
const defaultStack = useMemo(() => create(StackViewType, {
|
|
117
|
+
sections: {}
|
|
118
|
+
}), [
|
|
119
|
+
collection
|
|
120
|
+
]);
|
|
121
|
+
const stack = collection.views[StackViewType.typename] ?? defaultStack;
|
|
122
|
+
const [collapsedSections, setCollapsedSections] = useState({});
|
|
123
|
+
useEffect(() => {
|
|
124
|
+
if (!collection.views[StackViewType.typename]) {
|
|
125
|
+
collection.views[StackViewType.typename] = stack;
|
|
126
|
+
}
|
|
127
|
+
}, [
|
|
128
|
+
collection,
|
|
129
|
+
stack
|
|
130
|
+
]);
|
|
131
|
+
const id = `stack-${collection.id}`;
|
|
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(React2.Fragment, 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-PJBETNMK.mjs.map
|
|
@@ -0,0 +1,7 @@
|
|
|
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 { type MosaicDataItem, type MosaicDropEvent, type MosaicMoveEvent, 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 collection: CollectionType;\n separation?: boolean;\n};\n\nconst StackMain = ({ 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 id = `stack-${collection.id}`;\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 <>\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 </>\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": ";;;;;;;;;;A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ArG,OAAA,cAACsG,YAAAA;IAAW/F;OAEZ,gBAAAP,OAAA,cAACuG,OAAAA;IAAIrG,MAAK;IAAOsG,WAAU;KACzB,gBAAAxG,OAAA,cAACyG,QAAAA;IACCb,eAAY;IACZc,YAAW;IACXC,SAAS,MACPlG,WAAW;MACTgE,QAAQS,aAAaG;MACrBtF,MAAM;QACJuF,SAAS;QACTC,WAAW;QACXC,SAAS;UAAErB,UAAU;UAAY5D;QAAW;MAC9C;IACF,CAAA;KAGF,gBAAAP,OAAA,cAAC4G,MAAAA,IAAAA,GACD,gBAAA5G,OAAA,cAAC8F,QAAAA;IAAKU,WAAU;KAAW3F,EAAE,mBAAA,CAAA,CAAA,CAAA,CAAA;AAMzC;AAEA,IAAA,oBAAeP;",
|
|
6
|
+
"names": ["Plus", "React", "useEffect", "useMemo", "useState", "LayoutAction", "NavigationAction", "parseMetadataResolverPlugin", "Surface", "useIntentDispatcher", "useResolvePlugin", "create", "getType", "isReactiveObject", "useGraph", "SpaceAction", "fullyQualifiedId", "Button", "toLocalizedString", "useTranslation", "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", "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", "id", "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", "Stack", "data-testid", "emptyComponent", "span", "onDrop", "onOver", "onDeleteSection", "onNavigateToSection", "onAddSection", "onCollapseSection", "length", "AddSection", "div", "className", "Button", "classNames", "onClick", "Plus"]
|
|
7
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
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
|
|
@@ -0,0 +1,7 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { createRequire } from 'node:module';const require = createRequire(import.meta.url);
|
|
2
|
+
|
|
3
|
+
// packages/plugins/plugin-stack/src/meta.tsx
|
|
4
|
+
var STACK_PLUGIN = "dxos.org/plugin/stack";
|
|
5
|
+
var SECTION_IDENTIFIER = "dxos.org/type/StackSection";
|
|
6
|
+
var meta_default = {
|
|
7
|
+
id: STACK_PLUGIN,
|
|
8
|
+
// TODO(wittjosiah): Prevents "stacks" language from being exposed to users in settings panel.
|
|
9
|
+
name: "Collections",
|
|
10
|
+
icon: "ph--stack-simple--regular"
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
export {
|
|
14
|
+
STACK_PLUGIN,
|
|
15
|
+
SECTION_IDENTIFIER,
|
|
16
|
+
meta_default
|
|
17
|
+
};
|
|
18
|
+
//# sourceMappingURL=chunk-T42IEBEL.mjs.map
|
|
@@ -0,0 +1,7 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,284 @@
|
|
|
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 { Main } from "@dxos/react-ui";
|
|
18
|
+
import { baseSurface, topbarBlockPaddingStart, bottombarBlockPaddingEnd } from "@dxos/react-ui-theme";
|
|
19
|
+
|
|
20
|
+
// packages/plugins/plugin-stack/src/components/index.ts
|
|
21
|
+
import React3 from "react";
|
|
22
|
+
|
|
23
|
+
// packages/plugins/plugin-stack/src/components/StackSettings.tsx
|
|
24
|
+
import React from "react";
|
|
25
|
+
import { SettingsValue } from "@dxos/plugin-settings";
|
|
26
|
+
import { Input, useTranslation } from "@dxos/react-ui";
|
|
27
|
+
var StackSettings = ({ settings }) => {
|
|
28
|
+
const { t } = useTranslation(STACK_PLUGIN);
|
|
29
|
+
return /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement(SettingsValue, {
|
|
30
|
+
label: t("settings separation label")
|
|
31
|
+
}, /* @__PURE__ */ React.createElement(Input.Switch, {
|
|
32
|
+
checked: settings.separation,
|
|
33
|
+
onCheckedChange: (checked) => settings.separation = !!checked
|
|
34
|
+
})));
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
// packages/plugins/plugin-stack/src/components/AddSectionDialog.tsx
|
|
38
|
+
import { FilePlus } from "@phosphor-icons/react";
|
|
39
|
+
import React2, { useCallback, useRef, useState } from "react";
|
|
40
|
+
import { usePlugin, useIntent, LayoutAction, useResolvePlugin, parseFileManagerPlugin } from "@dxos/app-framework";
|
|
41
|
+
import { create } from "@dxos/echo-schema";
|
|
42
|
+
import { FileType } from "@dxos/plugin-ipfs/types";
|
|
43
|
+
import { getSpace } from "@dxos/react-client/echo";
|
|
44
|
+
import { Dialog, toLocalizedString, useTranslation as useTranslation2 } from "@dxos/react-ui";
|
|
45
|
+
import { Path } from "@dxos/react-ui-mosaic";
|
|
46
|
+
import { SearchList } from "@dxos/react-ui-searchlist";
|
|
47
|
+
import { getSize, mx } from "@dxos/react-ui-theme";
|
|
48
|
+
import { nonNullable } from "@dxos/util";
|
|
49
|
+
var dataHasAddSectionDialogProps = (data) => {
|
|
50
|
+
return "subject" in data && typeof data.subject === "object" && !!data.subject && "position" in data.subject && typeof data.subject.position === "string" && "collection" in data.subject;
|
|
51
|
+
};
|
|
52
|
+
var AddSectionDialog = ({ path, position, collection }) => {
|
|
53
|
+
const { t } = useTranslation2(STACK_PLUGIN);
|
|
54
|
+
const stackPlugin = usePlugin(STACK_PLUGIN);
|
|
55
|
+
const fileManagerPlugin = useResolvePlugin(parseFileManagerPlugin);
|
|
56
|
+
const fileRef = useRef(null);
|
|
57
|
+
const { dispatch } = useIntent();
|
|
58
|
+
const space = getSpace(collection);
|
|
59
|
+
const [pending, setPending] = useState(false);
|
|
60
|
+
const [uploadError, setUploadError] = useState();
|
|
61
|
+
const handleAdd = useCallback((sectionObject) => {
|
|
62
|
+
const index = position === "beforeAll" ? 0 : position === "afterAll" ? collection.objects.length : collection.objects.filter(nonNullable).findIndex((section) => section.id === Path.last(path));
|
|
63
|
+
collection.objects.splice(index + (position === "after" ? 1 : 0), 0, sectionObject);
|
|
64
|
+
const stack = collection.views[StackViewType.typename];
|
|
65
|
+
if (stack) {
|
|
66
|
+
stack.sections[sectionObject.id] = {};
|
|
67
|
+
}
|
|
68
|
+
setPending(false);
|
|
69
|
+
void dispatch?.({
|
|
70
|
+
action: LayoutAction.SET_LAYOUT,
|
|
71
|
+
data: {
|
|
72
|
+
element: "dialog",
|
|
73
|
+
state: false
|
|
74
|
+
}
|
|
75
|
+
});
|
|
76
|
+
}, [
|
|
77
|
+
collection,
|
|
78
|
+
path,
|
|
79
|
+
position,
|
|
80
|
+
dispatch
|
|
81
|
+
]);
|
|
82
|
+
const handleFileUpload = fileManagerPlugin?.provides.file.upload && space ? async (file) => {
|
|
83
|
+
const filename = file.name.split(".")[0];
|
|
84
|
+
try {
|
|
85
|
+
const info = await fileManagerPlugin.provides.file.upload?.(file, space);
|
|
86
|
+
if (info) {
|
|
87
|
+
const obj = create(FileType, {
|
|
88
|
+
type: file.type,
|
|
89
|
+
name: filename,
|
|
90
|
+
filename,
|
|
91
|
+
cid: info.cid
|
|
92
|
+
});
|
|
93
|
+
handleAdd(obj);
|
|
94
|
+
}
|
|
95
|
+
} catch (err) {
|
|
96
|
+
setUploadError(err);
|
|
97
|
+
}
|
|
98
|
+
} : void 0;
|
|
99
|
+
return /* @__PURE__ */ React2.createElement(Dialog.Content, null, /* @__PURE__ */ React2.createElement(Dialog.Title, null, t(`add section ${position} dialog title`)), /* @__PURE__ */ React2.createElement(SearchList.Root, {
|
|
100
|
+
label: t("add section input placeholder")
|
|
101
|
+
}, /* @__PURE__ */ React2.createElement(SearchList.Input, {
|
|
102
|
+
placeholder: t("add section input placeholder"),
|
|
103
|
+
classNames: "pli-3",
|
|
104
|
+
disabled: pending
|
|
105
|
+
}), /* @__PURE__ */ React2.createElement(SearchList.Content, {
|
|
106
|
+
classNames: "min-bs-24 bs-fit max-bs-64 overflow-auto",
|
|
107
|
+
...pending && {
|
|
108
|
+
inert: "true"
|
|
109
|
+
}
|
|
110
|
+
}, stackPlugin?.provides?.stack.creators?.map(({ id, icon: Icon, label: propsLabel, testId, intent }) => {
|
|
111
|
+
const label = toLocalizedString(propsLabel, t);
|
|
112
|
+
return /* @__PURE__ */ React2.createElement(SearchList.Item, {
|
|
113
|
+
value: label,
|
|
114
|
+
key: id,
|
|
115
|
+
onSelect: async () => {
|
|
116
|
+
setPending(true);
|
|
117
|
+
const { data: nextSection } = await dispatch({
|
|
118
|
+
...intent,
|
|
119
|
+
data: {
|
|
120
|
+
space
|
|
121
|
+
}
|
|
122
|
+
}) ?? {};
|
|
123
|
+
handleAdd(nextSection);
|
|
124
|
+
},
|
|
125
|
+
classNames: "flex items-center gap-2 pli-2",
|
|
126
|
+
"data-testid": testId
|
|
127
|
+
}, Icon && /* @__PURE__ */ React2.createElement(Icon, {
|
|
128
|
+
className: mx(getSize(4), "shrink-0")
|
|
129
|
+
}), /* @__PURE__ */ React2.createElement("span", {
|
|
130
|
+
className: "grow truncate"
|
|
131
|
+
}, label));
|
|
132
|
+
}), handleFileUpload && /* @__PURE__ */ React2.createElement(SearchList.Item, {
|
|
133
|
+
value: t("upload file label"),
|
|
134
|
+
classNames: "flex items-center gap-2 pli-2",
|
|
135
|
+
onSelect: () => fileRef.current?.click()
|
|
136
|
+
}, /* @__PURE__ */ React2.createElement(FilePlus, null), /* @__PURE__ */ React2.createElement("span", {
|
|
137
|
+
className: "grow truncate"
|
|
138
|
+
}, t("upload file label"))), uploadError && /* @__PURE__ */ React2.createElement("div", {
|
|
139
|
+
className: "text-error-500"
|
|
140
|
+
}, uploadError.message))), handleFileUpload && /* @__PURE__ */ React2.createElement("input", {
|
|
141
|
+
type: "file",
|
|
142
|
+
className: "sr-only",
|
|
143
|
+
ref: fileRef,
|
|
144
|
+
onChange: ({ target: { files } }) => files && handleFileUpload(files[0])
|
|
145
|
+
}));
|
|
146
|
+
};
|
|
147
|
+
|
|
148
|
+
// packages/plugins/plugin-stack/src/components/index.ts
|
|
149
|
+
var StackMain = React3.lazy(() => import("./StackMain-PJBETNMK.mjs"));
|
|
150
|
+
|
|
151
|
+
// packages/plugins/plugin-stack/src/translations.ts
|
|
152
|
+
import { translations as stackTranslations } from "@dxos/react-ui-stack";
|
|
153
|
+
var translations_default = [
|
|
154
|
+
{
|
|
155
|
+
"en-US": {
|
|
156
|
+
[STACK_PLUGIN]: {
|
|
157
|
+
"plugin name": "Stacks",
|
|
158
|
+
"settings separation label": "Separate sections",
|
|
159
|
+
"add section beforeAll dialog title": "Add a section to the start",
|
|
160
|
+
"add section afterAll dialog title": "Add a section to the end",
|
|
161
|
+
"add section before dialog title": "Add a section",
|
|
162
|
+
"add section after dialog title": "Add a section",
|
|
163
|
+
"add section input placeholder": "Find the type of section to add",
|
|
164
|
+
"upload file label": "Add file",
|
|
165
|
+
"add section label": "Add section"
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
},
|
|
169
|
+
...stackTranslations
|
|
170
|
+
];
|
|
171
|
+
|
|
172
|
+
// packages/plugins/plugin-stack/src/StackPlugin.tsx
|
|
173
|
+
var StackPlugin = () => {
|
|
174
|
+
const settings = new LocalStorageStore(STACK_PLUGIN, {
|
|
175
|
+
separation: true
|
|
176
|
+
});
|
|
177
|
+
const stackState = create2({
|
|
178
|
+
creators: []
|
|
179
|
+
});
|
|
180
|
+
return {
|
|
181
|
+
meta: meta_default,
|
|
182
|
+
ready: async (plugins) => {
|
|
183
|
+
settings.prop({
|
|
184
|
+
key: "separation",
|
|
185
|
+
type: LocalStorageStore.bool()
|
|
186
|
+
});
|
|
187
|
+
for (const plugin of plugins) {
|
|
188
|
+
if (plugin.meta.id === STACK_PLUGIN) {
|
|
189
|
+
continue;
|
|
190
|
+
}
|
|
191
|
+
if (Array.isArray(plugin.provides?.stack?.creators)) {
|
|
192
|
+
stackState.creators.push(...plugin.provides.stack.creators ?? []);
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
},
|
|
196
|
+
provides: {
|
|
197
|
+
settings: settings.values,
|
|
198
|
+
metadata: {
|
|
199
|
+
records: {
|
|
200
|
+
[StackViewType.typename]: {
|
|
201
|
+
placeholder: [
|
|
202
|
+
"stack title placeholder",
|
|
203
|
+
{
|
|
204
|
+
ns: STACK_PLUGIN
|
|
205
|
+
}
|
|
206
|
+
],
|
|
207
|
+
icon: "ph--stack-simple--regular"
|
|
208
|
+
},
|
|
209
|
+
[SECTION_IDENTIFIER]: {
|
|
210
|
+
parse: (section, type) => {
|
|
211
|
+
switch (type) {
|
|
212
|
+
case "node":
|
|
213
|
+
return {
|
|
214
|
+
id: section.object.id,
|
|
215
|
+
label: section.object.title,
|
|
216
|
+
data: section.object
|
|
217
|
+
};
|
|
218
|
+
case "object":
|
|
219
|
+
return section.object;
|
|
220
|
+
case "view-object":
|
|
221
|
+
return section;
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
},
|
|
227
|
+
translations: translations_default,
|
|
228
|
+
echo: {
|
|
229
|
+
schema: [
|
|
230
|
+
StackViewType
|
|
231
|
+
]
|
|
232
|
+
},
|
|
233
|
+
surface: {
|
|
234
|
+
component: ({ data, role }) => {
|
|
235
|
+
switch (data.component) {
|
|
236
|
+
case `${STACK_PLUGIN}/AddSectionDialog`:
|
|
237
|
+
return dataHasAddSectionDialogProps(data) ? /* @__PURE__ */ React4.createElement(AddSectionDialog, data.subject) : null;
|
|
238
|
+
}
|
|
239
|
+
const primary = data.active ?? data.object;
|
|
240
|
+
switch (role) {
|
|
241
|
+
case "main":
|
|
242
|
+
return primary instanceof CollectionType ? /* @__PURE__ */ React4.createElement(Main.Content, {
|
|
243
|
+
bounce: true,
|
|
244
|
+
classNames: [
|
|
245
|
+
baseSurface,
|
|
246
|
+
topbarBlockPaddingStart,
|
|
247
|
+
bottombarBlockPaddingEnd
|
|
248
|
+
]
|
|
249
|
+
}, /* @__PURE__ */ React4.createElement(StackMain, {
|
|
250
|
+
collection: primary,
|
|
251
|
+
separation: settings.values.separation
|
|
252
|
+
})) : null;
|
|
253
|
+
case "article":
|
|
254
|
+
return primary instanceof CollectionType ? /* @__PURE__ */ React4.createElement("div", {
|
|
255
|
+
role: "none",
|
|
256
|
+
className: "row-span-2 overflow-auto"
|
|
257
|
+
}, /* @__PURE__ */ React4.createElement(StackMain, {
|
|
258
|
+
collection: primary,
|
|
259
|
+
separation: settings.values.separation
|
|
260
|
+
})) : null;
|
|
261
|
+
case "settings": {
|
|
262
|
+
return data.plugin === meta_default.id ? /* @__PURE__ */ React4.createElement(StackSettings, {
|
|
263
|
+
settings: settings.values
|
|
264
|
+
}) : null;
|
|
265
|
+
}
|
|
266
|
+
default:
|
|
267
|
+
return null;
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
},
|
|
271
|
+
stack: stackState
|
|
272
|
+
}
|
|
273
|
+
};
|
|
274
|
+
};
|
|
275
|
+
|
|
276
|
+
// packages/plugins/plugin-stack/src/index.ts
|
|
277
|
+
var src_default = StackPlugin;
|
|
278
|
+
export {
|
|
279
|
+
SectionSchema,
|
|
280
|
+
StackPlugin,
|
|
281
|
+
StackViewType,
|
|
282
|
+
src_default as default
|
|
283
|
+
};
|
|
284
|
+
//# sourceMappingURL=index.mjs.map
|