Skip to content

Commit

Permalink
First working version, using the kb from #6050
Browse files Browse the repository at this point in the history
  • Loading branch information
sneridagh committed Dec 16, 2024
1 parent 81632ac commit 4a6db26
Show file tree
Hide file tree
Showing 13 changed files with 51 additions and 60 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ eslint.xml
yarn-error.log
build
.changelog.draft
.registry.loader.js

# yarn 3
.pnp.*
Expand Down
2 changes: 1 addition & 1 deletion packages/volto/.eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
"rootPathSuffix": "src",
},
},
"import/core-modules": ["load-volto-addons"],
"import/core-modules": ["@plone/registry/addons-loader"],
"react": {
"version": "detect",
},
Expand Down
2 changes: 1 addition & 1 deletion packages/volto/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@
"~/config": "<rootDir>/src/config",
"~/../locales/${lang}.json": "<rootDir>/locales/en.json",
"(.*)/locales/(.*)": "<rootDir>/locales/$2",
"load-volto-addons": "<rootDir>/jest-addons-loader.js",
"@plone/registry/addons-loader": "<rootDir>/jest-addons-loader.js",
"@package/(.*)$": "<rootDir>/src/$1",
"@root/config": "<rootDir>/jest-addons-loader.js",
"@root/(.*)$": "<rootDir>/src/$1",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {
URLUtils,
} from '@plone/volto/helpers/Url/Url';

import doesNodeContainClick from '@plone/volto/helpers/Utils/doesNodeContainClick/doesNodeContainClick';
import doesNodeContainClick from '@plone/volto/helpers/Utils/doesNodeContainClick';
import { Input, Form, Button } from 'semantic-ui-react';
import { defineMessages, injectIntl } from 'react-intl';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react';
import doesNodeContainClick from '@plone/volto/helpers/Utils/doesNodeContainClick/doesNodeContainClick';
import doesNodeContainClick from '@plone/volto/helpers/Utils/doesNodeContainClick';
import addSVG from '@plone/volto/icons/circle-plus.svg';
import { blockHasValue } from '@plone/volto/helpers/Blocks/Blocks';
import Icon from '@plone/volto/components/theme/Icon/Icon';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React from 'react';
import { createPortal } from 'react-dom';
import { CSSTransition } from 'react-transition-group';
import PropTypes from 'prop-types';
import doesNodeContainClick from '@plone/volto/helpers/Utils/doesNodeContainClick/doesNodeContainClick';
import doesNodeContainClick from '@plone/volto/helpers/Utils/doesNodeContainClick';

const DEFAULT_TIMEOUT = 500;

Expand Down
2 changes: 1 addition & 1 deletion packages/volto/src/components/manage/Toolbar/Toolbar.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { Link } from 'react-router-dom';
import jwtDecode from 'jwt-decode';
import { connect } from 'react-redux';
import { compose } from 'redux';
import doesNodeContainClick from '@plone/volto/helpers/Utils/doesNodeContainClick/doesNodeContainClick';
import doesNodeContainClick from '@plone/volto/helpers/Utils/doesNodeContainClick';
import { withCookies } from 'react-cookie';
import filter from 'lodash/filter';
import find from 'lodash/find';
Expand Down
3 changes: 2 additions & 1 deletion packages/volto/src/components/theme/App/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ import clearSVG from '@plone/volto/icons/clear.svg';
import MultilingualRedirector from '@plone/volto/components/theme/MultilingualRedirector/MultilingualRedirector';
import WorkingCopyToastsFactory from '@plone/volto/components/manage/WorkingCopyToastsFactory/WorkingCopyToastsFactory';
import LockingToastsFactory from '@plone/volto/components/manage/LockingToastsFactory/LockingToastsFactory';
// TODO: RouteAnnouncer fails with hydation error?
import RouteAnnouncer from '@plone/volto/components/theme/RouteAnnouncer/RouteAnnouncer';

/**
Expand Down Expand Up @@ -185,7 +186,7 @@ export class App extends Component {
</main>
</Segment>
</MultilingualRedirector>
<RouteAnnouncer />
{/* <RouteAnnouncer /> */}
<Footer />
<LockingToastsFactory
content={this.props.content}
Expand Down
4 changes: 3 additions & 1 deletion packages/volto/src/config/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ import {
unwantedControlPanelsFields,
} from './ControlPanels';

import applyAddonConfiguration, { addonsInfo } from 'load-volto-addons';
import applyAddonConfiguration, {
addonsInfo,
} from '@plone/registry/addons-loader';

import { installDefaultComponents } from './Components';
import { installDefaultWidgets } from './Widgets';
Expand Down
7 changes: 5 additions & 2 deletions packages/volto/src/constants/Languages.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* @module constants/Languages
*/

module.exports = {
const languages = {
ca: 'Català',
de: 'Deutsch',
en: 'English',
Expand All @@ -21,4 +21,7 @@ module.exports = {
zh_CN: '中文',
};

// export default languages;
// module.exports = languages;
// module.exports = { default: languages };
// TODO: For some reason loading cjs from ESM fails, and this has to export default as ESM :/
export default languages;
2 changes: 1 addition & 1 deletion packages/volto/src/helpers/Utils/useDetectClickOutside.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useCallback, useEffect, useRef } from 'react';
import doesNodeContainClick from '@plone/volto/helpers/Utils/doesNodeContainClick/doesNodeContainClick';
import doesNodeContainClick from '@plone/volto/helpers/Utils/doesNodeContainClick';

/**
* Hook used to detect clicks outside a component (or an escape key press).
Expand Down
61 changes: 14 additions & 47 deletions packages/volto/vite-plugins/volto.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,42 +2,26 @@ import fs from 'fs';
import path from 'path';
import fixReactVirtualized from 'esbuild-plugin-react-virtualized';
import { svgLoader } from './svg';

import AddonConfigurationRegistry from '@plone/registry/src/addon-registry';
import createAddonsLoader from '@plone/registry/src/create-addons-loader';
import createThemeAddonsLoader from '@plone/registry/src/create-theme-addons-loader';
import { PloneRegistryVitePlugin } from '@plone/registry/vite-plugin';
import { AddonRegistry } from '@plone/registry/addon-registry';
import { poToJson } from '@plone/scripts/i18n.cjs';

export const VoltoVitePlugin = () => {
const projectRootPath = path.resolve('.');
const registry = new AddonConfigurationRegistry(projectRootPath);
console.log(
registry,
// registry.getAddonsFromEnvVarCustomizationPaths(),
registry.getResolveAliases('vite'),
registry.getAddonCustomizationPaths('vite'),
// registry.getAddonsFromEnvVarCustomizationPaths(),
);
const addonsLoaderPath = createAddonsLoader(
registry.getAddonDependencies(),
registry.getAddons(),
);
const { registry } = AddonRegistry.init(projectRootPath);

const [addonsThemeLoaderVariablesPath, addonsThemeLoaderMainPath] =
createThemeAddonsLoader(registry.getCustomThemeAddons());
// Compile language JSON files from po files
// TODO: make a vite plugin for it
poToJson({ registry, addonMode: false });

// TODO: improve later
let themeConfigPath, themePath;
if (registry.theme) {
// The themes should be located in `src/theme`
themePath = registry.packages[registry.theme].modulePath;
themeConfigPath = `${themePath}/theme/theme.config`;
}

const addOns = Object.keys(registry.packages);

// Compile language JSON files from po files
poToJson({ registry, addonMode: false });

return [
svgLoader({
svgoConfig: {
Expand All @@ -56,15 +40,13 @@ export const VoltoVitePlugin = () => {
],
},
}),
PloneRegistryVitePlugin(),
{
name: 'volto',
enforce: 'pre',
config: () => ({
envPrefix: 'VOLTO_',
envPrefix: 'PLONE_',
ssr: {
optimizeDeps: {
exclude: addOns,
},
// external: ['lodash', 'semantic-ui-react'],
noExternal: ['use-deep-compare-effect'],
},
Expand All @@ -74,17 +56,13 @@ export const VoltoVitePlugin = () => {
},
},
optimizeDeps: {
exclude: addOns,
esbuildOptions: {
plugins: [fixReactVirtualized],
},
},
resolve: {
alias: [
{ find: /^~/, replacement: '' },
...registry.getAddonCustomizationPaths('vite'),
...registry.getAddonsFromEnvVarCustomizationPaths('vite'),
...registry.getResolveAliases('vite'),
{
find: '@plone/volto/config',
replacement: path.resolve(__dirname, '../src/config'),
Expand All @@ -104,17 +82,7 @@ export const VoltoVitePlugin = () => {
},
...(registry.theme
? // Load the theme config from the theme
[
{ find: '../../theme.config', replacement: themeConfigPath },
{
find: 'addonsThemeCustomizationsVariables',
replacement: addonsThemeLoaderVariablesPath,
},
{
find: 'addonsThemeCustomizationsMain',
replacement: addonsThemeLoaderMainPath,
},
]
[{ find: '../../theme.config', replacement: themeConfigPath }]
: // Load the theme config from SemanticUI
[
{
Expand All @@ -125,16 +93,15 @@ export const VoltoVitePlugin = () => {
),
},
]),
{ find: 'load-volto-addons', replacement: addonsLoaderPath },
{
find: 'volto-themes',
replacement: path.resolve(__dirname, '../theme/themes'),
},
// This is needed to make lodash work with Vite as lodash-es is full ESM
{
find: 'lodash',
replacement: 'lodash-es',
},
// {
// find: 'lodash',
// replacement: 'lodash-es',
// },
],
},
}),
Expand Down
21 changes: 19 additions & 2 deletions packages/volto/vite.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,31 @@ import react from '@vitejs/plugin-react';
import { nodePolyfills } from 'vite-plugin-node-polyfills';
import { VoltoVitePlugin } from './vite-plugins/volto';

// TODO: improve deployment settings
const prodServerName =
process.env.PLONE_API_PATH && process.env.PLONE_API_PATH.startsWith('https')
? process.env.PLONE_API_PATH
: '';

// https://vitejs.dev/config/
export default defineConfig({
plugins: [VoltoVitePlugin(), nodePolyfills(), react()],
server: {
port: 3000,
proxy: {
'/++api++/':
'http://localhost:8080/VirtualHostBase/http/localhost:3000/Plone/++api++/VirtualHostRoot',
'^/\\+\\+api\\+\\+($$|/.*)': {
target: prodServerName
? prodServerName
: 'http://localhost:8080/VirtualHostBase/http/localhost:3000/Plone/++api++/VirtualHostRoot',
...(prodServerName && {
changeOrigin: true,
secure: false,
}),
rewrite: (path) => {
console.log(path);
return path.replace('/++api++', '');
},
},
},
},
define: {
Expand Down

0 comments on commit 4a6db26

Please sign in to comment.