Skip to content

Commit 85ac228

Browse files
committed
AsyncMarkdownEditor and MarkdownWrapper should share styles #917
1 parent 28a1f5c commit 85ac228

File tree

9 files changed

+67
-80
lines changed

9 files changed

+67
-80
lines changed

browser/data-browser/src/chunks/MarkdownEditor/AsyncMarkdownEditor.tsx

Lines changed: 4 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import { ToggleButton } from './ToggleButton';
1414
import { SlashCommands, suggestion } from './SlashMenu/CommandsExtension';
1515
import { ExtendedImage } from './ImagePicker';
1616
import { transition } from '../../helpers/transition';
17+
import { markdownStyles } from '../../components/datatypes/Markdown';
1718

1819
export type AsyncMarkdownEditorProps = {
1920
placeholder?: string;
@@ -110,7 +111,7 @@ export default function AsyncMarkdownEditor({
110111
/>
111112
)}
112113
<EditorContent key='rich-editor' editor={editor}>
113-
<FloatingMenu editor={editor ?? undefined}>
114+
<FloatingMenu editor={editor}>
114115
<FloatingMenuText>Type &apos;/&apos; for options</FloatingMenuText>
115116
</FloatingMenu>
116117
<BubbleMenu />
@@ -137,6 +138,7 @@ const calcHeight = (value: string) => {
137138
return `calc(${lines * LINE_HEIGHT}em + 5px)`;
138139
};
139140

141+
// WARNING: Only add styles specific to editing. For other styles, add to `MarkdownWrapper`
140142
const EditorWrapper = styled.div<{ hideEditor: boolean }>`
141143
position: relative;
142144
background-color: ${p => p.theme.colors.bg};
@@ -171,27 +173,7 @@ const EditorWrapper = styled.div<{ hideEditor: boolean }>`
171173
height: auto;
172174
}
173175
174-
pre {
175-
padding: 0.75rem 1rem;
176-
background-color: ${p => p.theme.colors.bg1};
177-
border-radius: ${p => p.theme.radius};
178-
font-family: monospace;
179-
180-
code {
181-
white-space: pre;
182-
color: inherit;
183-
padding: 0;
184-
background: none;
185-
font-size: 0.8rem;
186-
}
187-
}
188-
189-
blockquote {
190-
margin-inline-start: 0;
191-
border-inline-start: 3px solid ${p => p.theme.colors.textLight2};
192-
color: ${p => p.theme.colors.textLight};
193-
padding-inline-start: 1rem;
194-
}
176+
${markdownStyles}
195177
}
196178
`;
197179

browser/data-browser/src/components/Card.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ export const CardRow = styled.div<CardRowProps>`
4242
display: block;
4343
border-top: ${p => (p.noBorder ? 'none' : 'var(--border)')};
4444
padding: ${p => p.theme.size(2)} ${p => p.theme.size()};
45+
overflow-wrap: break-word;
4546
`;
4647

4748
/** A block inside a Card which has full width */

browser/data-browser/src/components/SearchFilter.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { useEffect, useState } from 'react';
2-
import { urls, useArray, useProperty, useResource } from '@tomic/react';
2+
import { core, urls, useArray, useProperty, useResource } from '@tomic/react';
33
import { ResourceSelector } from '../components/forms/ResourceSelector';
44

55
/**
@@ -18,7 +18,7 @@ export function ClassFilter({ filters, setFilters }): JSX.Element {
1818
// Set the filters to the default values of the properties
1919
setFilters({
2020
...filters,
21-
[urls.properties.isA]: klass,
21+
[core.properties.isA]: klass,
2222
});
2323
}, [klass, JSON.stringify(filters)]);
2424

@@ -27,7 +27,7 @@ export function ClassFilter({ filters, setFilters }): JSX.Element {
2727
<ResourceSelector
2828
setSubject={setClass}
2929
value={klass}
30-
isA={urls.classes.class}
30+
classType={core.classes.class}
3131
/>
3232
{allProps?.map(propertySubject => (
3333
<PropertyFilter

browser/data-browser/src/components/datatypes/Markdown.tsx

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import ReactMarkdown from 'react-markdown';
2-
import { styled } from 'styled-components';
2+
import { css, styled } from 'styled-components';
33
import remarkGFM from 'remark-gfm';
44
import { Button } from '../Button';
55
import { truncateMarkdown } from '../../helpers/markdown';
@@ -44,16 +44,11 @@ Markdown.defaultProps = {
4444
renderGFM: true,
4545
};
4646

47-
const MarkdownWrapper = styled.div`
48-
width: 100%;
49-
overflow-x: hidden;
50-
img {
51-
max-width: 100%;
52-
}
53-
54-
* {
47+
/** Styles shared in Markdown View & Edit renderers */
48+
export const markdownStyles = css`
49+
/* * {
5550
white-space: unset;
56-
}
51+
} */
5752
5853
p,
5954
h1,
@@ -69,6 +64,10 @@ const MarkdownWrapper = styled.div`
6964
margin-bottom: 0;
7065
}
7166
67+
ul li {
68+
margin-bottom: 1rem;
69+
}
70+
7271
blockquote {
7372
margin-inline-start: 0rem;
7473
padding-inline-start: 1rem;
@@ -116,4 +115,14 @@ const MarkdownWrapper = styled.div`
116115
}
117116
`;
118117

118+
const MarkdownWrapper = styled.div`
119+
width: 100%;
120+
overflow-x: hidden;
121+
img {
122+
max-width: 100%;
123+
}
124+
125+
${markdownStyles}
126+
`;
127+
119128
export default Markdown;

browser/data-browser/src/hooks/useUpload.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import {
22
AtomicError,
3-
properties,
3+
dataBrowser,
44
Resource,
55
useArray,
66
useStore,
@@ -24,7 +24,7 @@ export function useUpload(parentResource: Resource): UseUploadResult {
2424
const [error, setError] = useState<Error | undefined>(undefined);
2525
const [subResources, setSubResources] = useArray(
2626
parentResource,
27-
properties.subResources,
27+
dataBrowser.properties.subResources,
2828
opts,
2929
);
3030

@@ -40,7 +40,7 @@ export function useUpload(parentResource: Resource): UseUploadResult {
4040
const allUploaded = [...netUploaded];
4141
setIsUploading(false);
4242
await setSubResources([...subResources, ...allUploaded]);
43-
await parentResource.save(store);
43+
await parentResource.save();
4444

4545
return allUploaded;
4646
} catch (e) {

browser/data-browser/src/routes/NewResource/NewRoute.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { useResource, urls } from '@tomic/react';
1+
import { useResource, core } from '@tomic/react';
22
import { useCallback } from 'react';
33
import { useNavigate } from 'react-router';
44

@@ -75,9 +75,8 @@ function NewResourceSelector() {
7575
</h1>
7676
<div>
7777
<ResourceSelector
78-
hideCreateOption
7978
setSubject={handleClassSet}
80-
isA={urls.classes.class}
79+
classType={core.classes.class}
8180
/>
8281
</div>
8382
<BaseButtons parent={calculatedParent} />

browser/data-browser/src/routes/SearchRoute.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@ export function Search(): JSX.Element {
141141
<Column ref={resultsDiv} gap='1rem'>
142142
{results.map((subject, index) => (
143143
<ResourceCard
144+
small
144145
initialInView={index < 5}
145146
subject={subject}
146147
key={subject}

browser/data-browser/src/views/Card/CollectionCard.tsx

Lines changed: 22 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ const MAX_COUNT = 5;
1616
* Renders a Resource and all its Properties in a random order. Title
1717
* (shortname) is rendered prominently at the top.
1818
*/
19-
function CollectionCard({ resource, small }: CardViewProps): JSX.Element {
19+
function CollectionCard({ resource }: CardViewProps): JSX.Element {
2020
const [description] = useString(resource, core.properties.description);
2121
const [members] = useArray(resource, collections.properties.members);
2222
const [showAll, setShowMore] = useState(false);
@@ -32,38 +32,32 @@ function CollectionCard({ resource, small }: CardViewProps): JSX.Element {
3232
<Column gap='0.5rem'>
3333
<ResourceCardTitle resource={resource} />
3434
{description && <Markdown text={description} />}
35-
<Show show={!small}>
36-
{subjects.length === 0 ? (
37-
<Empty>No resources</Empty>
38-
) : (
39-
<CardInsideFull>
40-
{subjects.map(member => {
41-
return (
42-
<CardRow key={member}>
43-
<ResourceInline subject={member} />
44-
</CardRow>
45-
);
46-
})}
47-
{tooMany && (
48-
<CardRow>
49-
<Button clean onClick={() => setShowMore(!showAll)}>
50-
{showAll
51-
? 'show less'
52-
: `show ${members.length - MAX_COUNT} more`}
53-
</Button>
35+
{subjects.length === 0 ? (
36+
<Empty>No resources</Empty>
37+
) : (
38+
<CardInsideFull>
39+
{subjects.map(member => {
40+
return (
41+
<CardRow key={member}>
42+
<ResourceInline subject={member} />
5443
</CardRow>
55-
)}
56-
</CardInsideFull>
57-
)}
58-
</Show>
44+
);
45+
})}
46+
{tooMany && (
47+
<CardRow>
48+
<Button clean onClick={() => setShowMore(!showAll)}>
49+
{showAll
50+
? 'show less'
51+
: `show ${members.length - MAX_COUNT} more`}
52+
</Button>
53+
</CardRow>
54+
)}
55+
</CardInsideFull>
56+
)}
5957
</Column>
6058
);
6159
}
6260

63-
const Show: FC<PropsWithChildren<{ show: boolean }>> = ({ show, children }) => {
64-
return show ? children : null;
65-
};
66-
6761
const Empty = styled.span`
6862
color: ${({ theme }) => theme.colors.textLight};
6963
`;

browser/data-browser/src/views/Card/ResourceCard.tsx

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -127,29 +127,30 @@ export function ResourceCardDefault({
127127
<ResourceCardTitle resource={resource}>
128128
<ClassName>{isAResource.title}</ClassName>
129129
</ResourceCardTitle>
130-
<DescriptionWrapper>
130+
<DescriptionWrapper
131+
style={{
132+
maxHeight: small ? '14rem' : 'auto',
133+
}}
134+
>
131135
<ValueForm
132136
resource={resource}
133137
propertyURL={core.properties.description}
134138
/>
135139
</DescriptionWrapper>
136-
{!small && (
137-
<AllProps
138-
basic
139-
resource={resource}
140-
except={defaultHiddenProps}
141-
editable
142-
/>
143-
)}
140+
<AllProps
141+
basic
142+
resource={resource}
143+
except={defaultHiddenProps}
144+
editable
145+
/>
144146
</Column>
145147
);
146148
}
147149

148150
export default ResourceCard;
149151

150152
const DescriptionWrapper = styled.div`
151-
max-height: 10rem;
152-
overflow: hidden;
153+
overflow: auto;
153154
`;
154155

155156
const ClassName = styled.span`

0 commit comments

Comments
 (0)