@plone/volto 18.0.0-alpha.3 → 18.0.0-alpha.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.eslintrc +3 -3
- package/.prettierignore +8 -0
- package/.prettierrc +12 -0
- package/{packages/registry/.release-it.json → .release-it.json} +11 -6
- package/CHANGELOG.md +29 -4
- package/package.json +57 -127
- package/razzle.config.js +4 -7
- package/src/components/manage/Controlpanels/Users/UserGroupMembershipControlPanel.jsx +2 -2
- package/src/components/manage/Form/Form.jsx +5 -2
- package/src/config/index.js +0 -4
- package/src/icons/divide-horizontal.svg +0 -0
- package/src/icons/divide-vertical.svg +0 -0
- package/src/icons/hero.svg +0 -0
- package/src/icons/slider.svg +0 -0
- package/src/icons/summary.svg +0 -0
- package/src/middleware/api.js +1 -1
- package/theme/themes/default/elements/icon.overrides +0 -0
- package/theme/themes/default/globals/reset.overrides +0 -0
- package/theme/themes/default/globals/site.variables +0 -0
- package/theme/themes/default/modules/dropdown.overrides +0 -0
- package/theme/themes/default/modules/dropdown.variables +0 -0
- package/theme/themes/default/modules/modal.variables +0 -0
- package/theme/themes/default/modules/video.overrides +0 -0
- package/theme/themes/default/modules/video.variables +0 -0
- package/theme/themes/pastanaga/assets/fonts/icons.eot +0 -0
- package/theme/themes/pastanaga/assets/fonts/icons.svg +0 -0
- package/theme/themes/pastanaga/assets/fonts/icons.ttf +0 -0
- package/theme/themes/pastanaga/assets/fonts/icons.woff +0 -0
- package/theme/themes/pastanaga/globals/reset.overrides +0 -0
- package/theme/themes/pastanaga/globals/site.variables +0 -0
- package/theme/themes/pastanaga/modules/dropdown.variables +0 -0
- package/theme/themes/pastanaga/modules/modal.variables +0 -0
- package/theme/themes/pastanaga/modules/video.overrides +0 -0
- package/theme/themes/pastanaga/modules/video.variables +0 -0
- package/tsconfig.json +1 -4
- package/types/config/RichTextEditor/index.d.ts +5 -8
- package/types/helpers/AsyncConnect/index.d.ts +2 -2
- package/types/helpers/Url/Url.d.ts +3 -3
- package/types/icons/load-icons.d.ts +1 -1
- package/webpack-plugins/webpack-less-plugin.js +1 -0
- package/CODE_OF_CONDUCT.md +0 -13
- package/CONTRIBUTING.md +0 -7
- package/README.md +0 -154
- package/RELEASING.md +0 -73
- package/ROADMAP.md +0 -30
- package/SECURITY.md +0 -14
- package/apps/plone/node_modules/.bin/acorn +0 -17
- package/apps/plone/node_modules/.bin/addon +0 -17
- package/apps/plone/node_modules/.bin/autoprefixer +0 -17
- package/apps/plone/node_modules/.bin/browserslist +0 -17
- package/apps/plone/node_modules/.bin/build-storybook +0 -17
- package/apps/plone/node_modules/.bin/changelogupdater +0 -17
- package/apps/plone/node_modules/.bin/eslint +0 -17
- package/apps/plone/node_modules/.bin/eslint-config-prettier +0 -17
- package/apps/plone/node_modules/.bin/i18n +0 -17
- package/apps/plone/node_modules/.bin/jest +0 -17
- package/apps/plone/node_modules/.bin/lessc +0 -17
- package/apps/plone/node_modules/.bin/missdev +0 -17
- package/apps/plone/node_modules/.bin/prettier +0 -17
- package/apps/plone/node_modules/.bin/razzle +0 -17
- package/apps/plone/node_modules/.bin/server-test +0 -17
- package/apps/plone/node_modules/.bin/start-server-and-test +0 -17
- package/apps/plone/node_modules/.bin/start-storybook +0 -17
- package/apps/plone/node_modules/.bin/start-test +0 -17
- package/apps/plone/node_modules/.bin/storybook-server +0 -17
- package/apps/plone/node_modules/.bin/stylelint +0 -17
- package/apps/plone/node_modules/.bin/tlds +0 -17
- package/apps/plone/node_modules/.bin/ts-jest +0 -17
- package/apps/plone/node_modules/.bin/tsc +0 -17
- package/apps/plone/node_modules/.bin/tsserver +0 -17
- package/apps/plone/node_modules/.bin/uuid +0 -17
- package/apps/plone/node_modules/.bin/webpack +0 -17
- package/apps/plone/node_modules/.bin/webpack-dev-server +0 -17
- package/apps/plone/src/addons/volto-volto-project/node_modules/.bin/acorn +0 -17
- package/apps/plone/src/addons/volto-volto-project/node_modules/.bin/addon +0 -17
- package/apps/plone/src/addons/volto-volto-project/node_modules/.bin/browserslist +0 -17
- package/apps/plone/src/addons/volto-volto-project/node_modules/.bin/changelogupdater +0 -17
- package/apps/plone/src/addons/volto-volto-project/node_modules/.bin/eslint +0 -17
- package/apps/plone/src/addons/volto-volto-project/node_modules/.bin/eslint-config-prettier +0 -17
- package/apps/plone/src/addons/volto-volto-project/node_modules/.bin/i18n +0 -17
- package/apps/plone/src/addons/volto-volto-project/node_modules/.bin/prettier +0 -17
- package/apps/plone/src/addons/volto-volto-project/node_modules/.bin/release-it +0 -17
- package/apps/plone/src/addons/volto-volto-project/node_modules/.bin/stylelint +0 -17
- package/apps/plone/src/addons/volto-volto-project/node_modules/.bin/tsc +0 -17
- package/apps/plone/src/addons/volto-volto-project/node_modules/.bin/tsserver +0 -17
- package/logos/Logo.png +0 -0
- package/logos/VoltoLogoEra2-dark-mode.png +0 -0
- package/logos/VoltoLogoEra2.png +0 -0
- package/logos/volto-colorful.png +0 -0
- package/logos/volto-colorful.svg +0 -35
- package/logos/volto-guide.png +0 -0
- package/logos/volto-h-transparent.svg +0 -6
- package/logos/volto-transparent.png +0 -0
- package/logos/volto-transparent.svg +0 -19
- package/logos/volto-transparent2.svg +0 -5
- package/logos/volto-yellow.svg +0 -29
- package/logos/volto.sketch +0 -0
- package/packages/README.md +0 -7
- package/packages/registry/.towncrier/towncrier_template.jinja +0 -10
- package/packages/registry/CHANGELOG.md +0 -16
- package/packages/registry/README.md +0 -207
- package/packages/registry/addon-registry.js +0 -603
- package/packages/registry/create-addons-loader.js +0 -116
- package/packages/registry/create-theme-addons-loader.js +0 -78
- package/packages/registry/news/.gitkeep +0 -0
- package/packages/registry/node_modules/.bin/browserslist +0 -17
- package/packages/registry/node_modules/.bin/parcel +0 -17
- package/packages/registry/node_modules/.bin/release-it +0 -17
- package/packages/registry/node_modules/.bin/tsc +0 -17
- package/packages/registry/node_modules/.bin/tsserver +0 -17
- package/packages/registry/node_modules/.bin/vitest +0 -17
- package/packages/registry/package.json +0 -76
- package/packages/registry/src/index.ts +0 -174
- package/packages/registry/src/registry.test.js +0 -111
- package/packages/registry/tsconfig.json +0 -32
- package/packages/scripts/CHANGELOG.md +0 -173
- package/packages/scripts/README.md +0 -128
- package/packages/scripts/addon/consolidate.js +0 -28
- package/packages/scripts/addon/generators.js +0 -213
- package/packages/scripts/addon/getAddonInfo.js +0 -65
- package/packages/scripts/addon/index.js +0 -88
- package/packages/scripts/addon/utils.js +0 -44
- package/packages/scripts/backportpr.js +0 -75
- package/packages/scripts/changelogupdater.cjs +0 -94
- package/packages/scripts/corepackagebump.js +0 -20
- package/packages/scripts/i18n.cjs +0 -310
- package/packages/scripts/package.json +0 -76
- package/packages/scripts/templates/towncrier_template.jinja +0 -10
- package/packages/types/Blocks/View.ts +0 -11
- package/packages/types/actions.ts +0 -15
- package/packages/types/breadcrumbs.ts +0 -10
- package/packages/types/config/Blocks.ts +0 -153
- package/packages/types/config/Content.ts +0 -62
- package/packages/types/config/Settings.ts +0 -86
- package/packages/types/config/Views.ts +0 -15
- package/packages/types/config/Widgets.ts +0 -7
- package/packages/types/config/index.ts +0 -21
- package/packages/types/content/common.ts +0 -60
- package/packages/types/content/get.ts +0 -66
- package/packages/types/index.ts +0 -0
- package/packages/types/navigation.ts +0 -12
- package/packages/types/node_modules/.bin/browserslist +0 -17
- package/packages/types/node_modules/.bin/parcel +0 -17
- package/packages/types/node_modules/.bin/release-it +0 -17
- package/packages/types/node_modules/.bin/tsc +0 -17
- package/packages/types/node_modules/.bin/tsserver +0 -17
- package/packages/types/package.json +0 -64
- package/packages/types/types.ts +0 -61
- package/packages/volto-slate/.i18n.babel.config.js +0 -1
- package/packages/volto-slate/README.md +0 -4
- package/packages/volto-slate/build/messages/src/blocks/Table/TableBlockEdit.json +0 -90
- package/packages/volto-slate/build/messages/src/blocks/Text/DefaultTextBlockEditor.json +0 -6
- package/packages/volto-slate/build/messages/src/blocks/Text/DetachedTextBlockEditor.json +0 -6
- package/packages/volto-slate/build/messages/src/blocks/Text/SlashMenu.json +0 -6
- package/packages/volto-slate/build/messages/src/editor/plugins/AdvancedLink/index.json +0 -10
- package/packages/volto-slate/build/messages/src/editor/plugins/Link/index.json +0 -10
- package/packages/volto-slate/build/messages/src/editor/plugins/Table/index.json +0 -30
- package/packages/volto-slate/build/messages/src/elementEditor/messages.json +0 -10
- package/packages/volto-slate/build/messages/src/widgets/HtmlSlateWidget.json +0 -6
- package/packages/volto-slate/build/messages/src/widgets/RichTextWidgetView.json +0 -6
- package/packages/volto-slate/locales/de/LC_MESSAGES/volto.po +0 -148
- package/packages/volto-slate/locales/en/LC_MESSAGES/volto.po +0 -148
- package/packages/volto-slate/locales/volto.pot +0 -182
- package/packages/volto-slate/package.json +0 -43
- package/packages/volto-slate/src/actions/content.js +0 -30
- package/packages/volto-slate/src/actions/index.js +0 -3
- package/packages/volto-slate/src/actions/plugins.js +0 -9
- package/packages/volto-slate/src/actions/selection.js +0 -22
- package/packages/volto-slate/src/blocks/Table/Cell.jsx +0 -87
- package/packages/volto-slate/src/blocks/Table/Cell.test.js +0 -54
- package/packages/volto-slate/src/blocks/Table/TableBlockEdit.jsx +0 -694
- package/packages/volto-slate/src/blocks/Table/TableBlockEdit.test.js +0 -40
- package/packages/volto-slate/src/blocks/Table/TableBlockView.jsx +0 -150
- package/packages/volto-slate/src/blocks/Table/TableBlockView.test.js +0 -49
- package/packages/volto-slate/src/blocks/Table/deconstruct.js +0 -113
- package/packages/volto-slate/src/blocks/Table/extensions/normalizeTable.js +0 -5
- package/packages/volto-slate/src/blocks/Table/index.js +0 -60
- package/packages/volto-slate/src/blocks/Table/schema.js +0 -122
- package/packages/volto-slate/src/blocks/Text/DefaultTextBlockEditor.jsx +0 -304
- package/packages/volto-slate/src/blocks/Text/DetachedTextBlockEditor.jsx +0 -77
- package/packages/volto-slate/src/blocks/Text/MarkdownIntroduction.jsx +0 -59
- package/packages/volto-slate/src/blocks/Text/PluginSidebar.jsx +0 -18
- package/packages/volto-slate/src/blocks/Text/ShortcutListing.jsx +0 -28
- package/packages/volto-slate/src/blocks/Text/SlashMenu.jsx +0 -203
- package/packages/volto-slate/src/blocks/Text/TextBlockEdit.jsx +0 -38
- package/packages/volto-slate/src/blocks/Text/TextBlockEdit.test.js +0 -107
- package/packages/volto-slate/src/blocks/Text/TextBlockSchema.js +0 -54
- package/packages/volto-slate/src/blocks/Text/TextBlockView.jsx +0 -31
- package/packages/volto-slate/src/blocks/Text/css/editor.css +0 -18
- package/packages/volto-slate/src/blocks/Text/extensions/Readme.md +0 -49
- package/packages/volto-slate/src/blocks/Text/extensions/breakList.js +0 -100
- package/packages/volto-slate/src/blocks/Text/extensions/index.js +0 -6
- package/packages/volto-slate/src/blocks/Text/extensions/insertBreak.js +0 -57
- package/packages/volto-slate/src/blocks/Text/extensions/isSelected.js +0 -7
- package/packages/volto-slate/src/blocks/Text/extensions/normalizeExternalData.js +0 -7
- package/packages/volto-slate/src/blocks/Text/extensions/withDeserializers.js +0 -87
- package/packages/volto-slate/src/blocks/Text/extensions/withLists.js +0 -5
- package/packages/volto-slate/src/blocks/Text/index.js +0 -171
- package/packages/volto-slate/src/blocks/Text/keyboard/backspaceInList.js +0 -58
- package/packages/volto-slate/src/blocks/Text/keyboard/breakBlocks.js +0 -3
- package/packages/volto-slate/src/blocks/Text/keyboard/cancelEsc.js +0 -7
- package/packages/volto-slate/src/blocks/Text/keyboard/indentListItems.js +0 -240
- package/packages/volto-slate/src/blocks/Text/keyboard/index.js +0 -52
- package/packages/volto-slate/src/blocks/Text/keyboard/joinBlocks.js +0 -180
- package/packages/volto-slate/src/blocks/Text/keyboard/moveListItems.js +0 -124
- package/packages/volto-slate/src/blocks/Text/keyboard/slashMenu.js +0 -19
- package/packages/volto-slate/src/blocks/Text/keyboard/softBreak.js +0 -7
- package/packages/volto-slate/src/blocks/Text/keyboard/traverseBlocks.js +0 -81
- package/packages/volto-slate/src/blocks/Text/keyboard/unwrapEmptyString.js +0 -26
- package/packages/volto-slate/src/blocks/Text/schema.js +0 -39
- package/packages/volto-slate/src/constants.js +0 -123
- package/packages/volto-slate/src/editor/EditorContext.jsx +0 -5
- package/packages/volto-slate/src/editor/EditorReference.jsx +0 -22
- package/packages/volto-slate/src/editor/SlateEditor.jsx +0 -375
- package/packages/volto-slate/src/editor/config.jsx +0 -344
- package/packages/volto-slate/src/editor/decorate.js +0 -68
- package/packages/volto-slate/src/editor/deserialize.js +0 -185
- package/packages/volto-slate/src/editor/extensions/index.js +0 -6
- package/packages/volto-slate/src/editor/extensions/insertBreak.js +0 -15
- package/packages/volto-slate/src/editor/extensions/insertData.js +0 -159
- package/packages/volto-slate/src/editor/extensions/isInline.js +0 -14
- package/packages/volto-slate/src/editor/extensions/normalizeExternalData.js +0 -8
- package/packages/volto-slate/src/editor/extensions/normalizeNode.js +0 -48
- package/packages/volto-slate/src/editor/extensions/withDeserializers.js +0 -15
- package/packages/volto-slate/src/editor/extensions/withTestingFeatures.jsx +0 -84
- package/packages/volto-slate/src/editor/index.js +0 -14
- package/packages/volto-slate/src/editor/less/editor.less +0 -173
- package/packages/volto-slate/src/editor/less/globals.less +0 -18
- package/packages/volto-slate/src/editor/less/slate.less +0 -28
- package/packages/volto-slate/src/editor/plugins/AdvancedLink/deserialize.js +0 -90
- package/packages/volto-slate/src/editor/plugins/AdvancedLink/extensions.js +0 -32
- package/packages/volto-slate/src/editor/plugins/AdvancedLink/index.js +0 -50
- package/packages/volto-slate/src/editor/plugins/AdvancedLink/render.jsx +0 -37
- package/packages/volto-slate/src/editor/plugins/AdvancedLink/schema.js +0 -114
- package/packages/volto-slate/src/editor/plugins/AdvancedLink/styles.less +0 -8
- package/packages/volto-slate/src/editor/plugins/Blockquote/index.js +0 -30
- package/packages/volto-slate/src/editor/plugins/Callout/index.js +0 -34
- package/packages/volto-slate/src/editor/plugins/Image/deconstruct.js +0 -30
- package/packages/volto-slate/src/editor/plugins/Image/extensions.js +0 -51
- package/packages/volto-slate/src/editor/plugins/Image/index.js +0 -11
- package/packages/volto-slate/src/editor/plugins/Image/render.jsx +0 -22
- package/packages/volto-slate/src/editor/plugins/Link/extensions.js +0 -58
- package/packages/volto-slate/src/editor/plugins/Link/index.js +0 -164
- package/packages/volto-slate/src/editor/plugins/Link/render.jsx +0 -54
- package/packages/volto-slate/src/editor/plugins/Markdown/constants.js +0 -81
- package/packages/volto-slate/src/editor/plugins/Markdown/extensions.js +0 -334
- package/packages/volto-slate/src/editor/plugins/Markdown/index.js +0 -28
- package/packages/volto-slate/src/editor/plugins/Markdown/utils.js +0 -198
- package/packages/volto-slate/src/editor/plugins/StyleMenu/StyleMenu.jsx +0 -153
- package/packages/volto-slate/src/editor/plugins/StyleMenu/index.js +0 -19
- package/packages/volto-slate/src/editor/plugins/StyleMenu/style.less +0 -29
- package/packages/volto-slate/src/editor/plugins/StyleMenu/utils.js +0 -168
- package/packages/volto-slate/src/editor/plugins/Table/TableButton.jsx +0 -142
- package/packages/volto-slate/src/editor/plugins/Table/TableCell.jsx +0 -44
- package/packages/volto-slate/src/editor/plugins/Table/TableContainer.jsx +0 -37
- package/packages/volto-slate/src/editor/plugins/Table/TableSizePicker.jsx +0 -83
- package/packages/volto-slate/src/editor/plugins/Table/extensions.js +0 -87
- package/packages/volto-slate/src/editor/plugins/Table/index.js +0 -390
- package/packages/volto-slate/src/editor/plugins/Table/less/public.less +0 -29
- package/packages/volto-slate/src/editor/plugins/Table/less/table.less +0 -28
- package/packages/volto-slate/src/editor/plugins/Table/render.jsx +0 -30
- package/packages/volto-slate/src/editor/plugins/index.js +0 -19
- package/packages/volto-slate/src/editor/render.jsx +0 -224
- package/packages/volto-slate/src/editor/ui/BasicToolbar.jsx +0 -11
- package/packages/volto-slate/src/editor/ui/BlockButton.jsx +0 -31
- package/packages/volto-slate/src/editor/ui/ClearFormattingButton.jsx +0 -21
- package/packages/volto-slate/src/editor/ui/ExpandedToolbar.jsx +0 -18
- package/packages/volto-slate/src/editor/ui/Expando.jsx +0 -5
- package/packages/volto-slate/src/editor/ui/InlineToolbar.jsx +0 -73
- package/packages/volto-slate/src/editor/ui/MarkButton.jsx +0 -23
- package/packages/volto-slate/src/editor/ui/MarkElementButton.jsx +0 -30
- package/packages/volto-slate/src/editor/ui/Menu.jsx +0 -13
- package/packages/volto-slate/src/editor/ui/PositionedToolbar.jsx +0 -32
- package/packages/volto-slate/src/editor/ui/Separator.jsx +0 -7
- package/packages/volto-slate/src/editor/ui/SlateContextToolbar.jsx +0 -13
- package/packages/volto-slate/src/editor/ui/SlateToolbar.jsx +0 -96
- package/packages/volto-slate/src/editor/ui/Toolbar.jsx +0 -103
- package/packages/volto-slate/src/editor/ui/ToolbarButton.jsx +0 -33
- package/packages/volto-slate/src/editor/ui/ToolbarButton.test.js +0 -25
- package/packages/volto-slate/src/editor/ui/index.js +0 -15
- package/packages/volto-slate/src/editor/utils.js +0 -248
- package/packages/volto-slate/src/elementEditor/ContextButtons.jsx +0 -56
- package/packages/volto-slate/src/elementEditor/PluginEditor.jsx +0 -124
- package/packages/volto-slate/src/elementEditor/Readme.md +0 -6
- package/packages/volto-slate/src/elementEditor/SchemaProvider.jsx +0 -3
- package/packages/volto-slate/src/elementEditor/SidebarEditor.jsx +0 -46
- package/packages/volto-slate/src/elementEditor/ToolbarButton.jsx +0 -44
- package/packages/volto-slate/src/elementEditor/index.js +0 -5
- package/packages/volto-slate/src/elementEditor/makeInlineElementPlugin.js +0 -100
- package/packages/volto-slate/src/elementEditor/messages.js +0 -14
- package/packages/volto-slate/src/elementEditor/utils.js +0 -226
- package/packages/volto-slate/src/hooks/index.js +0 -3
- package/packages/volto-slate/src/hooks/useEditorContext.js +0 -6
- package/packages/volto-slate/src/hooks/useIsomorphicLayoutEffect.js +0 -7
- package/packages/volto-slate/src/hooks/useSelectionPosition.js +0 -25
- package/packages/volto-slate/src/i18n.js +0 -180
- package/packages/volto-slate/src/icons/hashlink.svg +0 -57
- package/packages/volto-slate/src/index.js +0 -61
- package/packages/volto-slate/src/reducers/content.js +0 -74
- package/packages/volto-slate/src/reducers/index.js +0 -3
- package/packages/volto-slate/src/reducers/plugins.js +0 -17
- package/packages/volto-slate/src/reducers/selection.js +0 -16
- package/packages/volto-slate/src/utils/blocks.js +0 -375
- package/packages/volto-slate/src/utils/blocks.test.js +0 -138
- package/packages/volto-slate/src/utils/editor.js +0 -31
- package/packages/volto-slate/src/utils/image.js +0 -25
- package/packages/volto-slate/src/utils/index.js +0 -11
- package/packages/volto-slate/src/utils/internals.js +0 -46
- package/packages/volto-slate/src/utils/lists.js +0 -92
- package/packages/volto-slate/src/utils/marks.js +0 -104
- package/packages/volto-slate/src/utils/mime-types.js +0 -24
- package/packages/volto-slate/src/utils/nodes.js +0 -4
- package/packages/volto-slate/src/utils/ops.js +0 -20
- package/packages/volto-slate/src/utils/random.js +0 -17
- package/packages/volto-slate/src/utils/selection.js +0 -236
- package/packages/volto-slate/src/utils/slate-string-utils.js +0 -408
- package/packages/volto-slate/src/utils/volto-blocks.js +0 -314
- package/packages/volto-slate/src/widgets/ErrorBoundary.jsx +0 -27
- package/packages/volto-slate/src/widgets/HtmlSlateWidget.jsx +0 -139
- package/packages/volto-slate/src/widgets/ObjectByTypeWidget.jsx +0 -49
- package/packages/volto-slate/src/widgets/RichTextWidget.jsx +0 -72
- package/packages/volto-slate/src/widgets/RichTextWidgetView.jsx +0 -37
- package/packages/volto-slate/src/widgets/style.css +0 -21
- package/types/components/manage/Blocks/Video/Body.test.d.ts +0 -1
|
@@ -1,344 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import config from '@plone/volto/registry';
|
|
3
|
-
|
|
4
|
-
import boldIcon from '@plone/volto/icons/bold.svg';
|
|
5
|
-
import codeIcon from '@plone/volto/icons/code.svg';
|
|
6
|
-
import formatClearIcon from '@plone/volto/icons/format-clear.svg';
|
|
7
|
-
import headingIcon from '@plone/volto/icons/heading.svg';
|
|
8
|
-
import italicIcon from '@plone/volto/icons/italic.svg';
|
|
9
|
-
import listBulletIcon from '@plone/volto/icons/list-bullet.svg';
|
|
10
|
-
import listNumberedIcon from '@plone/volto/icons/list-numbered.svg';
|
|
11
|
-
import subheadingIcon from '@plone/volto/icons/subheading.svg';
|
|
12
|
-
import subTextIcon from '@plone/volto/icons/subtext.svg';
|
|
13
|
-
import underlineIcon from '@plone/volto/icons/underline.svg';
|
|
14
|
-
import strikethroughIcon from '@plone/volto/icons/strikethrough.svg';
|
|
15
|
-
import subindexIcon from '@plone/volto/icons/subindex.svg';
|
|
16
|
-
import superindexIcon from '@plone/volto/icons/superindex.svg';
|
|
17
|
-
|
|
18
|
-
import { createEmptyParagraph } from '@plone/volto-slate/utils';
|
|
19
|
-
|
|
20
|
-
import {
|
|
21
|
-
MarkButton,
|
|
22
|
-
MarkElementButton,
|
|
23
|
-
BlockButton,
|
|
24
|
-
ClearFormattingButton,
|
|
25
|
-
Separator,
|
|
26
|
-
Expando,
|
|
27
|
-
} from './ui';
|
|
28
|
-
import { highlightSelection } from './decorate'; // highlightByType,
|
|
29
|
-
import {
|
|
30
|
-
insertData,
|
|
31
|
-
isInline,
|
|
32
|
-
withDeleteSelectionOnEnter,
|
|
33
|
-
withDeserializers,
|
|
34
|
-
normalizeNode,
|
|
35
|
-
normalizeExternalData,
|
|
36
|
-
} from './extensions';
|
|
37
|
-
import {
|
|
38
|
-
// inlineTagDeserializer,
|
|
39
|
-
bodyTagDeserializer,
|
|
40
|
-
blockTagDeserializer,
|
|
41
|
-
preTagDeserializer,
|
|
42
|
-
spanTagDeserializer,
|
|
43
|
-
bTagDeserializer,
|
|
44
|
-
codeTagDeserializer,
|
|
45
|
-
} from './deserialize';
|
|
46
|
-
import { renderLinkElement } from './render';
|
|
47
|
-
|
|
48
|
-
// Registry of available buttons
|
|
49
|
-
export const buttons = {
|
|
50
|
-
bold: (props) => (
|
|
51
|
-
<MarkElementButton
|
|
52
|
-
title="Bold"
|
|
53
|
-
format="strong"
|
|
54
|
-
icon={boldIcon}
|
|
55
|
-
{...props}
|
|
56
|
-
/>
|
|
57
|
-
),
|
|
58
|
-
italic: (props) => (
|
|
59
|
-
<MarkElementButton
|
|
60
|
-
title="Italic"
|
|
61
|
-
format="em"
|
|
62
|
-
icon={italicIcon}
|
|
63
|
-
{...props}
|
|
64
|
-
/>
|
|
65
|
-
),
|
|
66
|
-
underline: (props) => (
|
|
67
|
-
<MarkElementButton
|
|
68
|
-
title="Underline"
|
|
69
|
-
format="u"
|
|
70
|
-
icon={underlineIcon}
|
|
71
|
-
{...props}
|
|
72
|
-
/>
|
|
73
|
-
),
|
|
74
|
-
strikethrough: (props) => (
|
|
75
|
-
<MarkElementButton
|
|
76
|
-
title="Strikethrough"
|
|
77
|
-
format="del"
|
|
78
|
-
icon={strikethroughIcon}
|
|
79
|
-
{...props}
|
|
80
|
-
/>
|
|
81
|
-
),
|
|
82
|
-
sub: (props) => (
|
|
83
|
-
<MarkElementButton
|
|
84
|
-
title="Subscript"
|
|
85
|
-
format="sub"
|
|
86
|
-
icon={subindexIcon}
|
|
87
|
-
{...props}
|
|
88
|
-
/>
|
|
89
|
-
),
|
|
90
|
-
sup: (props) => (
|
|
91
|
-
<MarkElementButton
|
|
92
|
-
title="Superscript"
|
|
93
|
-
format="sup"
|
|
94
|
-
icon={superindexIcon}
|
|
95
|
-
{...props}
|
|
96
|
-
/>
|
|
97
|
-
),
|
|
98
|
-
code: (props) => (
|
|
99
|
-
<MarkButton title="Code" format="code" icon={codeIcon} {...props} />
|
|
100
|
-
),
|
|
101
|
-
'heading-two': (props) => (
|
|
102
|
-
<BlockButton
|
|
103
|
-
title="Title"
|
|
104
|
-
format="h2"
|
|
105
|
-
allowedChildren={config.settings.slate.allowedHeadlineElements}
|
|
106
|
-
icon={headingIcon}
|
|
107
|
-
{...props}
|
|
108
|
-
/>
|
|
109
|
-
),
|
|
110
|
-
'heading-three': (props) => (
|
|
111
|
-
<BlockButton
|
|
112
|
-
title="Subtitle"
|
|
113
|
-
format="h3"
|
|
114
|
-
allowedChildren={config.settings.slate.allowedHeadlineElements}
|
|
115
|
-
icon={subheadingIcon}
|
|
116
|
-
{...props}
|
|
117
|
-
/>
|
|
118
|
-
),
|
|
119
|
-
'heading-four': (props) => (
|
|
120
|
-
<BlockButton
|
|
121
|
-
title="Heading 4"
|
|
122
|
-
allowedChildren={config.settings.slate.allowedHeadlineElements}
|
|
123
|
-
format="h4"
|
|
124
|
-
icon={subTextIcon}
|
|
125
|
-
{...props}
|
|
126
|
-
/>
|
|
127
|
-
),
|
|
128
|
-
clearformatting: (props) => (
|
|
129
|
-
<ClearFormattingButton title="Clear formatting" icon={formatClearIcon} />
|
|
130
|
-
),
|
|
131
|
-
'numbered-list': (props) => (
|
|
132
|
-
<BlockButton
|
|
133
|
-
title="Numbered list"
|
|
134
|
-
format="ol"
|
|
135
|
-
icon={listNumberedIcon}
|
|
136
|
-
{...props}
|
|
137
|
-
/>
|
|
138
|
-
),
|
|
139
|
-
'bulleted-list': (props) => (
|
|
140
|
-
<BlockButton title="Bulleted list" format="ul" icon={listBulletIcon} />
|
|
141
|
-
),
|
|
142
|
-
separator: (props) => <Separator />,
|
|
143
|
-
expando: (props) => <Expando />,
|
|
144
|
-
};
|
|
145
|
-
|
|
146
|
-
export const defaultToolbarButtons = [
|
|
147
|
-
'bold',
|
|
148
|
-
'italic',
|
|
149
|
-
'underline',
|
|
150
|
-
'strikethrough',
|
|
151
|
-
'separator',
|
|
152
|
-
'heading-two',
|
|
153
|
-
'heading-three',
|
|
154
|
-
'heading-four',
|
|
155
|
-
'separator',
|
|
156
|
-
'clearformatting',
|
|
157
|
-
'separator',
|
|
158
|
-
'sub',
|
|
159
|
-
'sup',
|
|
160
|
-
'separator',
|
|
161
|
-
'bulleted-list',
|
|
162
|
-
'numbered-list',
|
|
163
|
-
];
|
|
164
|
-
|
|
165
|
-
export const toolbarButtons = [...defaultToolbarButtons];
|
|
166
|
-
|
|
167
|
-
export const expandedToolbarButtons = [...defaultToolbarButtons];
|
|
168
|
-
|
|
169
|
-
// These components are rendered in the toolbar on demand, as configured by
|
|
170
|
-
// plugins. They are rendered as "context" buttons, when there is no selection
|
|
171
|
-
// Each one is a function (editor) => (<Component/> or null). It is important
|
|
172
|
-
// to be able to tell if a plugin would return something because we don't want
|
|
173
|
-
// to render the toolbar at all if there's no children (due to CSS reasons).
|
|
174
|
-
export const contextToolbarButtons = [];
|
|
175
|
-
|
|
176
|
-
// Each Element node type available in the editor can be configured to have
|
|
177
|
-
// specific toolbar buttons shown above the element of that type when it
|
|
178
|
-
// contains the selection. The Table plugin of SlateEditor uses this to put a
|
|
179
|
-
// Delete table button above the currently selected table.
|
|
180
|
-
export const elementToolbarButtons = {};
|
|
181
|
-
|
|
182
|
-
// A set of components that are always rendered, unlike the button variety.
|
|
183
|
-
// They make it possible to orchestrate form-based editing of components
|
|
184
|
-
export const persistentHelpers = [];
|
|
185
|
-
|
|
186
|
-
// The slate editor is "decorated" with the capabilities from this list.
|
|
187
|
-
// While Slate calls them plugins, we use "extension" to avoid confusion.
|
|
188
|
-
// A Volto Slate editor plugins adds more functionality: buttons, new elements,
|
|
189
|
-
// etc.
|
|
190
|
-
// Each extension is a simple mutator function with signature: `editor => editor`.
|
|
191
|
-
// See https://docs.slatejs.org/concepts/07-plugins and
|
|
192
|
-
// https://docs.slatejs.org/concepts/06-editor
|
|
193
|
-
//
|
|
194
|
-
// First here gets executed last, so if you want to override behavior, push new
|
|
195
|
-
// extensions to the end of this list, to rely on default behavior implemented
|
|
196
|
-
// here.
|
|
197
|
-
export const extensions = [
|
|
198
|
-
withDeleteSelectionOnEnter,
|
|
199
|
-
withDeserializers,
|
|
200
|
-
insertData,
|
|
201
|
-
isInline,
|
|
202
|
-
normalizeNode,
|
|
203
|
-
normalizeExternalData,
|
|
204
|
-
];
|
|
205
|
-
|
|
206
|
-
// Default hotkeys and the format they trigger
|
|
207
|
-
export const hotkeys = {
|
|
208
|
-
'mod+b': { format: 'strong', type: 'inline' },
|
|
209
|
-
'mod+i': { format: 'em', type: 'inline' },
|
|
210
|
-
'mod+u': { format: 'u', type: 'inline' },
|
|
211
|
-
'mod+s': { format: 'del', type: 'inline' },
|
|
212
|
-
// 'mod+`': { format: 'code', type: 'inline' },
|
|
213
|
-
// TODO: more hotkeys, including from plugins!
|
|
214
|
-
};
|
|
215
|
-
|
|
216
|
-
// Raw shortcut/keydown handlers
|
|
217
|
-
export const keyDownHandlers = {};
|
|
218
|
-
|
|
219
|
-
// Paragraphs (as default type of blocks) and lists need special handling
|
|
220
|
-
export const listTypes = ['ul', 'ol'];
|
|
221
|
-
export const listItemType = 'li';
|
|
222
|
-
export const tableTypes = [
|
|
223
|
-
'table',
|
|
224
|
-
'tbody',
|
|
225
|
-
'thead',
|
|
226
|
-
'tfoot',
|
|
227
|
-
'tr',
|
|
228
|
-
'td',
|
|
229
|
-
'th',
|
|
230
|
-
];
|
|
231
|
-
export const defaultBlockType = 'p';
|
|
232
|
-
|
|
233
|
-
// Default rendered elements
|
|
234
|
-
// TODO: expose the IDs in constants.js, for uniformity
|
|
235
|
-
export const elements = {
|
|
236
|
-
default: ({ attributes, children }) => <p {...attributes}>{children}</p>,
|
|
237
|
-
|
|
238
|
-
h1: renderLinkElement('h1'),
|
|
239
|
-
h2: renderLinkElement('h2'),
|
|
240
|
-
h3: renderLinkElement('h3'),
|
|
241
|
-
h4: renderLinkElement('h4'),
|
|
242
|
-
|
|
243
|
-
li: ({ attributes, children }) => <li {...attributes}>{children}</li>,
|
|
244
|
-
ol: ({ attributes, children }) => <ol {...attributes}>{children}</ol>,
|
|
245
|
-
ul: ({ attributes, children }) => {
|
|
246
|
-
return <ul {...attributes}>{children}</ul>;
|
|
247
|
-
},
|
|
248
|
-
|
|
249
|
-
div: ({ attributes, children }) => <div {...attributes}>{children}</div>,
|
|
250
|
-
p: ({ attributes, children, element }) => <p {...attributes}>{children}</p>,
|
|
251
|
-
|
|
252
|
-
// While usual slate editor consider these to be Leafs, we treat them as
|
|
253
|
-
// inline elements because they can sometimes contain elements (ex:
|
|
254
|
-
// <b><a/></b>
|
|
255
|
-
em: ({ children }) => <em>{children}</em>,
|
|
256
|
-
i: ({ children }) => <i>{children}</i>,
|
|
257
|
-
b: ({ children }) => {
|
|
258
|
-
return <b>{children}</b>;
|
|
259
|
-
},
|
|
260
|
-
strong: ({ children }) => {
|
|
261
|
-
return <strong>{children}</strong>;
|
|
262
|
-
},
|
|
263
|
-
u: ({ children }) => <u>{children}</u>,
|
|
264
|
-
s: ({ children }) => <del>{children}</del>,
|
|
265
|
-
del: ({ children }) => <del>{children}</del>,
|
|
266
|
-
sub: ({ children }) => <sub>{children}</sub>,
|
|
267
|
-
sup: ({ children }) => <sup>{children}</sup>,
|
|
268
|
-
code: ({ children }) => <code>{children}</code>,
|
|
269
|
-
};
|
|
270
|
-
|
|
271
|
-
export const inlineElements = [
|
|
272
|
-
'em',
|
|
273
|
-
'i',
|
|
274
|
-
'b',
|
|
275
|
-
'strong',
|
|
276
|
-
'u',
|
|
277
|
-
'del',
|
|
278
|
-
'sub',
|
|
279
|
-
'sup',
|
|
280
|
-
'code',
|
|
281
|
-
];
|
|
282
|
-
|
|
283
|
-
// Order of definition here is important (higher = inner element)
|
|
284
|
-
export const leafs = {
|
|
285
|
-
// code: ({ children }) => {
|
|
286
|
-
// return <code>{children}</code>;
|
|
287
|
-
// },
|
|
288
|
-
};
|
|
289
|
-
|
|
290
|
-
export const defaultValue = () => {
|
|
291
|
-
return [createEmptyParagraph()];
|
|
292
|
-
};
|
|
293
|
-
|
|
294
|
-
// HTML deserialization (html -> slate data conversion)
|
|
295
|
-
// These are used in clipboard paste handling
|
|
296
|
-
// Any tag that is not listed here (or added by a plugin) will be stripped
|
|
297
|
-
// (its children will be rendered, though)
|
|
298
|
-
export const htmlTagsToSlate = {
|
|
299
|
-
B: bTagDeserializer,
|
|
300
|
-
BODY: bodyTagDeserializer,
|
|
301
|
-
CODE: codeTagDeserializer,
|
|
302
|
-
PRE: preTagDeserializer,
|
|
303
|
-
SPAN: spanTagDeserializer,
|
|
304
|
-
|
|
305
|
-
BLOCKQUOTE: blockTagDeserializer('blockquote'),
|
|
306
|
-
DEL: blockTagDeserializer('del'),
|
|
307
|
-
EM: blockTagDeserializer('em'),
|
|
308
|
-
H1: blockTagDeserializer('h1'),
|
|
309
|
-
H2: blockTagDeserializer('h2'),
|
|
310
|
-
H3: blockTagDeserializer('h3'),
|
|
311
|
-
H4: blockTagDeserializer('h4'),
|
|
312
|
-
H5: blockTagDeserializer('h5'),
|
|
313
|
-
H6: blockTagDeserializer('h6'),
|
|
314
|
-
I: blockTagDeserializer('i'),
|
|
315
|
-
P: blockTagDeserializer('p'),
|
|
316
|
-
S: blockTagDeserializer('del'),
|
|
317
|
-
STRONG: blockTagDeserializer('strong'),
|
|
318
|
-
SUB: blockTagDeserializer('sub'),
|
|
319
|
-
SUP: blockTagDeserializer('sup'),
|
|
320
|
-
U: blockTagDeserializer('u'),
|
|
321
|
-
|
|
322
|
-
OL: blockTagDeserializer('ol'),
|
|
323
|
-
UL: blockTagDeserializer('ul'),
|
|
324
|
-
LI: blockTagDeserializer('li'),
|
|
325
|
-
};
|
|
326
|
-
|
|
327
|
-
// Adds "highlight" decoration in the editor. Used by `highlightByType`
|
|
328
|
-
// See the Footnote plugin for an example.
|
|
329
|
-
export const nodeTypesToHighlight = [];
|
|
330
|
-
|
|
331
|
-
// "Runtime" decorator functions. These are transient decorations that are
|
|
332
|
-
// applied in the editor. They are not persisted in the final value, so they
|
|
333
|
-
// are useful for example to highlight search results or a certain type of node
|
|
334
|
-
// Signature: ([node, path], ranges) => ranges
|
|
335
|
-
export const runtimeDecorators = [highlightSelection]; // , highlightByType
|
|
336
|
-
|
|
337
|
-
// Only these types of element nodes are allowed in the headlines
|
|
338
|
-
export const allowedHeadlineElements = ['em', 'i'];
|
|
339
|
-
|
|
340
|
-
// Scroll into view when typing
|
|
341
|
-
export const scrollIntoView = true;
|
|
342
|
-
|
|
343
|
-
// In inline toolbar only one tag should be active at a time.
|
|
344
|
-
export const exclusiveElements = [['sup', 'sub']];
|
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
import { Node, Range } from 'slate';
|
|
2
|
-
// import { ReactEditor } from 'slate-react';
|
|
3
|
-
|
|
4
|
-
import config from '@plone/volto/registry';
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* highlightByType.
|
|
8
|
-
*
|
|
9
|
-
* @param {} editor
|
|
10
|
-
* @param {} node, path
|
|
11
|
-
* @param {} ranges
|
|
12
|
-
*/
|
|
13
|
-
export const highlightByType = (editor, [node, path], ranges) => {
|
|
14
|
-
const { slate } = config.settings;
|
|
15
|
-
const { nodeTypesToHighlight } = slate;
|
|
16
|
-
|
|
17
|
-
if (nodeTypesToHighlight.includes(node.type)) {
|
|
18
|
-
const [found] = Node.texts(editor, { from: path, to: path });
|
|
19
|
-
const visualSelectionRanges = highlightSelection(editor, found, ranges);
|
|
20
|
-
const text = Node.string(node) || '';
|
|
21
|
-
const range = {
|
|
22
|
-
anchor: { path, offset: 0 },
|
|
23
|
-
focus: { path, offset: text.length },
|
|
24
|
-
// we need to differentiate between multiple highlight types, the active
|
|
25
|
-
// selection and the highlighted node
|
|
26
|
-
highlight: true,
|
|
27
|
-
highlightType: visualSelectionRanges.length === 0 ? node.type : null,
|
|
28
|
-
isSelection: visualSelectionRanges.length > 0,
|
|
29
|
-
};
|
|
30
|
-
return [range];
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
return ranges;
|
|
34
|
-
};
|
|
35
|
-
|
|
36
|
-
/**
|
|
37
|
-
* @function highlightSelection
|
|
38
|
-
*
|
|
39
|
-
* @summary A runtime decorator that decorates the saved selection, when the editor is
|
|
40
|
-
* is no longer active.
|
|
41
|
-
*
|
|
42
|
-
* @param {Editor} editor The editor on which to apply the decorator.
|
|
43
|
-
* @param {Node} node
|
|
44
|
-
* @param {Path} path
|
|
45
|
-
* @param {Array} ranges
|
|
46
|
-
*/
|
|
47
|
-
export function highlightSelection(editor, [node, path], ranges) {
|
|
48
|
-
let selected = editor.isSelected();
|
|
49
|
-
// const focused = ReactEditor.isFocused(editor);
|
|
50
|
-
// TODO: handle the case when the editor is not focused, then use the
|
|
51
|
-
// editor.getSavedSelection()
|
|
52
|
-
|
|
53
|
-
if (selected && editor.selection) {
|
|
54
|
-
const selection = editor.selection;
|
|
55
|
-
if (JSON.stringify(path) === JSON.stringify(selection.anchor.path)) {
|
|
56
|
-
const range = {
|
|
57
|
-
...selection,
|
|
58
|
-
highlight: true,
|
|
59
|
-
highlightType: 'selection',
|
|
60
|
-
isSelection: true,
|
|
61
|
-
};
|
|
62
|
-
if (Range.isExpanded(range)) {
|
|
63
|
-
ranges.push(range);
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
return ranges;
|
|
68
|
-
}
|
|
@@ -1,185 +0,0 @@
|
|
|
1
|
-
import { jsx } from 'slate-hyperscript';
|
|
2
|
-
import { Text } from 'slate';
|
|
3
|
-
// import { isWhitespace } from '@plone/volto-slate/utils';
|
|
4
|
-
import { TD, TH, COMMENT, ELEMENT_NODE, TEXT_NODE } from '../constants';
|
|
5
|
-
|
|
6
|
-
import { collapseInlineSpace } from './utils';
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* Deserialize to a Slate Node, an Array of Slate Nodes or null
|
|
10
|
-
*
|
|
11
|
-
* One particularity of this function is that it tries to do
|
|
12
|
-
* a "perception-based" conversion. For example, in html, multiple whitespaces
|
|
13
|
-
* display as a single space. A new line character in text is actually rendered
|
|
14
|
-
* as a space, etc. So we try to meet user's expectations that when they
|
|
15
|
-
* copy/paste content, we'll preserve the aspect of their text.
|
|
16
|
-
*
|
|
17
|
-
* See https://developer.mozilla.org/en-US/docs/Web/API/Document_Object_Model/Whitespace
|
|
18
|
-
*/
|
|
19
|
-
export const deserialize = (
|
|
20
|
-
editor,
|
|
21
|
-
el,
|
|
22
|
-
options = { collapseWhitespace: true },
|
|
23
|
-
) => {
|
|
24
|
-
const { htmlTagsToSlate } = editor;
|
|
25
|
-
|
|
26
|
-
if (el.nodeType === COMMENT) {
|
|
27
|
-
return null;
|
|
28
|
-
} else if (el.nodeType === TEXT_NODE) {
|
|
29
|
-
const text = options.collapseWhitespace
|
|
30
|
-
? collapseInlineSpace(el)
|
|
31
|
-
: el.textContent;
|
|
32
|
-
return text
|
|
33
|
-
? {
|
|
34
|
-
text,
|
|
35
|
-
}
|
|
36
|
-
: null;
|
|
37
|
-
} else if (el.nodeType !== ELEMENT_NODE) {
|
|
38
|
-
return null;
|
|
39
|
-
} else if (el.nodeName === 'BR') {
|
|
40
|
-
// gets merged with sibling text nodes by Slate normalization in insertData
|
|
41
|
-
return { text: '\n' };
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
if (el.getAttribute('data-slate-data')) {
|
|
45
|
-
return typeDeserialize(editor, el, options);
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
const { nodeName } = el;
|
|
49
|
-
|
|
50
|
-
if (htmlTagsToSlate[nodeName]) {
|
|
51
|
-
return htmlTagsToSlate[nodeName](editor, el, options);
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
// fallback deserializer, all unknown elements are "stripped"
|
|
55
|
-
return deserializeChildren(el, editor, options);
|
|
56
|
-
};
|
|
57
|
-
|
|
58
|
-
export const typeDeserialize = (editor, el, options) => {
|
|
59
|
-
const jsData = el.getAttribute('data-slate-data');
|
|
60
|
-
const { type, data } = JSON.parse(jsData);
|
|
61
|
-
return jsx(
|
|
62
|
-
'element',
|
|
63
|
-
{ type, data },
|
|
64
|
-
deserializeChildren(el, editor, options),
|
|
65
|
-
);
|
|
66
|
-
};
|
|
67
|
-
|
|
68
|
-
export const deserializeChildren = (parent, editor, options) =>
|
|
69
|
-
Array.from(parent.childNodes)
|
|
70
|
-
.map((el) => deserialize(editor, el, options))
|
|
71
|
-
.flat();
|
|
72
|
-
|
|
73
|
-
export const blockTagDeserializer = (tagname) => (editor, el, options) => {
|
|
74
|
-
// if (tagname === 'h2') debugger;
|
|
75
|
-
let children = deserializeChildren(el, editor, options).filter(
|
|
76
|
-
(n) => n !== null,
|
|
77
|
-
);
|
|
78
|
-
|
|
79
|
-
if (
|
|
80
|
-
[TD, TH].includes(tagname) &&
|
|
81
|
-
children.length > 0 &&
|
|
82
|
-
typeof children[0] === 'string'
|
|
83
|
-
) {
|
|
84
|
-
// TODO: should here be handled the cases when there are more strings in
|
|
85
|
-
// `children` or when there are besides strings other types of nodes too?
|
|
86
|
-
const p = { type: 'div', children: [{ text: '' }] };
|
|
87
|
-
p.children[0].text = children[0];
|
|
88
|
-
children = [p];
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
// normalizes block elements so that they're never empty
|
|
92
|
-
// Avoids a hard crash from the Slate editor
|
|
93
|
-
const hasValidChildren = children.length && children.find((c) => !!c);
|
|
94
|
-
if (!hasValidChildren) {
|
|
95
|
-
children = [{ text: '' }];
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
return jsx('element', { type: tagname }, children);
|
|
99
|
-
};
|
|
100
|
-
|
|
101
|
-
export const bodyTagDeserializer = (editor, el, options) => {
|
|
102
|
-
return jsx('fragment', {}, deserializeChildren(el, editor, options));
|
|
103
|
-
};
|
|
104
|
-
|
|
105
|
-
export const inlineTagDeserializer = (attrs) => (editor, el, options) => {
|
|
106
|
-
return deserializeChildren(el, editor, options).map((child) => {
|
|
107
|
-
const res =
|
|
108
|
-
Text.isText(child) || typeof child === 'string'
|
|
109
|
-
? jsx('text', attrs, child)
|
|
110
|
-
: {
|
|
111
|
-
...child,
|
|
112
|
-
attrs, // pass the inline attrs as separate object
|
|
113
|
-
};
|
|
114
|
-
return res;
|
|
115
|
-
});
|
|
116
|
-
};
|
|
117
|
-
|
|
118
|
-
export const spanTagDeserializer = (editor, el, options) => {
|
|
119
|
-
const style = el.getAttribute('style') || '';
|
|
120
|
-
let children = el.childNodes;
|
|
121
|
-
|
|
122
|
-
if (
|
|
123
|
-
// handle formatting from OpenOffice
|
|
124
|
-
children.length === 1 &&
|
|
125
|
-
children[0].nodeType === TEXT_NODE &&
|
|
126
|
-
children[0].textContent === '\n'
|
|
127
|
-
) {
|
|
128
|
-
return jsx('text', {}, ' ');
|
|
129
|
-
}
|
|
130
|
-
children = deserializeChildren(el, editor, options);
|
|
131
|
-
|
|
132
|
-
// whitespace is replaced by deserialize() with null;
|
|
133
|
-
children = children.map((c) => (c === null ? '' : c));
|
|
134
|
-
|
|
135
|
-
// TODO: handle sub/sup as <sub> and <sup>
|
|
136
|
-
// Handle Google Docs' <sub> formatting
|
|
137
|
-
if (style.replace(/\s/g, '').indexOf('vertical-align:sub') > -1) {
|
|
138
|
-
const attrs = { sub: true };
|
|
139
|
-
return children.map((child) => {
|
|
140
|
-
return jsx('text', attrs, child);
|
|
141
|
-
});
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
// Handle Google Docs' <sup> formatting
|
|
145
|
-
if (style.replace(/\s/g, '').indexOf('vertical-align:super') > -1) {
|
|
146
|
-
const attrs = { sup: true };
|
|
147
|
-
return children.map((child) => {
|
|
148
|
-
return jsx('text', attrs, child);
|
|
149
|
-
});
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
const res = children.find((c) => typeof c !== 'string')
|
|
153
|
-
? children
|
|
154
|
-
: jsx('text', {}, children);
|
|
155
|
-
|
|
156
|
-
return res;
|
|
157
|
-
};
|
|
158
|
-
|
|
159
|
-
export const bTagDeserializer = (editor, el, options) => {
|
|
160
|
-
// Google Docs does weird things with <b> tag
|
|
161
|
-
return (el.getAttribute('id') || '').indexOf('docs-internal-guid') > -1
|
|
162
|
-
? deserializeChildren(el, editor, options)
|
|
163
|
-
: jsx('element', { type: 'b' }, deserializeChildren(el, editor, options));
|
|
164
|
-
};
|
|
165
|
-
|
|
166
|
-
export const codeTagDeserializer = (editor, el, options) => {
|
|
167
|
-
return jsx('element', { type: 'code' }, el.textContent);
|
|
168
|
-
};
|
|
169
|
-
|
|
170
|
-
export const preTagDeserializer = (editor, el, options) => {
|
|
171
|
-
// Based on Slate example implementation. Replaces <pre> tags with <code>.
|
|
172
|
-
// Comment: I don't know how good of an idea is this. I'd rather have two
|
|
173
|
-
// separate formats: "preserve whitespace" and "code". This feels like a hack
|
|
174
|
-
const { nodeName } = el;
|
|
175
|
-
let parent = el;
|
|
176
|
-
|
|
177
|
-
if (el.childNodes[0] && el.childNodes[0].nodeName === 'CODE') {
|
|
178
|
-
parent = el.childNodes[0];
|
|
179
|
-
return codeTagDeserializer(editor, parent, options);
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
return blockTagDeserializer(nodeName)(editor, parent, options);
|
|
183
|
-
};
|
|
184
|
-
|
|
185
|
-
export default deserialize;
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { Transforms, Range } from 'slate';
|
|
2
|
-
|
|
3
|
-
export const withDeleteSelectionOnEnter = (editor) => {
|
|
4
|
-
const { insertBreak } = editor;
|
|
5
|
-
|
|
6
|
-
editor.insertBreak = () => {
|
|
7
|
-
// if selection is expanded, delete it
|
|
8
|
-
if (editor?.selection && Range.isExpanded(editor.selection)) {
|
|
9
|
-
Transforms.delete(editor);
|
|
10
|
-
}
|
|
11
|
-
return insertBreak();
|
|
12
|
-
};
|
|
13
|
-
|
|
14
|
-
return editor;
|
|
15
|
-
};
|