Skip to content

Commit

Permalink
chore(strapi): upgraded strapi support for v5
Browse files Browse the repository at this point in the history
* Updated [project structure for v5 support](https://docs.strapi.io/dev-docs/plugins/development/plugin-structure)
* Updated admin interface to utilize new design system and deprecate helper plugin
  • Loading branch information
johnmgrant committed Oct 5, 2024
1 parent 9206a8b commit 771b760
Show file tree
Hide file tree
Showing 37 changed files with 4,869 additions and 6,386 deletions.
143 changes: 135 additions & 8 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,11 +1,138 @@
# Don't check auto-generated stuff into git
coverage
node_modules
stats.json
package-lock.json
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.

############################
# OS X
############################

# Cruft
.DS_Store
npm-debug.log
.AppleDouble
.LSOverride
Icon
.Spotlight-V100
.Trashes
._*


############################
# Linux
############################

*~


############################
# Windows
############################

Thumbs.db
ehthumbs.db
Desktop.ini
$RECYCLE.BIN/
*.cab
*.msi
*.msm
*.msp


############################
# Packages
############################

*.7z
*.csv
*.dat
*.dmg
*.gz
*.iso
*.jar
*.rar
*.tar
*.zip
*.com
*.class
*.dll
*.exe
*.o
*.seed
*.so
*.swo
*.swp
*.swn
*.swm
*.out
*.pid


############################
# Logs and databases
############################

.tmp
*.log
*.sql
*.sqlite
*.sqlite3


############################
# Misc.
############################

*#
ssl
.idea
dist/
nbproject
.tsbuildinfo
.eslintcache
.env


############################
# Strapi
############################

public/uploads/*
!public/uploads/.gitkeep


############################
# Build
############################

dist
build


############################
# Node.js
############################

lib-cov
lcov.info
pids
logs
results
node_modules
.node_history


############################
# Package managers
############################

.yarn/*
!.yarn/cache
!.yarn/unplugged
!.yarn/patches
!.yarn/releases
!.yarn/sdks
!.yarn/versions
.pnp.*
yarn-error.log


############################
# Tests
############################

coverage
2 changes: 2 additions & 0 deletions admin/custom.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
declare module '@strapi/design-system/*';
declare module '@strapi/design-system';
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*/

import { useEffect, useRef } from 'react';
import pluginId from '../../pluginId';
import pluginId from '../pluginId';

type InitializerProps = {
setPlugin: (id: string) => void;
Expand All @@ -21,4 +21,4 @@ const Initializer = ({ setPlugin }: InitializerProps) => {
return null;
};

export default Initializer;
export {Initializer};
61 changes: 61 additions & 0 deletions admin/src/components/MediaLib.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import {FC as FunctionComponent} from 'react';

import {useStrapiApp} from '@strapi/admin/strapi-admin';
import type {Schema} from '@strapi/types';


const prefixFileUrlWithBackendUrl = (fileURL: string) => {
return !!fileURL &&
fileURL.startsWith('/') &&
'strapi' in window &&
window.strapi instanceof Object &&
'backendURL' in window.strapi &&
window.strapi.backendURL ?
`${window.strapi.backendURL}${fileURL}` :
fileURL;
};

interface MediaLibComponentProps {
isOpen: boolean,
onChange: (files: Schema.Attribute.MediaValue<true>) => void,
onToggle: () => void,
}

const MediaLib: FunctionComponent<MediaLibComponentProps> = ({
isOpen,
onChange,
onToggle,
}) => {
const components = useStrapiApp('ImageDialog', (state) => state.components);
if (!components || !isOpen) return null;

const MediaLibraryDialog = components['media-library'] as FunctionComponent<{
onClose: () => void,
onSelectAssets: (_images: Schema.Attribute.MediaValue<true>) => void,
}>;

const handleSelectAssets = (files: Schema.Attribute.MediaValue<true>) => {
const formattedFiles = files.map((f) => ({
alt: f.alternativeText || f.name,
url: prefixFileUrlWithBackendUrl(f.url),
mime: f.mime,
}));

onChange(formattedFiles);
};

return (
<MediaLibraryDialog
onClose={onToggle}
onSelectAssets={handleSelectAssets}
/>
);
};

MediaLib.defaultProps = {
isOpen: false,
onChange: (_files: Schema.Attribute.MediaValue<true>) => {},
onToggle: () => {},
};

export {MediaLib};
43 changes: 0 additions & 43 deletions admin/src/components/MediaLib/index.tsx

This file was deleted.

Loading

0 comments on commit 771b760

Please sign in to comment.