@dxos/plugin-presenter 0.6.8-main.046e6cf

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 (97) hide show
  1. package/LICENSE +8 -0
  2. package/README.md +3 -0
  3. package/dist/lib/browser/MarkdownSlide-RIKDY66R.mjs +313 -0
  4. package/dist/lib/browser/MarkdownSlide-RIKDY66R.mjs.map +7 -0
  5. package/dist/lib/browser/PresenterMain-J5Y5ND2S.mjs +228 -0
  6. package/dist/lib/browser/PresenterMain-J5Y5ND2S.mjs.map +7 -0
  7. package/dist/lib/browser/RevealMain-3KPVP35M.mjs +170 -0
  8. package/dist/lib/browser/RevealMain-3KPVP35M.mjs.map +7 -0
  9. package/dist/lib/browser/chunk-KWRWOGSM.mjs +20 -0
  10. package/dist/lib/browser/chunk-KWRWOGSM.mjs.map +7 -0
  11. package/dist/lib/browser/chunk-XDACGTXJ.mjs +18 -0
  12. package/dist/lib/browser/chunk-XDACGTXJ.mjs.map +7 -0
  13. package/dist/lib/browser/index.mjs +216 -0
  14. package/dist/lib/browser/index.mjs.map +7 -0
  15. package/dist/lib/browser/meta.json +1 -0
  16. package/dist/lib/browser/meta.mjs +9 -0
  17. package/dist/lib/browser/meta.mjs.map +7 -0
  18. package/dist/types/src/PresenterPlugin.d.ts +4 -0
  19. package/dist/types/src/PresenterPlugin.d.ts.map +1 -0
  20. package/dist/types/src/components/Markdown/Container.d.ts +8 -0
  21. package/dist/types/src/components/Markdown/Container.d.ts.map +1 -0
  22. package/dist/types/src/components/Markdown/Container.stories.d.ts +34 -0
  23. package/dist/types/src/components/Markdown/Container.stories.d.ts.map +1 -0
  24. package/dist/types/src/components/Markdown/Slide.d.ts +10 -0
  25. package/dist/types/src/components/Markdown/Slide.d.ts.map +1 -0
  26. package/dist/types/src/components/Markdown/Slide.stories.d.ts +15 -0
  27. package/dist/types/src/components/Markdown/Slide.stories.d.ts.map +1 -0
  28. package/dist/types/src/components/Markdown/index.d.ts +3 -0
  29. package/dist/types/src/components/Markdown/index.d.ts.map +1 -0
  30. package/dist/types/src/components/Markdown/theme.d.ts +16 -0
  31. package/dist/types/src/components/Markdown/theme.d.ts.map +1 -0
  32. package/dist/types/src/components/MarkdownSlide.d.ts +7 -0
  33. package/dist/types/src/components/MarkdownSlide.d.ts.map +1 -0
  34. package/dist/types/src/components/Presenter/Layout.d.ts +11 -0
  35. package/dist/types/src/components/Presenter/Layout.d.ts.map +1 -0
  36. package/dist/types/src/components/Presenter/Pager.d.ts +19 -0
  37. package/dist/types/src/components/Presenter/Pager.d.ts.map +1 -0
  38. package/dist/types/src/components/Presenter/Pager.stories.d.ts +14 -0
  39. package/dist/types/src/components/Presenter/Pager.stories.d.ts.map +1 -0
  40. package/dist/types/src/components/Presenter/index.d.ts +3 -0
  41. package/dist/types/src/components/Presenter/index.d.ts.map +1 -0
  42. package/dist/types/src/components/PresenterMain.d.ts +7 -0
  43. package/dist/types/src/components/PresenterMain.d.ts.map +1 -0
  44. package/dist/types/src/components/PresenterSettings.d.ts +6 -0
  45. package/dist/types/src/components/PresenterSettings.d.ts.map +1 -0
  46. package/dist/types/src/components/Reveal/Reveal.d.ts +10 -0
  47. package/dist/types/src/components/Reveal/Reveal.d.ts.map +1 -0
  48. package/dist/types/src/components/Reveal/index.d.ts +2 -0
  49. package/dist/types/src/components/Reveal/index.d.ts.map +1 -0
  50. package/dist/types/src/components/Reveal.stories.d.ts +9 -0
  51. package/dist/types/src/components/Reveal.stories.d.ts.map +1 -0
  52. package/dist/types/src/components/RevealMain.d.ts +7 -0
  53. package/dist/types/src/components/RevealMain.d.ts.map +1 -0
  54. package/dist/types/src/components/index.d.ts +12 -0
  55. package/dist/types/src/components/index.d.ts.map +1 -0
  56. package/dist/types/src/hooks/index.d.ts +2 -0
  57. package/dist/types/src/hooks/index.d.ts.map +1 -0
  58. package/dist/types/src/hooks/useControlledValue.d.ts +3 -0
  59. package/dist/types/src/hooks/useControlledValue.d.ts.map +1 -0
  60. package/dist/types/src/index.d.ts +5 -0
  61. package/dist/types/src/index.d.ts.map +1 -0
  62. package/dist/types/src/meta.d.ts +15 -0
  63. package/dist/types/src/meta.d.ts.map +1 -0
  64. package/dist/types/src/testing.d.ts +10 -0
  65. package/dist/types/src/testing.d.ts.map +1 -0
  66. package/dist/types/src/translations.d.ts +11 -0
  67. package/dist/types/src/translations.d.ts.map +1 -0
  68. package/dist/types/src/types.d.ts +14 -0
  69. package/dist/types/src/types.d.ts.map +1 -0
  70. package/package.json +80 -0
  71. package/src/PresenterPlugin.tsx +158 -0
  72. package/src/components/Markdown/Container.stories.tsx +54 -0
  73. package/src/components/Markdown/Container.tsx +81 -0
  74. package/src/components/Markdown/Slide.stories.tsx +22 -0
  75. package/src/components/Markdown/Slide.tsx +218 -0
  76. package/src/components/Markdown/index.ts +6 -0
  77. package/src/components/Markdown/theme.ts +26 -0
  78. package/src/components/MarkdownSlide.tsx +24 -0
  79. package/src/components/Presenter/Layout.tsx +33 -0
  80. package/src/components/Presenter/Pager.stories.tsx +32 -0
  81. package/src/components/Presenter/Pager.tsx +124 -0
  82. package/src/components/Presenter/index.ts +6 -0
  83. package/src/components/PresenterMain.tsx +85 -0
  84. package/src/components/PresenterSettings.tsx +26 -0
  85. package/src/components/Reveal/Reveal.tsx +136 -0
  86. package/src/components/Reveal/index.ts +5 -0
  87. package/src/components/Reveal.stories.tsx +32 -0
  88. package/src/components/RevealMain.tsx +49 -0
  89. package/src/components/index.ts +12 -0
  90. package/src/hooks/index.ts +5 -0
  91. package/src/hooks/useControlledValue.ts +14 -0
  92. package/src/index.ts +11 -0
  93. package/src/meta.tsx +18 -0
  94. package/src/testing.ts +48 -0
  95. package/src/translations.ts +17 -0
  96. package/src/types.ts +39 -0
  97. package/src/typings.d.ts +15 -0
@@ -0,0 +1,54 @@
1
+ //
2
+ // Copyright 2023 DXOS.org
3
+ //
4
+
5
+ import '@dxosTheme';
6
+
7
+ import React, { type FC } from 'react';
8
+
9
+ import { withFullscreen, withTheme } from '@dxos/storybook-utils';
10
+
11
+ import { Container } from './Container';
12
+ import { Slide } from './Slide';
13
+ import { createSlide } from '../../testing';
14
+
15
+ const Story: FC<{ content: string }> = ({ content }) => {
16
+ return (
17
+ <Container classNames='bg-neutral-200'>
18
+ <Slide content={content} />
19
+ </Container>
20
+ );
21
+ };
22
+
23
+ export default {
24
+ title: 'plugin-presenter/Container',
25
+ render: Story,
26
+ decorators: [withTheme, withFullscreen()],
27
+ parameters: {
28
+ layout: 'fullscreen',
29
+ },
30
+ };
31
+
32
+ export const Default = {
33
+ args: {
34
+ content: createSlide({ number: 1 }),
35
+ },
36
+ };
37
+
38
+ export const Code = {
39
+ args: {
40
+ content: createSlide({ code: true }),
41
+ },
42
+ };
43
+
44
+ export const List = {
45
+ args: {
46
+ content: createSlide({ list: 3 }),
47
+ },
48
+ };
49
+
50
+ export const Ordered = {
51
+ args: {
52
+ content: createSlide({ ordered: 4 }),
53
+ },
54
+ };
@@ -0,0 +1,81 @@
1
+ //
2
+ // Copyright 2023 DXOS.org
3
+ //
4
+
5
+ import React, { type PropsWithChildren, useState } from 'react';
6
+ import { useResizeDetector } from 'react-resize-detector';
7
+
8
+ import { type ThemedClassName } from '@dxos/react-ui';
9
+ import { mx } from '@dxos/react-ui-theme';
10
+
11
+ export type ContainerProps = ThemedClassName<PropsWithChildren<{}>>;
12
+
13
+ /**
14
+ * Scaled markdown container.
15
+ */
16
+ export const Container = ({ children, classNames }: ContainerProps) => {
17
+ const [props, setProps] = useState({});
18
+ const {
19
+ ref: containerRef,
20
+ width,
21
+ height,
22
+ } = useResizeDetector({
23
+ refreshMode: 'debounce',
24
+ refreshRate: 200,
25
+ refreshOptions: {
26
+ leading: true,
27
+ },
28
+ onResize: ({ width, height }) => {
29
+ if (width && height) {
30
+ setProps(createLayoutProps({ width, height }));
31
+ }
32
+ },
33
+ });
34
+
35
+ // TODO(burdon): Reconcile highlight colors with markdown editor.
36
+ // https://www.npmjs.com/package/react-markdown
37
+ return (
38
+ <div ref={containerRef} className={mx('flex grow relative overflow-hidden bg-attention', classNames)}>
39
+ <div className={mx('flex w-full h-full overflow-hidden absolute')} style={props}>
40
+ {width && height && children}
41
+ </div>
42
+ </div>
43
+ );
44
+ };
45
+
46
+ /**
47
+ * Compute CSS properties to transform DIV to be full screen.
48
+ *
49
+ * Display resolutions:
50
+ * window.screen.{availWidth, availHeight}
51
+ * 5K Studio 16.2-inch Macbook Pro
52
+ * Max 5120 x 2880 3456 x 2234
53
+ * Default 2560 x 1440 1728 x 1117 (Actual height 1080 - 37 pixel notch)
54
+ * Aspect 1.77 (16/9) 1.54
55
+ */
56
+ const createLayoutProps = ({ width, height }: { width: number; height: number }) => {
57
+ // Config.
58
+ const aspectRatio = 16 / 9;
59
+ const nominalWidth = 2560;
60
+ const nominalHeight = nominalWidth / aspectRatio;
61
+
62
+ // NOTE: Hack to detect full height on Macbook Pro due to notch.
63
+ // const macIntelNotch = 1117 - 1080;
64
+ // const fullscreen =
65
+ // height === screen.availHeight ||
66
+ // (window.navigator.platform === 'MacIntel' && height === screen.availHeight - macIntelNotch);
67
+
68
+ // If not fullscreen then make scale slightly smaller so there's a natural border.
69
+ // const scaleFactor = fullscreen ? 1 : 0.95;
70
+
71
+ // Compute scaling factor required.
72
+ const scale = Math.min(width / nominalWidth, height / nominalHeight);
73
+
74
+ return {
75
+ left: (width - nominalWidth) / 2,
76
+ top: (height - nominalHeight) / 2,
77
+ width: nominalWidth,
78
+ height: nominalHeight,
79
+ transform: `scale(${scale})`,
80
+ };
81
+ };
@@ -0,0 +1,22 @@
1
+ //
2
+ // Copyright 2023 DXOS.org
3
+ //
4
+
5
+ import '@dxosTheme';
6
+
7
+ import { Slide } from './Slide';
8
+ import { createSlide } from '../../testing';
9
+
10
+ export default {
11
+ title: 'plugin-presenter/Slide',
12
+ component: Slide,
13
+ parameters: {
14
+ layout: 'fullscreen',
15
+ },
16
+ };
17
+
18
+ export const Default = {
19
+ args: {
20
+ content: createSlide(),
21
+ },
22
+ };
@@ -0,0 +1,218 @@
1
+ //
2
+ // Copyright 2023 DXOS.org
3
+ //
4
+
5
+ import { h } from 'hastscript';
6
+ import React from 'react';
7
+ import ReactMarkdown from 'react-markdown';
8
+ import addClasses from 'rehype-add-classes';
9
+ import highlight from 'rehype-highlight';
10
+ import remarkFrontmatter from 'remark-frontmatter';
11
+ import remarkParseFrontmatter from 'remark-parse-frontmatter';
12
+
13
+ import 'highlight.js/styles/github.css';
14
+
15
+ import { theme } from './theme';
16
+
17
+ export type SlideProps = {
18
+ content?: string;
19
+ classes?: { [selector: string]: string };
20
+ };
21
+
22
+ export const Slide = ({ content = '', classes = theme.nodes }: SlideProps) => {
23
+ // TODO(thure): `rehype-highlight` ends up using `github.css` from `highlight.js`, but this does not appear to be
24
+ // configurable. Find a way to remove the literal stylesheet here.
25
+ return (
26
+ <>
27
+ <style>{`
28
+ .dark pre code.hljs {
29
+ display: block;
30
+ overflow-x: auto;
31
+ padding: 1em
32
+ }
33
+ .dark code.hljs {
34
+ padding: 3px 5px
35
+ }
36
+ /*!
37
+ Theme: GitHub Dark
38
+ Description: Dark theme as seen on github.com
39
+ Author: github.com
40
+ Maintainer: @Hirse
41
+ Updated: 2021-05-15
42
+
43
+ Outdated base version: https://github.com/primer/github-syntax-dark
44
+ Current colors taken from GitHub's CSS
45
+ */
46
+ .dark .hljs {
47
+ color: #c9d1d9;
48
+ background: #0d1117
49
+ }
50
+ .dark .hljs-doctag,
51
+ .dark .hljs-keyword,
52
+ .dark .hljs-meta .hljs-keyword,
53
+ .dark .hljs-template-tag,
54
+ .dark .hljs-template-variable,
55
+ .dark .hljs-type,
56
+ .dark .hljs-variable.language_ {
57
+ /* prettylights-syntax-keyword */
58
+ color: #ff7b72
59
+ }
60
+ .dark .hljs-title,
61
+ .dark .hljs-title.class_,
62
+ .dark .hljs-title.class_.inherited__,
63
+ .dark .hljs-title.function_ {
64
+ /* prettylights-syntax-entity */
65
+ color: #d2a8ff
66
+ }
67
+ .dark .hljs-attr,
68
+ .dark .hljs-attribute,
69
+ .dark .hljs-literal,
70
+ .dark .hljs-meta,
71
+ .dark .hljs-number,
72
+ .dark .hljs-operator,
73
+ .dark .hljs-variable,
74
+ .dark .hljs-selector-attr,
75
+ .dark .hljs-selector-class,
76
+ .dark .hljs-selector-id {
77
+ /* prettylights-syntax-constant */
78
+ color: #79c0ff
79
+ }
80
+ .dark .hljs-regexp,
81
+ .dark .hljs-string,
82
+ .dark .hljs-meta .hljs-string {
83
+ /* prettylights-syntax-string */
84
+ color: #a5d6ff
85
+ }
86
+ .dark .hljs-built_in,
87
+ .dark .hljs-symbol {
88
+ /* prettylights-syntax-variable */
89
+ color: #ffa657
90
+ }
91
+ .dark .hljs-comment,
92
+ .dark .hljs-code,
93
+ .dark .hljs-formula {
94
+ /* prettylights-syntax-comment */
95
+ color: #8b949e
96
+ }
97
+ .dark .hljs-name,
98
+ .dark .hljs-quote,
99
+ .dark .hljs-selector-tag,
100
+ .dark .hljs-selector-pseudo {
101
+ /* prettylights-syntax-entity-tag */
102
+ color: #7ee787
103
+ }
104
+ .dark .hljs-subst {
105
+ /* prettylights-syntax-storage-modifier-import */
106
+ color: #c9d1d9
107
+ }
108
+ .dark .hljs-section {
109
+ /* prettylights-syntax-markup-heading */
110
+ color: #1f6feb;
111
+ font-weight: bold
112
+ }
113
+ .dark .hljs-bullet {
114
+ /* prettylights-syntax-markup-list */
115
+ color: #f2cc60
116
+ }
117
+ .dark .hljs-emphasis {
118
+ /* prettylights-syntax-markup-italic */
119
+ color: #c9d1d9;
120
+ font-style: italic
121
+ }
122
+ .dark .hljs-strong {
123
+ /* prettylights-syntax-markup-bold */
124
+ color: #c9d1d9;
125
+ font-weight: bold
126
+ }
127
+ .dark .hljs-addition {
128
+ /* prettylights-syntax-markup-inserted */
129
+ color: #aff5b4;
130
+ background-color: #033a16
131
+ }
132
+ .dark .hljs-deletion {
133
+ /* prettylights-syntax-markup-deleted */
134
+ color: #ffdcd7;
135
+ background-color: #67060c
136
+ }
137
+ .dark .hljs-char.escape_,
138
+ .dark .hljs-link,
139
+ .dark .hljs-params,
140
+ .dark .hljs-property,
141
+ .dark .hljs-punctuation,
142
+ .dark .hljs-tag {
143
+ /* purposely ignored */
144
+
145
+ }
146
+ `}</style>
147
+ <ReactMarkdown
148
+ components={components}
149
+ // Markdown to HTML.
150
+ remarkPlugins={[[remarkFrontmatter, 'yaml'], remarkParseFrontmatter as any]}
151
+ // HTML processing.
152
+ rehypePlugins={[highlight, [addClasses, classes], slideLayout]}
153
+ >
154
+ {content}
155
+ </ReactMarkdown>
156
+ </>
157
+ );
158
+ };
159
+
160
+ /**
161
+ * Rehype plugin to format DOM based on frontmatter.
162
+ * https://github.com/unifiedjs/unified#plugin
163
+ * TODO(burdon): See tools/presenter: remarkPluginLayout
164
+ * E.g., layout image from front-matter.
165
+ */
166
+ const slideLayout =
167
+ (options = {}) =>
168
+ (tree: any, file: any) => {
169
+ const {
170
+ data: { frontmatter = {} },
171
+ } = file;
172
+
173
+ let content = tree.children;
174
+ const { layout, image } = frontmatter;
175
+ if (image) {
176
+ const img = h('div', {
177
+ class: 'flex grow shrink-0 bg-cover bg-center bg-no-repeat',
178
+ style: {
179
+ backgroundImage: `url(${image})`,
180
+ },
181
+ });
182
+
183
+ switch (layout) {
184
+ case 'fullscreen': {
185
+ content = img;
186
+ break;
187
+ }
188
+
189
+ case 'columns': {
190
+ content = h('div', { class: 'flex grow grid grid-cols-2' }, [
191
+ h('div', { class: theme.padding }, [content]),
192
+ img,
193
+ ]);
194
+ break;
195
+ }
196
+
197
+ case 'rows': {
198
+ content = h('div', { class: 'flex grow flex-col' }, [
199
+ h('div', { class: theme.padding }, [content]),
200
+ h('div', { class: ['flex grow pt-0', theme.padding] }, [img]),
201
+ ]);
202
+ break;
203
+ }
204
+ }
205
+ } else {
206
+ content = h('div', { class: ['flex grow flex-col', theme.padding] }, [content]);
207
+ }
208
+
209
+ const root = h('div', { class: ['flex flex-col grow', theme.root] }, [content]);
210
+ tree.children = [root];
211
+ };
212
+
213
+ const ImageWrapper = ({ node, ...props }: { node: any }) => {
214
+ const { alt = '', src } = props as { alt: string; src: string };
215
+ return <img alt={alt} src={src} />;
216
+ };
217
+
218
+ const components = { img: ImageWrapper };
@@ -0,0 +1,6 @@
1
+ //
2
+ // Copyright 2022 DXOS.org
3
+ //
4
+
5
+ export * from './Container';
6
+ export * from './Slide';
@@ -0,0 +1,26 @@
1
+ //
2
+ // Copyright 2023 DXOS.org
3
+ //
4
+
5
+ // TODO(burdon): Create theme type and picker.
6
+
7
+ export const theme = {
8
+ root: 'bg-attention leading-relaxed font-mono',
9
+
10
+ padding: 'px-40 py-16 gap-8',
11
+
12
+ nodes: {
13
+ h1: 'text-[80px] fg-accent',
14
+ h2: 'text-[60px] fg-accent',
15
+ h3: 'text-[48px] fg-accent',
16
+
17
+ p: 'text-[48px]',
18
+
19
+ ul: 'my-[16px] ml-12 leading-relaxed list-disc',
20
+ ol: 'my-[16px] ml-24 leading-relaxed list-decimal',
21
+ li: 'pl-6 text-[48px]',
22
+
23
+ pre: 'w-full mx-0 my-[32px] p-0 __border-l-[16px] surface-input p-4 __whitespace-pre-line',
24
+ code: 'p-0 text-[40px]',
25
+ },
26
+ };
@@ -0,0 +1,24 @@
1
+ //
2
+ // Copyright 2023 DXOS.org
3
+ //
4
+
5
+ import React, { type FC } from 'react';
6
+
7
+ import { type DocumentType } from '@dxos/plugin-markdown/types';
8
+
9
+ import { Container, Slide } from './Markdown';
10
+
11
+ const MarkdownSlide: FC<{ document: DocumentType }> = ({ document }) => {
12
+ const content = document.content?.content;
13
+ if (!content) {
14
+ return null;
15
+ }
16
+
17
+ return (
18
+ <Container>
19
+ <Slide content={content} />
20
+ </Container>
21
+ );
22
+ };
23
+
24
+ export default MarkdownSlide;
@@ -0,0 +1,33 @@
1
+ //
2
+ // Copyright 2023 DXOS.org
3
+ //
4
+
5
+ import React, { type PropsWithChildren, type ReactNode } from 'react';
6
+
7
+ import { type ThemedClassName } from '@dxos/react-ui';
8
+ import { mx } from '@dxos/react-ui-theme';
9
+
10
+ export type LayoutProps = ThemedClassName<
11
+ PropsWithChildren<{
12
+ className?: string;
13
+ topLeft?: ReactNode;
14
+ topRight?: ReactNode;
15
+ bottomLeft?: ReactNode;
16
+ bottomRight?: ReactNode;
17
+ }>
18
+ >;
19
+
20
+ export const Layout = ({ children, classNames, topLeft, topRight, bottomLeft, bottomRight }: LayoutProps) => {
21
+ return (
22
+ <div className={mx('flex grow relative overflow-hidden surface-attention', classNames)}>
23
+ <div className={mx('flex flex-col grow overflow-hidden')}>{children}</div>
24
+
25
+ <div className='z-[200]'>
26
+ <div className='absolute top-4 left-4'>{topLeft}</div>
27
+ <div className='absolute top-4 right-4'>{topRight}</div>
28
+ <div className='absolute bottom-4 left-4'>{bottomLeft}</div>
29
+ <div className='absolute bottom-4 right-4'>{bottomRight}</div>
30
+ </div>
31
+ </div>
32
+ );
33
+ };
@@ -0,0 +1,32 @@
1
+ //
2
+ // Copyright 2023 DXOS.org
3
+ //
4
+
5
+ import '@dxosTheme';
6
+
7
+ import React, { type FC, useState } from 'react';
8
+
9
+ import { PageNumber, Pager, StartButton } from './Pager';
10
+
11
+ const Story: FC<{ count?: number }> = ({ count = 20 }) => {
12
+ const [index, setIndex] = useState(0);
13
+ const [running, setRunning] = useState(false);
14
+
15
+ return (
16
+ <div className='grid grid-cols-3 gap-8'>
17
+ <Pager index={index} count={count} onChange={setIndex} />
18
+ <PageNumber index={index} count={count} />
19
+ <StartButton running={running} onClick={setRunning} />
20
+ </div>
21
+ );
22
+ };
23
+
24
+ export default {
25
+ title: 'plugin-presenter/Pager',
26
+ render: Story,
27
+ parameters: {
28
+ layout: 'centered',
29
+ },
30
+ };
31
+
32
+ export const Default = {};
@@ -0,0 +1,124 @@
1
+ //
2
+ // Copyright 2023 DXOS.org
3
+ //
4
+
5
+ import { Play, X, CaretDoubleLeft, CaretDoubleRight, CaretLeft, CaretRight } from '@phosphor-icons/react';
6
+ import React, { type FC, useEffect } from 'react';
7
+
8
+ import { Button } from '@dxos/react-ui';
9
+ import { getSize, mx } from '@dxos/react-ui-theme';
10
+
11
+ import { useControlledValue } from '../../hooks';
12
+
13
+ export type PagerProps = {
14
+ index?: number;
15
+ count?: number;
16
+ keys?: boolean; // TODO(burdon): Rename.
17
+ onChange?: (index: number) => void;
18
+ onExit?: () => void;
19
+ };
20
+
21
+ export const Pager = ({ index: controlledIndex = 0, count = 0, keys, onChange, onExit }: PagerProps) => {
22
+ const [index, setIndex] = useControlledValue(controlledIndex);
23
+ useEffect(() => {
24
+ onChange?.(index);
25
+ }, [index]);
26
+
27
+ const handleChangeIndex = (dir: number) => {
28
+ setIndex((index) => {
29
+ const next = index + dir;
30
+ return next >= 0 && next < count ? next : index;
31
+ });
32
+ };
33
+
34
+ // TODO(burdon): Standardize via system key binding.
35
+ useEffect(() => {
36
+ if (!keys) {
37
+ return;
38
+ }
39
+
40
+ const keydownHandler = (event: KeyboardEvent) => {
41
+ switch (event.key) {
42
+ case 'Escape': {
43
+ onExit?.();
44
+ break;
45
+ }
46
+ case 'ArrowLeft': {
47
+ if (event.shiftKey) {
48
+ onChange?.(0);
49
+ } else {
50
+ handleChangeIndex(-1);
51
+ }
52
+ break;
53
+ }
54
+ case 'ArrowRight': {
55
+ if (event.shiftKey) {
56
+ onChange?.(count - 1);
57
+ } else {
58
+ handleChangeIndex(1);
59
+ }
60
+ break;
61
+ }
62
+ case 'ArrowUp': {
63
+ onChange?.(0);
64
+ break;
65
+ }
66
+ case 'ArrowDown': {
67
+ onChange?.(count - 1);
68
+ break;
69
+ }
70
+ }
71
+ };
72
+
73
+ window.addEventListener('keydown', keydownHandler);
74
+ return () => window.removeEventListener('keydown', keydownHandler);
75
+ }, [keys, count]);
76
+
77
+ if (index === undefined || !count) {
78
+ return null;
79
+ }
80
+
81
+ return (
82
+ <div className='flex items-center text-neutral-500'>
83
+ <Button variant='ghost' classNames='p-0' onClick={() => onChange?.(0)}>
84
+ <CaretDoubleLeft className={mx(getSize(6))} />
85
+ </Button>
86
+ <Button variant='ghost' classNames='p-0' onClick={() => handleChangeIndex(-1)}>
87
+ <CaretLeft className={mx(getSize(6))} />
88
+ </Button>
89
+ <Button variant='ghost' classNames='p-0' onClick={() => handleChangeIndex(1)}>
90
+ <CaretRight className={mx(getSize(6))} />
91
+ </Button>
92
+ <Button variant='ghost' classNames='p-0' onClick={() => onChange?.(count - 1)}>
93
+ <CaretDoubleRight className={mx(getSize(6))} />
94
+ </Button>
95
+ </div>
96
+ );
97
+ };
98
+
99
+ export type PageNumberProps = {
100
+ index?: number;
101
+ count?: number;
102
+ };
103
+
104
+ export const PageNumber = ({ index = 0, count = 1 }: PageNumberProps) => {
105
+ if (index === undefined || !count) {
106
+ return null;
107
+ }
108
+
109
+ return (
110
+ <div className='flex items-center text-neutral-500 text-2xl'>
111
+ <div>
112
+ {index + 1} / {count}
113
+ </div>
114
+ </div>
115
+ );
116
+ };
117
+
118
+ export const StartButton: FC<{ running?: boolean; onClick?: (start: boolean) => void }> = ({ running, onClick }) => {
119
+ return (
120
+ <Button variant='ghost' classNames='p-0' onClick={() => onClick?.(!running)}>
121
+ {(running && <X className={mx(getSize(6))} />) || <Play className={mx(getSize(6))} />}
122
+ </Button>
123
+ );
124
+ };
@@ -0,0 +1,6 @@
1
+ //
2
+ // Copyright 2022 DXOS.org
3
+ //
4
+
5
+ export * from './Layout';
6
+ export * from './Pager';