Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Lexical] Create initial Gallery View with Emoji Plugin Example #28

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 5 additions & 26 deletions packages/lexical-website/docusaurus.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -239,24 +239,6 @@ const config = {
onBrokenMarkdownLinks: 'throw',
organizationName: 'facebook',
plugins: [
process.env.FB_INTERNAL
? null
: [
'./plugins/package-docs',
/** @type {import('./plugins/package-docs').PackageDocsPluginOptions} */
{
baseDir: path.resolve(__dirname, '..'),
editUrl: `${GITHUB_REPO_URL}/tree/main/packages/`,
packageFrontMatter: {
lexical: [
'sidebar_position: 1',
'sidebar_label: lexical (core)',
].join('\n'),
},
targetDir: path.resolve(__dirname, 'docs/packages'),
},
],
'./plugins/webpack-buffer',
['docusaurus-plugin-typedoc', docusaurusPluginTypedocConfig],
async function tailwindcss() {
return {
Expand All @@ -281,7 +263,6 @@ const config = {
docs: {
beforeDefaultRemarkPlugins: [slugifyPlugin],
editUrl: `${GITHUB_REPO_URL}/tree/main/packages/lexical-website/`,
exclude: process.env.FB_INTERNAL ? ['docs/error/**'] : [],
path: 'docs',
sidebarItemsGenerator,
sidebarPath: require.resolve('./sidebars.js'),
Expand Down Expand Up @@ -405,13 +386,11 @@ const config = {
label: 'iOS',
position: 'left',
},
process.env.FB_INTERNAL
? {
label: 'Gallery',
position: 'left',
to: '/gallery',
}
: null,
{
label: 'Gallery',
position: 'left',
to: '/gallery',
},
{
href: GITHUB_REPO_URL,
label: 'GitHub',
Expand Down
4 changes: 4 additions & 0 deletions packages/lexical-website/fb/sdoc-cache.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"snippets": {},
"description": "@generated"
}
48 changes: 48 additions & 0 deletions packages/lexical-website/src/components/Gallery/Card.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
*/

import Link from '@docusaurus/Link';
import Heading from '@theme/Heading';
import clsx from 'clsx';
import React from 'react';

import styles from './styles.module.css';

function getCardImage(item) {
return (
item.preview ??
`https://slorber-api-screenshot.netlify.app/${encodeURIComponent(
item.uri,
)}/showcase`
);
}
Comment on lines +16 to +23
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ensure item.uri is defined before use.

Consider adding a check to ensure item.uri is defined before using it to construct the URL. This will prevent potential errors if item.uri is undefined.

Use this diff to add a check:

  return (
    item.preview ??
+   (item.uri &&
      `https://slorber-api-screenshot.netlify.app/${encodeURIComponent(
        item.uri,
      )}/showcase`)
  );
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
function getCardImage(item) {
return (
item.preview ??
`https://slorber-api-screenshot.netlify.app/${encodeURIComponent(
item.uri,
)}/showcase`
);
}
function getCardImage(item) {
return (
item.preview ??
(item.uri &&
`https://slorber-api-screenshot.netlify.app/${encodeURIComponent(
item.uri,
)}/showcase`)
);
}


function Card({item}) {
const image = getCardImage(item);
return (
<li key={item.title} className="card shadow--md">
<a href={item.uri} target="_blank">
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

category Functionality

The external link in the Card component is missing important attributes for security and accessibility. When opening links in a new tab (target="_blank"), it's recommended to add rel="noopener noreferrer" to prevent potential security vulnerabilities. Additionally, consider adding an aria-label to the link for better accessibility, especially since it only contains an image.

Chat with Korbit by mentioning @korbit-ai, and give a 👍 or 👎 to help Korbit improve your reviews.

<div className={clsx('card__image', styles.showcaseCardImage)}>
<img src={image} alt={item.title} />
</div>
</a>
<div className="card__body">
<div className={clsx(styles.showcaseCardHeader)}>
<Heading as="h4" className={styles.showcaseCardTitle}>
<Link href={item.website} className={styles.showcaseCardLink}>
{item.title}
</Link>
</Heading>
</div>
<p className={styles.showcaseCardBody}>{item.description}</p>
</div>
</li>
);
Comment on lines +25 to +45
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

category Functionality

I noticed that the Card component doesn't handle cases where some properties of the item object might be missing. This could lead to errors if, for example, item.uri or item.website are undefined. Consider adding checks for these properties and providing fallback values. For instance, you could use the optional chaining operator (?.) and nullish coalescing operator (??) to safely access these properties and provide default values.

Chat with Korbit by mentioning @korbit-ai, and give a 👍 or 👎 to help Korbit improve your reviews.

}

export default React.memo(Card);
38 changes: 38 additions & 0 deletions packages/lexical-website/src/components/Gallery/GalleryCards.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
*/

import useDocusaurusContext from '@docusaurus/useDocusaurusContext';
import clsx from 'clsx';

import Card from './Card';
import {plugins} from './pluginList';
import styles from './styles.module.css';

function CardList({cards}) {
return (
<div className="container">
<ul className={clsx('clean-list', styles.cardList)}>
{cards.map((item) => (
<Card key={item.title} item={item} />
))}
</ul>
</div>
);
}
Comment on lines +16 to +26
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

category Functionality

In the CardList component, it's important to add error handling for the 'cards' prop. Currently, if 'cards' is undefined or not an array, the component will throw an error when trying to map over it. Consider adding a check to ensure 'cards' is defined and is an array before mapping, and provide a fallback UI if it's not. This will improve the robustness of the component and prevent potential runtime errors.

Chat with Korbit by mentioning @korbit-ai, and give a 👍 or 👎 to help Korbit improve your reviews.


export default function GalleryCards() {
const {
siteConfig: {customFields},
} = useDocusaurusContext();

return (
<section className="margin-top--lg margin-bottom--xl">
<CardList cards={plugins(customFields)} />
</section>
);
}
17 changes: 17 additions & 0 deletions packages/lexical-website/src/components/Gallery/GalleryPage.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
*/

import GalleryCards from './GalleryCards';

export default function GalleryPage() {
return (
<main className="margin-vert--lg">
<GalleryCards />
</main>
);
}
Comment on lines +11 to +17
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

category Functionality

The GalleryPage component currently lacks a title or heading. Consider adding an <h1> or <h2> element with an appropriate title (e.g., 'Plugin Gallery') before the <GalleryCards /> component. This will improve the page structure and provide better context for users.

Chat with Korbit by mentioning @korbit-ai, and give a 👍 or 👎 to help Korbit improve your reviews.

14 changes: 14 additions & 0 deletions packages/lexical-website/src/components/Gallery/pluginList.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
*/

export const plugins = (customFields) => [
{
title: 'EmojiPlugin',
uri: `${customFields.STACKBLITZ_PREFIX}examples/vanilla-js-plugin?embed=1&file=src%2Femoji-plugin%2FEmojiPlugin.ts&terminalHeight=0&ctl=1`,
},
];
Comment on lines +9 to +14
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

category Functionality

The plugins function assumes that customFields.STACKBLITZ_PREFIX is always defined, which may not be the case. To improve robustness, consider adding a check for the existence of customFields and STACKBLITZ_PREFIX, or provide a default value. For example:

export const plugins = (customFields = {}) => [
  {
    title: 'EmojiPlugin',
    uri: `${customFields.STACKBLITZ_PREFIX || ''}examples/vanilla-js-plugin?embed=1&file=src%2Femoji-plugin%2FEmojiPlugin.ts&terminalHeight=0&ctl=1`,
  },
];

This change will prevent potential runtime errors if customFields or STACKBLITZ_PREFIX is undefined.

Chat with Korbit by mentioning @korbit-ai, and give a 👍 or 👎 to help Korbit improve your reviews.

68 changes: 68 additions & 0 deletions packages/lexical-website/src/components/Gallery/styles.module.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

.cardList {
display: grid;
grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
gap: 24px;
}

.showcaseFavorite {
padding-top: 2rem;
padding-bottom: 2rem;
background-color: #f6fdfd;
}

html[data-theme='dark'] .showcaseFavorite {
background-color: #232525;
}

.headingFavorites {
display: flex;
align-items: center;
}

.showcaseCardImage {
overflow: hidden;
height: 150px;
border-bottom: 2px solid var(--ifm-color-emphasis-200);
}

.showcaseCardHeader {
display: flex;
align-items: center;
margin-bottom: 12px;
}

.showcaseCardTitle {
margin-bottom: 0;
flex: 1 1 auto;
}

.showcaseCardTitle a {
text-decoration: none;
background: linear-gradient(
var(--ifm-color-primary),
var(--ifm-color-primary)
)
0% 100% / 0% 1px no-repeat;
transition: background-size ease-out 200ms;
}

.showcaseCardTitle a:not(:focus):hover {
background-size: 100% 1px;
}

.showcaseCardTitle,
.showcaseCardHeader {
margin-right: 0.25rem;
}

.showcaseCardBody {
font-size: smaller;
line-height: 1.66;
}
29 changes: 0 additions & 29 deletions packages/lexical-website/src/components/GalleryPage.js

This file was deleted.

4 changes: 2 additions & 2 deletions packages/lexical-website/src/pages/gallery.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ id: gallery
title: Gallery
---
import { FBInternOnly } from 'docusaurus-plugin-internaldocs-fb/internal';
import GalleryPage from '@site/src/components/GalleryPage';
import GalleryPage from '@site/src/components/Gallery/GalleryPage';

# Gallery (WIP)
# Gallery
<GalleryPage/>