Skip to content

Commit

Permalink
[WIP] Change Unsplash selector to use Lib
Browse files Browse the repository at this point in the history
no issue
  • Loading branch information
ronaldlangeveld committed Mar 12, 2024
1 parent 5c6267f commit ccc3a33
Show file tree
Hide file tree
Showing 9 changed files with 25 additions and 187 deletions.
4 changes: 1 addition & 3 deletions packages/kg-unsplash-selector/src/UnsplashSearchModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ interface UnsplashModalProps {
unsplashProviderConfig: DefaultHeaderTypes | null;
}

const UnsplashSearchModal : React.FC<UnsplashModalProps> = ({onClose, onImageInsert, unsplashProviderConfig}) => {
export const UnsplashSearchModal : React.FC<UnsplashModalProps> = ({onClose, onImageInsert, unsplashProviderConfig}) => {
const unsplashProvider = useMemo(() => {
if (!unsplashProviderConfig) {
return new InMemoryUnsplashProvider();
Expand Down Expand Up @@ -191,5 +191,3 @@ const UnsplashSearchModal : React.FC<UnsplashModalProps> = ({onClose, onImageIns
</UnsplashSelector>
);
};

export default UnsplashSearchModal;
4 changes: 2 additions & 2 deletions packages/kg-unsplash-selector/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export {default as UnsplashSearchModal} from './UnsplashSearchModal';
export {UnsplashSearchModal} from './UnsplashSearchModal';
export type {DefaultHeaderTypes, Photo as PhotoType} from './UnsplashTypes';
export {UnsplashProvider} from './api/UnsplashProvider';
import './styles/index.css';
import './styles/index.css';
2 changes: 1 addition & 1 deletion packages/koenig-lexical/demo/DemoApp.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ const WEBSOCKET_ENDPOINT = params.get('multiplayerEndpoint') || 'ws://localhost:
const WEBSOCKET_ID = params.get('multiplayerId') || '0';

const cardConfig = {
unsplash: {defaultHeaders: defaultUnsplashHeaders},
unsplash: defaultUnsplashHeaders,
fetchEmbed: fetchEmbed,
tenor: tenorConfig,
fetchAutocompleteLinks: () => Promise.resolve([
Expand Down
1 change: 1 addition & 0 deletions packages/koenig-lexical/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@
"@tryghost/kg-default-transforms": "^1.0.10",
"@tryghost/kg-markdown-html-renderer": "^7.0.2",
"@tryghost/kg-simplemde": "^3.0.1",
"@tryghost/kg-unsplash-selector": "0.1.8",
"@types/react": "18.2.48",
"@types/react-dom": "18.2.18",
"@uiw/react-codemirror": "^4.19.6",
Expand Down
177 changes: 0 additions & 177 deletions packages/koenig-lexical/src/components/ui/UnsplashModal.jsx

This file was deleted.

3 changes: 1 addition & 2 deletions packages/koenig-lexical/src/components/ui/UnsplashPlugin.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import KoenigComposerContext from '../../context/KoenigComposerContext.jsx';
import React from 'react';
import UnsplashModal from './UnsplashModal.jsx';
import UnsplashModal from './file-selectors/UnsplashModal.jsx';
import generateEditorState from '../../utils/generateEditorState';
import {$createNodeSelection, $getNodeByKey, $setSelection} from 'lexical';
import {useLexicalComposerContext} from '@lexical/react/LexicalComposerContext';
Expand All @@ -11,7 +11,6 @@ const UnsplashPlugin = ({nodeKey, isModalOpen = true}) => {
const [isOpen, setIsOpen] = React.useState(isModalOpen);

const onClose = () => {
// remove the image node from the editor
if (nodeKey) {
editor.update(() => {
const node = $getNodeByKey(nodeKey);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import MarkdownHelpDialog from './MarkdownHelpDialog';
import MarkdownImageUploader from './MarkdownImageUploader';
import React, {useLayoutEffect, useRef, useState} from 'react';
import SimpleMDE from '@tryghost/kg-simplemde';
import UnsplashModal from '../../UnsplashModal';
import UnsplashModal from '../../file-selectors/UnsplashModal';

import ctrlOrCmd from '../../../../utils/ctrlOrCmd';
import useMarkdownImageUploader from './useMarkdownImageUploader';
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import Portal from '../Portal';
import {UnsplashSearchModal} from '@tryghost/kg-unsplash-selector';

const UnsplashModal = ({unsplashConf, onImageInsert, onClose}) => {
return (
<Portal>
<UnsplashSearchModal
unsplashProviderConfig={unsplashConf}
onClose={onClose}
onImageInsert={onImageInsert}
/>
</Portal>
);
};

export default UnsplashModal;
3 changes: 2 additions & 1 deletion packages/koenig-lexical/vite.config.demo.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ export default (function viteDemoConfig() {
'@tryghost/kg-clean-basic-html',
'@tryghost/kg-default-transforms',
'@tryghost/kg-markdown-html-renderer',
'@tryghost/kg-simplemde'
'@tryghost/kg-simplemde',
'@tryghost/kg-unsplash-selector'
]
},
build: {
Expand Down

0 comments on commit ccc3a33

Please sign in to comment.