@dxos/react-ui-stack 0.7.5-main.9cb18ac → 0.7.5-main.9d2a38b

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.
@@ -2,7 +2,7 @@
2
2
  // Copyright 2024 DXOS.org
3
3
  //
4
4
 
5
- import React, { type ComponentPropsWithoutRef } from 'react';
5
+ import React, { type ComponentPropsWithoutRef, forwardRef } from 'react';
6
6
 
7
7
  import { type ThemedClassName } from '@dxos/react-ui';
8
8
  import { mx } from '@dxos/react-ui-theme';
@@ -10,33 +10,51 @@ import { mx } from '@dxos/react-ui-theme';
10
10
  import { useStack } from './StackContext';
11
11
 
12
12
  export type StackItemContentProps = ThemedClassName<ComponentPropsWithoutRef<'div'>> & {
13
- toolbar?: boolean;
13
+ /**
14
+ * This flag is required in order to clarify a developer experience that seemed like it needed extra boilerplate
15
+ * (`row-span-2`) or was buggy. See the description of the StackItem.Content component itself for more information.
16
+ */
17
+ toolbar: boolean;
18
+ /**
19
+ * Whether to provide for the layout of a statusbar after the content.
20
+ */
14
21
  statusbar?: boolean;
22
+ /**
23
+ * Whether to set a certain aspect ratio on the content, including the toolbar and statusbar. This is provided for
24
+ * convenience and consistency; it can instead be specified by the `classNames` or `style` props as needed.
25
+ */
26
+ size?: 'intrinsic' | 'video' | 'square';
15
27
  };
16
28
 
17
- export const StackItemContent = ({
18
- children,
19
- toolbar = true,
20
- statusbar,
21
- classNames,
22
- ...props
23
- }: StackItemContentProps) => {
24
- const { size } = useStack();
29
+ /**
30
+ * This component should be used by plugins for rendering content within a stack item, a.k.a. a “plank” or “section”.
31
+ * The `toolbar` flag must be provided since this component provides for the layout of content with the toolbar.
32
+ */
33
+ export const StackItemContent = forwardRef<HTMLDivElement, StackItemContentProps>(
34
+ ({ children, toolbar, statusbar, classNames, size = 'intrinsic', ...props }, forwardedRef) => {
35
+ const { size: stackItemSize } = useStack();
25
36
 
26
- return (
27
- <div
28
- role='none'
29
- {...props}
30
- className={mx('group grid grid-cols-[100%]', size === 'contain' && 'min-bs-0 overflow-hidden', classNames)}
31
- style={{
32
- gridTemplateRows: [
33
- ...(toolbar ? ['var(--rail-action)'] : []),
34
- '1fr',
35
- ...(statusbar ? ['var(--statusbar-size)'] : []),
36
- ].join(' '),
37
- }}
38
- >
39
- {children}
40
- </div>
41
- );
42
- };
37
+ return (
38
+ <div
39
+ role='none'
40
+ {...props}
41
+ className={mx(
42
+ 'group grid grid-cols-[100%]',
43
+ stackItemSize === 'contain' && 'min-bs-0 overflow-hidden',
44
+ size === 'video' ? 'aspect-video' : size === 'square' && 'aspect-square',
45
+ classNames,
46
+ )}
47
+ style={{
48
+ gridTemplateRows: [
49
+ ...(toolbar ? ['var(--rail-action)'] : []),
50
+ '1fr',
51
+ ...(statusbar ? ['var(--statusbar-size)'] : []),
52
+ ].join(' '),
53
+ }}
54
+ ref={forwardedRef}
55
+ >
56
+ {children}
57
+ </div>
58
+ );
59
+ },
60
+ );
@@ -43,7 +43,7 @@ export const StackItemHeadingLabel = forwardRef<HTMLHeadingElement, StackItemHea
43
43
  {...props}
44
44
  data-attention={((related && isRelated) || hasAttention || isAncestor).toString()}
45
45
  className={mx(
46
- 'pli-1 min-is-0 is-0 grow truncate font-medium text-baseText data-[attention=true]:text-accentText',
46
+ 'pli-1 min-is-0 is-0 grow truncate font-medium text-baseText data-[attention=true]:text-accentText self-center',
47
47
  classNames,
48
48
  )}
49
49
  ref={forwardedRef}
@@ -42,7 +42,7 @@ export const StackItemSigilButton = forwardRef<HTMLButtonElement, StackItemSigil
42
42
  <Button
43
43
  {...props}
44
44
  variant={variant}
45
- classNames={['m-1 shrink-0 pli-0 min-bs-0 is-[--rail-action] bs-[--rail-action] relative', classNames]}
45
+ classNames={['shrink-0 pli-0 min-bs-0 is-[--rail-action] bs-[--rail-action] relative', classNames]}
46
46
  ref={forwardedRef}
47
47
  >
48
48
  <MenuSignifierHorizontal />
@@ -1,8 +0,0 @@
1
- import React from 'react';
2
- import { type StackItemContentProps } from '../components';
3
- export declare const EditorContent: ({ data: { content } }: {
4
- data: StackItemContentProps & {
5
- content?: string;
6
- };
7
- }) => React.JSX.Element;
8
- //# sourceMappingURL=EditorContent.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"EditorContent.d.ts","sourceRoot":"","sources":["../../../../src/testing/EditorContent.tsx"],"names":[],"mappings":"AAIA,OAAO,KAAmB,MAAM,OAAO,CAAC;AAkBxC,OAAO,EAAa,KAAK,qBAAqB,EAAE,MAAM,eAAe,CAAC;AAEtE,eAAO,MAAM,aAAa,0BAAgC;IAAE,IAAI,EAAE,qBAAqB,GAAG;QAAE,OAAO,CAAC,EAAE,MAAM,CAAA;KAAE,CAAA;CAAE,sBAmC/G,CAAC"}
@@ -1,60 +0,0 @@
1
- //
2
- // Copyright 2024 DXOS.org
3
- //
4
-
5
- import React, { useState } from 'react';
6
-
7
- import { Expando } from '@dxos/echo-schema';
8
- import { create } from '@dxos/live-object';
9
- import { useThemeContext } from '@dxos/react-ui';
10
- import {
11
- createBasicExtensions,
12
- createMarkdownExtensions,
13
- createThemeExtensions,
14
- decorateMarkdown,
15
- formattingKeymap,
16
- Toolbar,
17
- useActionHandler,
18
- useFormattingState,
19
- useTextEditor,
20
- } from '@dxos/react-ui-editor';
21
- import { focusRing, mx, textBlockWidth } from '@dxos/react-ui-theme';
22
-
23
- import { StackItem, type StackItemContentProps } from '../components';
24
-
25
- export const EditorContent = ({ data: { content = '' } }: { data: StackItemContentProps & { content?: string } }) => {
26
- const { themeMode } = useThemeContext();
27
- const [text] = useState(create(Expando, { content }));
28
- const id = text.id;
29
- const [formattingState, formattingObserver] = useFormattingState();
30
- const { parentRef, view, focusAttributes } = useTextEditor(() => {
31
- return {
32
- id,
33
- initialValue: text.content,
34
- extensions: [
35
- formattingObserver,
36
- createBasicExtensions(),
37
- createMarkdownExtensions({ themeMode }),
38
- createThemeExtensions({ themeMode, syntaxHighlighting: true, slots: { editor: { className: 'p-2' } } }),
39
- decorateMarkdown(),
40
- formattingKeymap(),
41
- ],
42
- };
43
- }, [id, formattingObserver, themeMode]);
44
-
45
- const handleAction = useActionHandler(view);
46
-
47
- return (
48
- <StackItem.Content>
49
- <div {...focusAttributes} className={mx(textBlockWidth, focusRing, 'rounded-sm order-last')} ref={parentRef} />
50
- <Toolbar.Root
51
- onAction={handleAction}
52
- state={formattingState}
53
- classNames='sticky block-start-0 bg-[--sticky-bg] z-10'
54
- >
55
- <Toolbar.Markdown />
56
- <Toolbar.Separator />
57
- </Toolbar.Root>
58
- </StackItem.Content>
59
- );
60
- };