@ossy/storage 1.1.0 → 1.2.1

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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@ossy/storage",
3
3
  "description": "Analytics module — workspace analytics for website traffic",
4
- "version": "1.1.0",
4
+ "version": "1.2.1",
5
5
  "type": "module",
6
6
  "main": "./src/index.js",
7
7
  "module": "./src/index.js",
@@ -21,5 +21,14 @@
21
21
  "/src",
22
22
  "README.md"
23
23
  ],
24
- "gitHead": "ccbb5575213d2703e3cad5608b85c3478fc421bc"
24
+ "peerDependencies": {
25
+ "@ossy/app": "*",
26
+ "@ossy/design-system": "*",
27
+ "@ossy/resources": "*",
28
+ "@ossy/router-react": "*",
29
+ "@ossy/sdk-react": "*",
30
+ "ramda": "*",
31
+ "react": "*"
32
+ },
33
+ "gitHead": "b976fdb88970a76f135238baa970c20f9f357dc9"
25
34
  }
@@ -0,0 +1,103 @@
1
+ import React from 'react'
2
+ import { Title, Button, View, PageSection } from '@ossy/design-system'
3
+
4
+ const Cover = ({
5
+ title,
6
+ titleMaxWidth = '1100px',
7
+ text,
8
+ actions = [],
9
+ }) => (
10
+ <View
11
+ gap="l"
12
+ placeContent='center'
13
+ layout="column"
14
+ justifyContent='center'
15
+ style={{
16
+ height: '100%',
17
+ borderRadius: 'var(--space-m)',
18
+ padding: 'var(--space-xl) var(--space-s)',
19
+ }}
20
+ >
21
+
22
+ <View gap="m" alignItems="center">
23
+ <Title as="h1" variant="display" style={{ maxWidth: titleMaxWidth, textWrap: 'balance' }}>
24
+ {title}
25
+ </Title>
26
+
27
+ <Title as="h2" variant="title-tertiary" style={{ maxWidth: '800px' }}>
28
+ {text}
29
+ </Title>
30
+ </View>
31
+
32
+ <View gap="m" layout="row" justifyContent="center">
33
+ {actions.map(({ label, ...props }) => (
34
+ <Button {...props} key={label}>
35
+ {label}
36
+ </Button>
37
+ ))}
38
+ </View>
39
+
40
+ </View>
41
+ )
42
+
43
+
44
+ export const HeroCover = ({
45
+ title,
46
+ titleMaxWidth = '1100px',
47
+ text,
48
+ actions = [],
49
+
50
+ // section props
51
+ id= 'hero-cover',
52
+ surfaceAs= "div",
53
+ maxWidth='l',
54
+ surface="hero",
55
+ ...props
56
+ }) => {
57
+ const { style: passthroughStyle, ...pageSectionProps } = props
58
+
59
+ return (
60
+ <PageSection
61
+ id={id}
62
+ surfaceAs={surfaceAs}
63
+ maxWidth={maxWidth}
64
+ surface={surface}
65
+ {...pageSectionProps}
66
+ data-rounded
67
+ data-component="@ossy/website-ossy/cover"
68
+ style={{
69
+ backgroundAttachment: 'scroll',
70
+ boxShadow: 'inset 0 1px 0 color-mix(in srgb, var(--foreground) 6%, transparent)',
71
+ ...passthroughStyle,
72
+ }}
73
+ >
74
+ <style href="@ossy/website-ossy/cover" precedence='high'>
75
+ {`
76
+ [data-component="@ossy/website-ossy/cover"] {
77
+ gap: var(--space-m);
78
+ min-height: min(42vh, 420px);
79
+ height: auto;
80
+ }
81
+
82
+ [data-rounded] {
83
+ border-radius: var(--space-m);
84
+ overflow: hidden;
85
+ }
86
+
87
+ @media (min-width: 900px) {
88
+ [data-component="@ossy/website-ossy/cover"] {
89
+ min-height: min(46vh, 520px);
90
+ }
91
+ }
92
+ `}
93
+ </style>
94
+
95
+ <Cover
96
+ title={title}
97
+ titleMaxWidth={titleMaxWidth}
98
+ text={text}
99
+ actions={actions}
100
+ />
101
+ </PageSection>
102
+ )
103
+ }
@@ -0,0 +1,412 @@
1
+ import React, { useState, useEffect } from 'react'
2
+ import { useResources, useWorkspace, AsyncStatus } from '@ossy/sdk-react'
3
+ import {
4
+ pipe,
5
+ split,
6
+ filter,
7
+ identity,
8
+ last,
9
+ } from 'ramda'
10
+ import {
11
+ Overlay,
12
+ Switch,
13
+ Stack,
14
+ DropZone,
15
+ Breadcrumbs,
16
+ Guide,
17
+ DelayedRender,
18
+ useDocumentTitle,
19
+ View,
20
+ Button,
21
+ ContextMenu,
22
+ Dropdown,
23
+ Title,
24
+ Tags,
25
+ EmptyState,
26
+ } from '@ossy/design-system'
27
+ import { useActivePath, ResourcePanel, ResourceList, ResourceDialogMove } from '@ossy/resources'
28
+ import { useRouter } from '@ossy/router-react'
29
+
30
+ const Path = ({ path, ...props }) => (
31
+ <Button variant="command" {...props}>
32
+ {last(path.split('/'))}
33
+ </Button>
34
+ )
35
+
36
+ const ResourcesListStatus = {
37
+ Error: 'Error',
38
+ Loading: 'Loading',
39
+ Empty: 'Empty',
40
+ Success: 'Success'
41
+ }
42
+
43
+
44
+ const Overlays = {
45
+ None: 'None',
46
+ Removedirectory : 'RemoveDirectory',
47
+ MoveResource: 'MoveResource'
48
+ }
49
+
50
+ export const ResourcesPage = () => {
51
+ const router = useRouter()
52
+ const { workspace } = useWorkspace()
53
+ const [overlay, setOverlay] = useState(Overlays.None)
54
+ const [selectedResourceId, setSelectedResourceId] = useState()
55
+ const [resourcesListStatus, setResourcesListStatus] = useState(ResourcesListStatus.Loading)
56
+ const activePath = useActivePath()
57
+
58
+ const {
59
+ status: resourcesStatus,
60
+ resources,
61
+ removeResource,
62
+ moveResource,
63
+ createDirectory,
64
+ } = useResources(activePath)
65
+
66
+ const [isCreatingFolder, setIsCreatingFolder] = useState(false)
67
+ const [newFolderName, setNewFolderName] = useState('New folder')
68
+
69
+ const onCreateFolderSave = (name) => {
70
+ const folderName = (name || '').trim()
71
+ if (!folderName) {
72
+ onCreateFolderCancel()
73
+ return
74
+ }
75
+ createDirectory({ name: folderName, location: activePath })
76
+ .finally(() => {
77
+ setIsCreatingFolder(false)
78
+ setNewFolderName('New folder')
79
+ })
80
+ }
81
+
82
+ const onCreateFolderCancel = () => {
83
+ setIsCreatingFolder(false)
84
+ setNewFolderName('New folder')
85
+ }
86
+
87
+ const inlineFolder = isCreatingFolder
88
+ ? { name: newFolderName, onChange: setNewFolderName, onSave: onCreateFolderSave, onCancel: onCreateFolderCancel }
89
+ : null
90
+
91
+ useDocumentTitle(workspace.name || 'loading workspace')
92
+
93
+ const goTo = x => () => {
94
+ router.searchParams.set('location', `${x}/`)
95
+ }
96
+
97
+ const onMoveResource = newLocation => resourceId => {
98
+ moveResource(resourceId, newLocation)
99
+ }
100
+
101
+ const onRemoveResource = resource => {
102
+ setSelectedResourceId(resource.id)
103
+
104
+ if (resource.type === 'directory') {
105
+ setOverlay(Overlays.RemoveDirectory)
106
+ } else {
107
+ removeResource(resource.id)
108
+ }
109
+
110
+ }
111
+
112
+ const getActivePath = () => pipe(
113
+ split('/'),
114
+ filter(identity),
115
+ x => x.reduce((acc, curr, i) => i === 0
116
+ ? [`/${curr}`]
117
+ : [...acc, `${acc[i - 1]}/${curr}`], []),
118
+ filter(identity),
119
+ paths => paths.map((path, i) => {
120
+ const isLast = i === (paths.length - 1)
121
+ if (isLast) return <Path key={path} path={path} onClick={goTo(path)} />
122
+ return (
123
+ <DropZone onDrop={onMoveResource(`${path}/`)}>
124
+ <Path key={path} path={path} href={router.getHref(`@storage/home?location=${path}`)}/>
125
+ </DropZone>
126
+ )
127
+ })
128
+ )(activePath)
129
+
130
+ useEffect(() => {
131
+ if (resourcesStatus === AsyncStatus.NotInitialized) {
132
+ setResourcesListStatus(ResourcesListStatus.Loading)
133
+ } else if (resourcesStatus === AsyncStatus.Loading) {
134
+ setResourcesListStatus(ResourcesListStatus.Loading)
135
+ } else if (resourcesStatus === AsyncStatus.Error) {
136
+ setResourcesListStatus(ResourcesListStatus.Error)
137
+ } else if (resourcesStatus === AsyncStatus.Success) {
138
+ resources.length === 0
139
+ ? setResourcesListStatus(ResourcesListStatus.Empty)
140
+ : setResourcesListStatus(ResourcesListStatus.Success)
141
+ }
142
+ }, [resources, resourcesStatus])
143
+
144
+ const filterResources = resources
145
+ //filter out the @ossy resources, it is resources that the system creates
146
+ .filter(resource => !resource?.name?.startsWith?.('@ossy'))
147
+ .map(resource => {
148
+
149
+ if (resource.type === 'directory') {
150
+ return {
151
+ ...resource,
152
+ href: router.getHref(`@storage/home?location=${activePath}${resource.name}`),
153
+ onDrop: onMoveResource(`${resource.location}${resource.name}/`),
154
+ actions: [
155
+ <ContextMenu.Item
156
+ prefix="mail-forward"
157
+ href={router.getHref(`@storage/home?location=${activePath}${resource.name}`)}
158
+ onClick={event => { event.stopPropagation() }}
159
+ key="details"
160
+ >
161
+ Open
162
+ </ContextMenu.Item>,
163
+ <ContextMenu.Separator key="separator"></ContextMenu.Separator>,
164
+ <ContextMenu.Item
165
+ variant="command-danger"
166
+ prefix="trash-empty"
167
+ key="remove"
168
+ onClick={event => {
169
+ event.stopPropagation()
170
+ onRemoveResource(resource)
171
+ }}
172
+ >Remove
173
+ </ContextMenu.Item>
174
+ ]
175
+ }
176
+ }
177
+
178
+ return {
179
+ ...resource,
180
+ dragData: resource.id,
181
+ onClick: () => setSelectedResourceId(resource.id),
182
+ actions: [
183
+ <ContextMenu.Item
184
+ key="details"
185
+ prefix="details-more"
186
+ onClick={event => {
187
+ event.stopPropagation()
188
+ setSelectedResourceId(resource.id)}
189
+ }
190
+ >
191
+ View
192
+ </ContextMenu.Item>,
193
+ <ContextMenu.Item
194
+ key="details"
195
+ prefix="details-more"
196
+ onClick={event => {
197
+ event.stopPropagation()
198
+ setSelectedResourceId(resource.id)
199
+ setOverlay(Overlays.MoveResource)
200
+ }
201
+ }
202
+ >
203
+ Move
204
+ </ContextMenu.Item>,
205
+ <ContextMenu.Separator key="separator"></ContextMenu.Separator>,
206
+ <ContextMenu.Item
207
+ key="remove"
208
+ variant="command-danger"
209
+ prefix="trash-empty"
210
+ onClick={event => {
211
+ event.stopPropagation()
212
+ onRemoveResource(resource)
213
+ }}
214
+ >Remove
215
+ </ContextMenu.Item>
216
+ ]
217
+ }
218
+
219
+ })
220
+ .sort((a, b) => {
221
+ if (a.type === 'directory' && b.type !== 'directory') return -1
222
+ if (a.type !== 'directory' && b.type === 'directory') return 1
223
+ })
224
+
225
+ return (
226
+ <View style={{ height: '100%' }}>
227
+
228
+ <style>
229
+ {`
230
+ [data-scrollbar="hide"] {
231
+ -ms-overflow-style: none; /* Hide scrollbar in Internet Explorer */
232
+ scrollbar-width: none; /* Hide scrollbar in Firefox */
233
+ }
234
+
235
+ [data-scrollbar="hide"]::-webkit-scrollbar {
236
+ display: none; /* Hide scrollbar in WebKit browsers (Chrome, Safari) */
237
+ }
238
+
239
+ `}
240
+ </style>
241
+
242
+ <View layout="row" inset="m" justifyContent="space-between" alignItems="center" surface="primary" roundness="s" style={{ flexShrink: 0 }}>
243
+ <View layout='row' gap="s" alignItems="center">
244
+ <Title>Storage</Title>
245
+
246
+ <Tags size="s" tags={['Beta']} />
247
+ </View>
248
+ </View>
249
+
250
+ <Stack horizontal gap="xs" style={{ flexGrow: 1 }}>
251
+
252
+ <Stack.Item fill surface="primary" roundness="xs" >
253
+ <Stack bordered style={{ height: '100%' }}>
254
+
255
+ <Stack.Item
256
+ data-surface="primary"
257
+ layout="row"
258
+ style={{
259
+ alignItems: 'center',
260
+ justifyContent: 'space-between',
261
+ padding: 'var(--space-s) var(--space-m)',
262
+ gap: 'var(--space-m)',
263
+ height: '48px',
264
+ flexShrink: 0
265
+ }}
266
+ >
267
+
268
+ <Breadcrumbs>
269
+ {
270
+ activePath === '/'
271
+ ? <Button prefix="home-alt" variant="command" href={router.getHref('@storage/home')} />
272
+ : (
273
+ <DropZone onDrop={onMoveResource('/')}>
274
+ <Button prefix="home-alt" variant="command" href={router.getHref('@storage/home')} />
275
+ </DropZone>
276
+ )
277
+ }
278
+
279
+ { activePath !== '/' && getActivePath() }
280
+ </Breadcrumbs>
281
+
282
+ <Dropdown trigger={<Button prefix="add" variant="command" style={{ height: '32px' }}>Add</Button>}>
283
+ <View inset="xs" surface="primary" roundness="s">
284
+ <ContextMenu roundness="s" surface="primary">
285
+ <ContextMenu.Item
286
+ prefix="folder-add"
287
+ onClick={() => {
288
+ setIsCreatingFolder(true)
289
+ setNewFolderName('New folder')
290
+ }}
291
+ >
292
+ Create folder
293
+ </ContextMenu.Item>
294
+ <ContextMenu.Item
295
+ prefix="software-upload"
296
+ href={router.getHref(`@upload-media?location=${activePath}`)}
297
+ >
298
+ Upload file
299
+ </ContextMenu.Item>
300
+ </ContextMenu>
301
+ </View>
302
+ </Dropdown>
303
+
304
+ </Stack.Item>
305
+
306
+ <Stack.Item fill data-scrollbar="hide" style={{ overflowY: 'auto' }}>
307
+ <Switch on={resourcesListStatus}>
308
+
309
+ <Switch.Case match={[ResourcesListStatus.Error]}>
310
+ <View layout="off-center" style={{ height: '100%' }}>
311
+ <Guide
312
+ slot="content"
313
+ title="Something went wrong"
314
+ text="We could not fetch the data to display"
315
+ style={{ width: '100vw', maxWidth: '350px' }}
316
+ />
317
+ </View>
318
+ </Switch.Case>
319
+
320
+ <Switch.Case match={[ResourcesListStatus.Loading]}>
321
+ <DelayedRender>
322
+ {[1, 2, 3].map(n => (
323
+ <Stack.Item key={n}>
324
+ <div
325
+ className="inset-m cursor-pointer sans-serif d-flex align-center justify-between"
326
+ style={{ height: '56px', }}
327
+ >
328
+ <div className="d-flex align-center">
329
+ <span
330
+ className="inline-m"
331
+ style={{
332
+ width: '20px',
333
+ height: '18px',
334
+ background: 'hsl(0, 0%, 50%)',
335
+ borderRadius: '16px'
336
+ }}
337
+ />
338
+ <span
339
+ style={{
340
+ width: '300px',
341
+ height: '18px',
342
+ background: 'hsl(0, 0%, 50%)',
343
+ borderRadius: '16px'
344
+ }}
345
+ />
346
+ </div>
347
+ </div>
348
+ </Stack.Item>
349
+ ))}
350
+ </DelayedRender>
351
+ </Switch.Case>
352
+
353
+ <Switch.Case match={[ResourcesListStatus.Empty]}>
354
+ {isCreatingFolder
355
+ ? <ResourceList resources={[]} inlineFolder={inlineFolder} />
356
+ : <EmptyState message="Empty directory" />
357
+ }
358
+ </Switch.Case>
359
+
360
+ <Switch.Case match={[ResourcesListStatus.Success]}>
361
+ <ResourceList resources={filterResources} inlineFolder={inlineFolder} />
362
+ </Switch.Case>
363
+
364
+ </Switch>
365
+ </Stack.Item>
366
+
367
+ </Stack>
368
+ </Stack.Item>
369
+
370
+ <ResourcePanel resourceId={selectedResourceId} onClose={() => setSelectedResourceId(undefined)} />
371
+
372
+ </Stack>
373
+
374
+
375
+ {
376
+ overlay === Overlays.RemoveDirectory && (
377
+ <Overlay isVisible={true} onClose={() => setOverlay(Overlays.None)}>
378
+ <View layout="off-center-s" style={{ height: '100%' }}>
379
+ <View slot="content">
380
+ <View surface="primary" roundness="s">
381
+ <View surface="primary" inset="l" roundness="s">
382
+ <Guide
383
+ title="Remove directory"
384
+ text="Are you sure you want to remove this directory and everything in it?"
385
+ actions={[
386
+ { label: 'Cancel', variant: "command", onClick: () => setOverlay(Overlays.None) },
387
+ { label: 'Remove', variant: 'command-danger', onClick: () => {
388
+ removeResource(selectedResourceId)
389
+ setOverlay(Overlays.None)
390
+ }}
391
+ ]}
392
+ />
393
+ </View>
394
+ </View>
395
+ </View>
396
+ </View>
397
+ </Overlay>
398
+ )
399
+ }
400
+
401
+ {
402
+ overlay === Overlays.MoveResource && (
403
+ <Overlay isVisible={true} onClose={() => setOverlay(Overlays.None)}>
404
+ <ResourceDialogMove onClose={() => setOverlay(Overlays.None)} resourceId={selectedResourceId}/>
405
+ </Overlay>
406
+ )
407
+ }
408
+
409
+ </View>
410
+ )
411
+ }
412
+
@@ -0,0 +1,84 @@
1
+ import React from 'react'
2
+ import {
3
+ Title,
4
+ Text,
5
+ View,
6
+ Icon2,
7
+ PageSection,
8
+ MarkdownViewer
9
+ } from '@ossy/design-system'
10
+ import { HeroCover } from './HeroCover.jsx'
11
+
12
+ export default ({
13
+ cover,
14
+ features
15
+ }) => {
16
+ return (
17
+ <PageSection maxWidth="xl" gap="l">
18
+
19
+ <View gap="l" surface="primary" style={{ padding: 'var(--space-m) var(--space-l)', height: '100%', overflowY: 'auto' }}>
20
+
21
+ <HeroCover {...cover} />
22
+
23
+ <View gap="m" inset="s">
24
+
25
+ <Title variant="secondary">
26
+ Overview
27
+ </Title>
28
+
29
+ <View gap="m" layout="row-wrap">
30
+ {features.map(x => (
31
+ <View
32
+ key={x.title}
33
+ roundness="m"
34
+ surface="primary"
35
+ inset="m"
36
+ gap="m"
37
+ style={{
38
+ width: 200,
39
+ border: '1px solid var(--separator)',
40
+ }}
41
+ >
42
+ <View justifyContent="center" alignItems="center">
43
+ <Icon2 name={x.icon} size="m" />
44
+ </View>
45
+ <Text variant="small" style={{ fontWeight: 'bold', textAlign: 'center' }}>{x.title}</Text>
46
+ <Text variant="small" style={{ textAlign: 'center' }}>{x.text}</Text>
47
+ </View>
48
+ ))}
49
+
50
+ </View>
51
+ </View>
52
+
53
+ <View gap="m" inset="s">
54
+ <Title variant="secondary">
55
+ Features
56
+ </Title>
57
+
58
+ {features.map(x => (
59
+ <View key={x.title} roundness="m" gap="m" inset="l" style={{
60
+ border: '1px solid var(--separator)',
61
+ }}>
62
+
63
+ <View layout="row" gap="s" alignItems="center">
64
+ <View justifyContent="center" alignItems="center">
65
+ <Icon2 name={x.icon} size="m" />
66
+ </View>
67
+ <Title variant="tertiary">
68
+ {x.title}
69
+ </Title>
70
+ </View>
71
+
72
+ <Text>{x.text}</Text>
73
+
74
+ { x.content && <MarkdownViewer children={x.content} /> }
75
+ </View>
76
+ ))}
77
+ </View>
78
+
79
+
80
+ </View>
81
+
82
+ </PageSection>
83
+ )
84
+ }
package/src/cover.js ADDED
@@ -0,0 +1,5 @@
1
+ export const cover = {
2
+ title: 'Storage',
3
+ titleVariant: 'primary',
4
+ text: 'Managing content should be easy',
5
+ }
@@ -0,0 +1,54 @@
1
+ export const features = [
2
+ {
3
+ "title": "Web UI",
4
+ "text": "Simple, intuitive interface with familiar directory structure.",
5
+ "icon": "browser",
6
+ "content": `<img src={https://d1yuixo7x29bj4.cloudfront.net/36zDqF0TKZZ5KkJdyg7NH/KgqxjIFZpuVl-VMydMDdC.png} />`
7
+ },
8
+ {
9
+ "title": "Collaboration",
10
+ "text": "Invite team members and manage user permissions.",
11
+ "icon": "user-list"
12
+ },
13
+ {
14
+ "title": "React hooks",
15
+ "text": "Load content with useResources by passing a folder path.",
16
+ "icon": "code-slash",
17
+ "content": `
18
+ \`\`\`
19
+ // Layout / SiteDocumentHead
20
+ import { WorkspaceProvider, useResources } from '@ossy/sdk-react'
21
+
22
+ export const App = () => (
23
+ <WorkspaceProvider workspaceId="your-workspace-id">
24
+ <MyComponent />
25
+ </WorkspaceProvider>
26
+ )
27
+
28
+ const MyComponent = () => {
29
+ const { status, resources } = useResources('/folder/path/in/cms')
30
+
31
+ return status !== 'Success'
32
+ ? <>Loading...</>
33
+ : <>{resources.map(resource => <div key={resource.id}>{resource.name}</div>)}</>
34
+ }
35
+
36
+ \`\`\`
37
+ `
38
+ },
39
+ {
40
+ "title": "REST API",
41
+ "text": "JSON-based API access with simple token authentication.",
42
+ "icon": "plug"
43
+ },
44
+ {
45
+ "title": "Custom fields",
46
+ "text": "Define content structure with JSON field definitions.",
47
+ "icon": "list"
48
+ },
49
+ {
50
+ "title": "CI/CD ready",
51
+ "text": "Store field definitions in Git and integrate with your pipeline.",
52
+ "icon": "git-branch"
53
+ },
54
+ ]
package/src/index.js CHANGED
@@ -1 +1,4 @@
1
1
  export { Definition } from './Definition.js'
2
+ export { ResourcesPage } from './ResourcesPage.jsx'
3
+ export { cover } from './cover.js'
4
+ export { features } from './features.js'
@@ -0,0 +1,19 @@
1
+ import React from 'react'
2
+ import { ResourcesPage } from './ResourcesPage.jsx'
3
+ import { useApp } from '@ossy/app/shell'
4
+ import { cover } from './cover.js'
5
+ import { features } from './features.js'
6
+ import SalesSection from './SalesSection.jsx'
7
+
8
+ export const metadata = {
9
+ id: 'storage/home',
10
+ path: {
11
+ sv: '/storage',
12
+ en: '/storage',
13
+ },
14
+ }
15
+
16
+ export default () => {
17
+ const app = useApp()
18
+ return app?.isAuthenticated ? <ResourcesPage /> : <SalesSection cover={cover} features={features} />
19
+ }