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

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
  •  
  •  
  •  
8 changes: 7 additions & 1 deletion docs/source/upgrade-guide/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -723,11 +723,17 @@ 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/utils/index.js`

##### Alternative

Expand Down
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
pnicolli marked this conversation as resolved.
Show resolved Hide resolved
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
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { useMemo } from 'react';
import { ReactEditor } from 'slate-react';
import { omit } from 'lodash';
import omit from 'lodash/omit';

const withTestingFeatures = (WrappedComponent) => {
return (props) => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { jsx } from 'slate-hyperscript';
import { LINK } from '@plone/volto-slate/constants';
import { deserialize } from '@plone/volto-slate/editor/deserialize';
import { isEmpty } from 'lodash';
import isEmpty from 'lodash/isEmpty';
// import { Editor } from 'slate';

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react';
import { UniversalLink } from '@plone/volto/components';
import UniversalLink from '@plone/volto/components/manage/UniversalLink/UniversalLink';
import './styles.less';

export const LinkElement = ({ attributes, children, element, mode }) => {
Expand Down
4 changes: 2 additions & 2 deletions packages/volto-slate/src/editor/plugins/Link/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ import {
import { SIMPLELINK, LINK } from '@plone/volto-slate/constants';
import { LinkElement } from './render';
import { simpleLinkDeserializer, withSimpleLink } from './extensions';
import { setPluginOptions } from '@plone/volto-slate/actions';
import { setPluginOptions } from '@plone/volto-slate/actions/plugins';
import {
ToolbarButton as UIToolbarButton,
PositionedToolbar,
} from '@plone/volto-slate/editor/ui';
import { useSelectionPosition } from '@plone/volto-slate/hooks';
import { useSelectionPosition } from '@plone/volto-slate/hooks/useSelectionPosition';

import linkSVG from '@plone/volto/icons/link.svg';
import unlinkSVG from '@plone/volto/icons/unlink.svg';
Expand Down
4 changes: 2 additions & 2 deletions packages/volto-slate/src/editor/plugins/Link/render.jsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import React from 'react';
import cx from 'classnames';
import { UniversalLink } from '@plone/volto/components';
import UniversalLink from '@plone/volto/components/manage/UniversalLink/UniversalLink';
import config from '@plone/volto/registry';
import { isInternalURL, flattenToAppURL } from '@plone/volto/helpers';
import { isInternalURL, flattenToAppURL } from '@plone/volto/helpers/Url/Url';

const ViewLink = ({ url, target, download, children }) => {
const { openExternalLinkInNewTab } = config.settings;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { toggleList } from './utils';
import { isBlockActive } from '@plone/volto-slate/utils';
import { isBlockActive } from '@plone/volto-slate/utils/blocks';
import { UL, OL, LI, H2, H3, BLOCKQUOTE } from '@plone/volto-slate/constants';

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { castArray, map } from 'lodash';
import castArray from 'lodash/castArray';
import map from 'lodash/map';
import { Editor, Path, Point, Range, Transforms } from 'slate';

/**
Expand Down
2 changes: 1 addition & 1 deletion packages/volto-slate/src/editor/plugins/Markdown/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {
getMaxRange,
selectAll,
getSelectionNodesArrayByType,
} from '@plone/volto-slate/utils';
} from '@plone/volto-slate/utils/selection';
import { P, LI, UL, OL } from '@plone/volto-slate/constants';

export function unwrapNodesByType(editor, types, options = {}) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { useSlate } from 'slate-react';
import { Dropdown } from 'semantic-ui-react';
import { useIntl, defineMessages } from 'react-intl';
import cx from 'classnames';
import { omit } from 'lodash';
import omit from 'lodash/omit';
import { isBlockStyleActive, isInlineStyleActive, toggleStyle } from './utils';
import config from '@plone/volto/registry';
import { ToolbarButton } from '@plone/volto-slate/editor/ui';
Expand Down
Loading
Loading