Skip to content
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
536 changes: 536 additions & 0 deletions packages/lexical-playground/__tests__/e2e/Attachments.spec.mjs

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
cSample attachment content for testing.
5 changes: 4 additions & 1 deletion packages/lexical-playground/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import {type JSX, useMemo} from 'react';

import {isDevPlayground} from './appSettings';
import {buildHTMLConfig} from './buildHTMLConfig';
import {AttachmentStoreProvider} from './context/AttachmentStoreContext';
import {FlashMessageContext} from './context/FlashMessageContext';
import {SettingsContext, useSettings} from './context/SettingsContext';
import {SharedHistoryContext} from './context/SharedHistoryContext';
Expand Down Expand Up @@ -176,7 +177,9 @@ export default function PlaygroundApp(): JSX.Element {
return (
<SettingsContext>
<FlashMessageContext>
<App />
<AttachmentStoreProvider>
<App />
</AttachmentStoreProvider>
</FlashMessageContext>
<a
href="https://github.com/facebook/lexical/tree/main/packages/lexical-playground"
Expand Down
2 changes: 2 additions & 0 deletions packages/lexical-playground/src/Editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import {
import {useSettings} from './context/SettingsContext';
import {useSharedHistoryContext} from './context/SharedHistoryContext';
import ActionsPlugin from './plugins/ActionsPlugin';
import AttachmentPlugin from './plugins/AttachmentPlugin';
import AutocompletePlugin from './plugins/AutocompletePlugin';
import AutoEmbedPlugin from './plugins/AutoEmbedPlugin';
import AutoLinkPlugin from './plugins/AutoLinkPlugin';
Expand Down Expand Up @@ -249,6 +250,7 @@ export default function Editor(): JSX.Element {
<TableCellResizer />
<TableScrollShadowPlugin />
<ImagesPlugin />
<AttachmentPlugin />
<LinkPlugin hasLinkAttributes={hasLinkAttributes} />
<PollPlugin />
<TwitterPlugin />
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/**
* 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 type {AttachmentStore} from '../stores/AttachmentStore';
import type {JSX, ReactNode} from 'react';

import {createContext, useContext, useEffect, useMemo} from 'react';

import {DemoAttachmentStore} from '../stores/DemoAttachmentStore';

export interface AttachmentStoreContextValue {
store: AttachmentStore;
/** Flag to show UI warning about demo mode limitations */
showDemoWarning: boolean;
}

const Context = createContext<AttachmentStoreContextValue | null>(null);

interface AttachmentStoreProviderProps {
children: ReactNode;
/** Custom store implementation. Defaults to DemoAttachmentStore */
store?: AttachmentStore;
}

export function AttachmentStoreProvider({
children,
store,
}: AttachmentStoreProviderProps): JSX.Element {
const contextValue = useMemo(() => {
const resolvedStore = store ?? new DemoAttachmentStore();
return {
showDemoWarning:
!resolvedStore.isPersistent() &&
resolvedStore.getConfig().demoWarningLevel === 'ui',
store: resolvedStore,
};
}, [store]);

// Cleanup on unmount
useEffect(() => {
return () => {
const currentStore = contextValue.store;
if (currentStore instanceof DemoAttachmentStore) {
currentStore.cleanup();
}
};
}, [contextValue.store]);

return <Context.Provider value={contextValue}>{children}</Context.Provider>;
}

export function useAttachmentStore(): AttachmentStoreContextValue {
const ctx = useContext(Context);
if (!ctx) {
throw new Error(
'useAttachmentStore must be used within AttachmentStoreProvider',
);
}
return ctx;
}
3 changes: 3 additions & 0 deletions packages/lexical-playground/src/images/icons/paperclip.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions packages/lexical-playground/src/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -621,6 +621,11 @@ i.page-break,
background-image: url(images/icons/scissors.svg);
}

i.attachment,
.icon.attachment {
background-image: url(images/icons/paperclip.svg);
}

.link-editor .button.active,
.toolbar .button.active {
background-color: rgb(223, 232, 250);
Expand Down
Loading
Loading