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

Removed all imports from barrel files for components, actions, helpers, hooks and lodash #6509

Merged
merged 14 commits into from
Dec 8, 2024
Merged
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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ packages/volto-guillotina
dist
packages/registry/lib
packages/registry/docs
apps/rr7/.react-router
9 changes: 8 additions & 1 deletion docs/source/upgrade-guide/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -723,11 +723,18 @@ Modern bundlers, such as Vite, rely upon the import path to determine whether to

The barrel imports must be removed to increase the natural number of chunks that Volto divides on—especially on routes—resulting in code splitting done the right and natural way.
This forces us to rewrite all the imports everywhere—including core, projects, and add-ons—once we implement it.
The barrel imports files include the following.
The barrel imports files include the following in Volto.

- {file}`src/components/index.js`
- {file}`src/helpers/index.js`
- {file}`src/actions/index.js`
- {file}`src/hooks/index.js`

They also include the following in the `@plone/volto-slate` package.

- {file}`src/actions/index.js`
- {file}`src/editor/ui/index.js`
- {file}`src/utils/index.js`

##### Alternative

Expand Down
4 changes: 2 additions & 2 deletions packages/coresandbox/src/components/Blocks/FormBlock/Edit.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { SidebarPortal } from '@plone/volto/components';
import SidebarPortal from '@plone/volto/components/manage/Sidebar/SidebarPortal';
import Data from './Data';
import type { BlockEditProps } from '@plone/types';
import { Helmet } from '@plone/volto/helpers';
import { Helmet } from '@plone/volto/helpers/Helmet/Helmet';

import { defineMessages, useIntl } from 'react-intl';
import { Container } from 'semantic-ui-react';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import React, { useEffect } from 'react';
import { SidebarPortal } from '@plone/volto/components';
import SidebarPortal from '@plone/volto/components/manage/Sidebar/SidebarPortal';
import Data from './Data';
import type { BlockEditProps } from '@plone/types';
import { Input, Button } from 'semantic-ui-react';
import { Icon } from '@plone/volto/components';
import Icon from '@plone/volto/components/theme/Icon/Icon';
import aheadSVG from '@plone/volto/icons/ahead.svg';

const InputBlockEdit = (props: BlockEditProps) => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { SidebarPortal } from '@plone/volto/components';
import SidebarPortal from '@plone/volto/components/manage/Sidebar/SidebarPortal';
import Data from './Data';
import type { BlockEditProps } from '@plone/types';

Expand Down
2 changes: 1 addition & 1 deletion packages/coresandbox/src/components/TestForm.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react';
import { Helmet } from '@plone/volto/helpers';
import { Helmet } from '@plone/volto/helpers/Helmet/Helmet';

import { defineMessages, useIntl } from 'react-intl';
import { Container } from 'semantic-ui-react';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useEffect } from 'react';
import { searchContent } from '@plone/volto/actions';
import { searchContent } from '@plone/volto/actions/search/search';
import { useDispatch, useSelector } from 'react-redux';
import { Container } from 'semantic-ui-react';

Expand Down
6 changes: 3 additions & 3 deletions packages/coresandbox/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import TestBlockView from './components/Blocks/TestBlock/View';
import TestBlockEdit from './components/Blocks/TestBlock/Edit';
import InputBlockView from './components/Blocks/InputBlock/View';
import InputBlockEdit from './components/Blocks/InputBlock/Edit';
import { flattenToAppURL } from '@plone/volto/helpers';
import { flattenToAppURL } from '@plone/volto/helpers/Url/Url';
import { SliderSchema as TestBlockSchema } from './components/Blocks/TestBlock/schema';
import { inputBlockSchema } from './components/Blocks/InputBlock/schema';
import { multipleFieldsetsSchema } from './components/Blocks/TestBlock/schema';
Expand All @@ -13,13 +13,13 @@ import codeSVG from '@plone/volto/icons/code.svg';
import type { BlockConfigBase } from '@plone/types';
import type { ConfigType } from '@plone/registry';
import SlotComponentTest from './components/Slots/SlotTest';
import { ContentTypeCondition } from '@plone/volto/helpers';
import { ContentTypeCondition } from '@plone/volto/helpers/Slots';
import { RouteCondition } from '@plone/volto/helpers/Slots';
import TestForm from './components/TestForm';
import FormBlockView from './components/Blocks/FormBlock/View';
import FormBlockEdit from './components/Blocks/FormBlock/Edit';
import { formBlockSchema } from './components/Blocks/FormBlock/schema';
import { Login } from '@plone/volto/components';
import Login from '@plone/volto/components/theme/Login/Login';

const testBlock: BlockConfigBase = {
id: 'testBlock',
Expand Down
7 changes: 7 additions & 0 deletions packages/volto-slate/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,11 @@ module.exports = {
rules: {
'import/no-unresolved': 0,
},
settings: {
'import/resolver': {
alias: {
map: [['@plone/volto-slate', './src']],
},
},
},
};
1 change: 1 addition & 0 deletions packages/volto-slate/news/6509.internal
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Removed all imports from barrel files for components, actions, helpers, hooks and lodash. @pnicolli
2 changes: 1 addition & 1 deletion packages/volto-slate/src/actions/content.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { nestContent } from '@plone/volto/helpers';
import { nestContent } from '@plone/volto/helpers/Content/Content';
import { UPLOAD_CONTENT } from '@plone/volto-slate/constants';

// TODO: the PR has been merged into Volto, so this should be cleaned up
Expand Down
7 changes: 5 additions & 2 deletions packages/volto-slate/src/blocks/Table/TableBlockEdit.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,16 @@

import React, { Component } from 'react';
import PropTypes from 'prop-types';
import { isEmpty, map, remove } from 'lodash';
import isEmpty from 'lodash/isEmpty';
import map from 'lodash/map';
import remove from 'lodash/remove';
import { Button, Table } from 'semantic-ui-react';
import cx from 'classnames';
import { defineMessages, injectIntl } from 'react-intl';

import Cell from './Cell';
import { Icon, SidebarPortal } from '@plone/volto/components';
import Icon from '@plone/volto/components/theme/Icon/Icon';
import SidebarPortal from '@plone/volto/components/manage/Sidebar/SidebarPortal';
import { BlockDataForm } from '@plone/volto/components/manage/Form';
import TableSchema from './schema';

Expand Down
2 changes: 1 addition & 1 deletion packages/volto-slate/src/blocks/Table/TableBlockView.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import React, { useState, useMemo } from 'react';
import PropTypes from 'prop-types';
import { Table } from 'semantic-ui-react';
import { map } from 'lodash';
import map from 'lodash/map';
import {
serializeNodes,
serializeNodesToText,
Expand Down
14 changes: 6 additions & 8 deletions packages/volto-slate/src/blocks/Text/DefaultTextBlockEditor.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,20 @@ import { defineMessages, useIntl } from 'react-intl';
import { useInView } from 'react-intersection-observer';
import { Dimmer, Loader, Message, Segment } from 'semantic-ui-react';

import {
flattenToAppURL,
getBaseUrl,
validateFileUploadSize,
} from '@plone/volto/helpers';
import { flattenToAppURL, getBaseUrl } from '@plone/volto/helpers/Url/Url';
import { validateFileUploadSize } from '@plone/volto/helpers/FormValidation/FormValidation';
import config from '@plone/volto/registry';
import { SidebarPortal, BlockChooserButton } from '@plone/volto/components';
import SidebarPortal from '@plone/volto/components/manage/Sidebar/SidebarPortal';
import BlockChooserButton from '@plone/volto/components/manage/BlockChooser/BlockChooserButton';
import { BlockDataForm } from '@plone/volto/components/manage/Form';

import { SlateEditor } from '@plone/volto-slate/editor';
import { serializeNodesToText } from '@plone/volto-slate/editor/render';
import {
createImageBlock,
parseDefaultSelection,
deconstructToVoltoBlocks,
} from '@plone/volto-slate/utils';
} from '@plone/volto-slate/utils/volto-blocks';
import { parseDefaultSelection } from '@plone/volto-slate/utils/selection';
import { Transforms } from 'slate';

import PersistentSlashMenu from './SlashMenu';
Expand Down
7 changes: 4 additions & 3 deletions packages/volto-slate/src/blocks/Text/SlashMenu.jsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import React from 'react';
import PropTypes from 'prop-types';
import { filter, isEmpty } from 'lodash';
import filter from 'lodash/filter';
import isEmpty from 'lodash/isEmpty';
import { Menu } from 'semantic-ui-react';
import { useIntl, FormattedMessage } from 'react-intl';
import { Icon } from '@plone/volto/components';
import { useUser } from '@plone/volto/hooks';
import Icon from '@plone/volto/components/theme/Icon/Icon';
import useUser from '@plone/volto/hooks/user/useUser';

const emptySlateBlock = () => ({
value: [
Expand Down
6 changes: 2 additions & 4 deletions packages/volto-slate/src/blocks/Text/TextBlockEdit.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,8 @@ import React from 'react';

import { connect } from 'react-redux';

import {
uploadContent,
saveSlateBlockSelection,
} from '@plone/volto-slate/actions';
import { uploadContent } from '@plone/volto-slate/actions/content';
import saveSlateBlockSelection from '@plone/volto-slate/actions/selection';

import DefaultTextBlockEditor from './DefaultTextBlockEditor';
import DetachedTextBlockEditor from './DetachedTextBlockEditor';
Expand Down
4 changes: 2 additions & 2 deletions packages/volto-slate/src/blocks/Text/TextBlockView.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import {
serializeNodesToText,
} from '@plone/volto-slate/editor/render';
import config from '@plone/volto/registry';
import { isEqual } from 'lodash';
import isEqual from 'lodash/isEqual';
import Slugger from 'github-slugger';
import { normalizeString } from '@plone/volto/helpers';
import { normalizeString } from '@plone/volto/helpers/Utils/Utils';

const TextBlockView = (props) => {
const { id, data, styling = {} } = props;
Expand Down
14 changes: 6 additions & 8 deletions packages/volto-slate/src/blocks/Text/extensions/breakList.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
import { Editor, Range, Transforms } from 'slate';
import config from '@plone/volto/registry';
import {
isCursorAtBlockEnd,
splitEditorInTwoFragments,
setEditorContent,
createAndSelectNewBlockAfter,
getCurrentListItem,
createEmptyParagraph,
} from '@plone/volto-slate/utils';
import { isCursorAtBlockEnd } from '@plone/volto-slate/utils/selection';
import { splitEditorInTwoFragments } from '@plone/volto-slate/utils/ops';
import { setEditorContent } from '@plone/volto-slate/utils/editor';
import { createAndSelectNewBlockAfter } from '@plone/volto-slate/utils/volto-blocks';
import { getCurrentListItem } from '@plone/volto-slate/utils/lists';
import { createEmptyParagraph } from '@plone/volto-slate/utils/blocks';

/**
* Handles `Enter` key on empty and non-empty list items.
Expand Down
11 changes: 4 additions & 7 deletions packages/volto-slate/src/blocks/Text/extensions/insertBreak.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
import ReactDOM from 'react-dom';
import { Editor } from 'slate';
// import { ReactEditor } from 'slate-react';
import {
splitEditorInTwoFragments,
setEditorContent,
createAndSelectNewBlockAfter,
rangeIsInSplittableNode,
// deconstructToVoltoBlocks,
} from '@plone/volto-slate/utils';
import { splitEditorInTwoFragments } from '@plone/volto-slate/utils/ops';
import { setEditorContent } from '@plone/volto-slate/utils/editor';
import { createAndSelectNewBlockAfter } from '@plone/volto-slate/utils/volto-blocks';
import { rangeIsInSplittableNode } from '@plone/volto-slate/utils/internals';

/**
* @param {Editor} editor The Slate editor object to extend.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import isUrl from 'is-url';
import imageExtensions from 'image-extensions';
import { blockTagDeserializer } from '@plone/volto-slate/editor/deserialize';
import { getBaseUrl, validateFileUploadSize } from '@plone/volto/helpers';
import { getBaseUrl } from '@plone/volto/helpers/Url/Url';
import { validateFileUploadSize } from '@plone/volto/helpers/FormValidation/FormValidation';
import { v4 as uuid } from 'uuid';
import { Transforms } from 'slate';

Expand Down
2 changes: 1 addition & 1 deletion packages/volto-slate/src/blocks/Text/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React from 'react';
import TextBlockView from './TextBlockView';
import TextBlockEdit from './TextBlockEdit';
import TextBlockSchema from './TextBlockSchema';
import { cloneDeep } from 'lodash';
import cloneDeep from 'lodash/cloneDeep';

import {
goDown,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import config from '@plone/volto/registry';
import {
isCursorInList,
isCursorAtListBlockStart,
deconstructToVoltoBlocks,
} from '@plone/volto-slate/utils';
} from '@plone/volto-slate/utils/lists';
import { deconstructToVoltoBlocks } from '@plone/volto-slate/utils/volto-blocks';

/**
* Handle the new Volto blocks created by `deconstructToVoltoBlocks`.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { Editor, Path, Transforms } from 'slate';
import {
isCursorInList,
deconstructToVoltoBlocks,
getCurrentListItem,
mergeWithNextList,
mergeWithPreviousList,
} from '@plone/volto-slate/utils';
} from '@plone/volto-slate/utils/lists';
import { deconstructToVoltoBlocks } from '@plone/volto-slate/utils/volto-blocks';
import config from '@plone/volto/registry';

/**
Expand Down
14 changes: 8 additions & 6 deletions packages/volto-slate/src/blocks/Text/keyboard/joinBlocks.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,24 @@
import ReactDOM from 'react-dom';
import { cloneDeep } from 'lodash';
import cloneDeep from 'lodash/cloneDeep';
import { serializeNodesToText } from '@plone/volto-slate/editor/render';
import { Editor } from 'slate';
import {
getPreviousVoltoBlock,
getNextVoltoBlock,
isCursorAtBlockStart,
isCursorAtBlockEnd,
mergeSlateWithBlockBackward,
mergeSlateWithBlockForward,
makeEditor,
} from '@plone/volto-slate/utils';
} from '@plone/volto-slate/utils/volto-blocks';
import {
isCursorAtBlockStart,
isCursorAtBlockEnd,
} from '@plone/volto-slate/utils/selection';
import { makeEditor } from '@plone/volto-slate/utils/editor';
import {
changeBlock,
deleteBlock,
getBlocksFieldname,
getBlocksLayoutFieldname,
} from '@plone/volto/helpers';
} from '@plone/volto/helpers/Blocks/Blocks';
/**
* Joins the current block (which has an active Slate Editor)
* with the previous block, to make a single block.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import { Editor, Path, Transforms, Node } from 'slate';
import { isCursorInList, getCurrentListItem } from '@plone/volto-slate/utils';
import {
isCursorInList,
getCurrentListItem,
} from '@plone/volto-slate/utils/lists';
import config from '@plone/volto/registry';

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@ import { Node } from 'slate';
import {
isCursorAtBlockStart,
isCursorAtBlockEnd,
} from '@plone/volto-slate/utils/selection';
import {
getNextVoltoBlock,
getPreviousVoltoBlock,
createDefaultBlock,
} from '@plone/volto-slate/utils';
} from '@plone/volto-slate/utils/volto-blocks';
import { createDefaultBlock } from '@plone/volto-slate/utils/blocks';

/**
* goUp.
Expand Down
12 changes: 5 additions & 7 deletions packages/volto-slate/src/editor/SlateEditor.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import ReactDOM from 'react-dom';
import cx from 'classnames';
import { isEqual } from 'lodash';
import isEqual from 'lodash/isEqual';
import { Transforms, Editor } from 'slate'; // , Transforms
import { Slate, Editable, ReactEditor } from 'slate-react';
import React, { Component } from 'react'; // , useState
Expand All @@ -11,12 +11,10 @@ import config from '@plone/volto/registry';
import { Element, Leaf } from './render';

import withTestingFeatures from './extensions/withTestingFeatures';
import {
makeEditor,
toggleInlineFormat,
toggleMark,
parseDefaultSelection,
} from '@plone/volto-slate/utils';
import { makeEditor } from '@plone/volto-slate/utils/editor';
import { toggleInlineFormat } from '@plone/volto-slate/utils/blocks';
import { toggleMark } from '@plone/volto-slate/utils/marks';
import { parseDefaultSelection } from '@plone/volto-slate/utils/selection';
import { InlineToolbar } from './ui';
import EditorContext from './EditorContext';

Expand Down
2 changes: 1 addition & 1 deletion packages/volto-slate/src/editor/config.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import strikethroughIcon from '@plone/volto/icons/strikethrough.svg';
import subindexIcon from '@plone/volto/icons/subindex.svg';
import superindexIcon from '@plone/volto/icons/superindex.svg';

import { createEmptyParagraph } from '@plone/volto-slate/utils';
import { createEmptyParagraph } from '@plone/volto-slate/utils/blocks';

import {
MarkElementButton,
Expand Down
4 changes: 2 additions & 2 deletions packages/volto-slate/src/editor/extensions/insertData.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import { deserialize } from '@plone/volto-slate/editor/deserialize';
import {
createBlock,
createDefaultBlock,
MIMETypeName,
normalizeExternalData,
} from '@plone/volto-slate/utils';
} from '@plone/volto-slate/utils/blocks';
import { MIMETypeName } from '@plone/volto-slate/utils/mime-types';
import { isBlockActive } from '../../utils/blocks';

export const insertData = (editor) => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { normalizeExternalData as normalize } from '@plone/volto-slate/utils';
import { normalizeExternalData as normalize } from '@plone/volto-slate/utils/blocks';

export function normalizeExternalData(editor) {
editor.normalizeExternalData = (fragment) => {
Expand Down
Loading
Loading