diff --git a/app/package.json b/app/package.json index 99f89ab19b..20659f7e8d 100644 --- a/app/package.json +++ b/app/package.json @@ -40,7 +40,6 @@ "imask": "6.0.7", "lodash.assign": "4.2.0", "prismjs": "^1.19.0", - "prop-types": "15.7.2", "qhistory": "1.0.3", "react": "^18.2.0", "react-dom": "^18.2.0", diff --git a/changelog.md b/changelog.md index 7dc2f29be9..412618ab20 100644 --- a/changelog.md +++ b/changelog.md @@ -1,6 +1,7 @@ # 5.xx.xx - xx.xx.2024 **What's New** +* Remove 'prop-types' from UUI packages dependencies. Remove `uuiContextTypes` interface, since it was needed for already outdated React context API. * [Alert]: added support for size theming * [DataTable]: added support of column groups in table header. Read more - https://uui.epam.com/documents?id=advancedTables&mode=doc&category=tables&theme=electric#table_with_header_groups * [ErrorPage]: added field for additional message with support link (it works with `500, 503, default` errors), added support link for the site @@ -9,6 +10,11 @@ * [PickerInput]: fixed unnecessary api calls on body open with `minCharsToSearch` prop and search in body * [RTE]: fixed image caption not being visible when RTE initially in readonly mode * [DatePicker]: fixed body close if date picker input scrolled out from view +* [Modals]: prevent scrolling to the modal toggler because of focus return after modal close +* [RTE]: fixed scroll to the top of the editor after editor modal windows(Add image/link/video etc.) were close +* [RTE]: fixed error while merging cells without content +* [RTE]: fixed bug when files added from attachment button inserted in preview mode instead of attachment block +* [RTE]: fixed crash when removing the sole table row # 5.11.0 - 15.11.2024 diff --git a/epam-electric/package.json b/epam-electric/package.json index 3615bcfb6b..b19ef96a85 100644 --- a/epam-electric/package.json +++ b/epam-electric/package.json @@ -20,7 +20,6 @@ "mockdate": "^3.0.5" }, "peerDependencies": { - "prop-types": "*", "react": ">=16.0.0", "react-dom": ">=16.0.0" }, diff --git a/epam-promo/package.json b/epam-promo/package.json index e7c7b40533..9433b7ee6d 100644 --- a/epam-promo/package.json +++ b/epam-promo/package.json @@ -20,7 +20,6 @@ "classnames": "2.2.6" }, "peerDependencies": { - "prop-types": "*", "react": ">=16.0.0", "react-dom": ">=16.0.0" }, diff --git a/extra/package.json b/extra/package.json index 72735aecce..aa9c31bdd4 100644 --- a/extra/package.json +++ b/extra/package.json @@ -17,7 +17,6 @@ "immutable": "3.8.2" }, "peerDependencies": { - "prop-types": "*", "react": ">=16.0.0", "react-dom": ">=16.0.0" }, diff --git a/loveship/package.json b/loveship/package.json index 1ecddaa308..af7dfaccdc 100644 --- a/loveship/package.json +++ b/loveship/package.json @@ -20,7 +20,6 @@ "classnames": "2.2.6" }, "peerDependencies": { - "prop-types": "*", "react": ">=16.0.0", "react-dom": ">=16.0.0" }, diff --git a/uui-components/package.json b/uui-components/package.json index 064d404d1e..9744b90003 100644 --- a/uui-components/package.json +++ b/uui-components/package.json @@ -28,7 +28,6 @@ "react-transition-group": "4.4.5" }, "peerDependencies": { - "prop-types": "*", "react": ">=16.0.0", "react-dom": ">=16.0.0" }, diff --git a/uui-components/src/overlays/ModalBlocker.tsx b/uui-components/src/overlays/ModalBlocker.tsx index 948fb50187..891ead3b58 100644 --- a/uui-components/src/overlays/ModalBlocker.tsx +++ b/uui-components/src/overlays/ModalBlocker.tsx @@ -53,7 +53,7 @@ export const ModalBlocker = React.forwardRef( onClick={ handleBlockerClick } aria-label="Click to close a modal" /> - + {props.children} diff --git a/uui-core/package.json b/uui-core/package.json index eb141e6775..e40c28dbaf 100644 --- a/uui-core/package.json +++ b/uui-core/package.json @@ -24,7 +24,6 @@ "react-popper": "2.3.0" }, "peerDependencies": { - "prop-types": "*", "react": ">=16.0.0", "react-dom": ">=16.0.0" }, diff --git a/uui-core/src/types/contexts.ts b/uui-core/src/types/contexts.ts index 3bbbf1c95b..a11fe63d03 100644 --- a/uui-core/src/types/contexts.ts +++ b/uui-core/src/types/contexts.ts @@ -1,5 +1,4 @@ import { AnalyticsEvent, Link } from './objects'; -import * as PropTypes from 'prop-types'; import { IModal, INotification } from './props'; import { DndContextState, TMouseCoords } from '../services/dnd/DndContext'; import { Lock } from '../services/LockContext'; @@ -293,20 +292,3 @@ export interface CommonContexts extends UuiContexts { /** React router history instance */ history?: IHistory4; } - -export const uuiContextTypes = { - uuiAnalytics: PropTypes.object, - uuiErrors: PropTypes.object, - uuiApi: PropTypes.object, - uuiModals: PropTypes.object, - uuiNotifications: PropTypes.object, - api: PropTypes.object, - uuiUserSettings: PropTypes.object, - uuiDnD: PropTypes.object, - uuiApp: PropTypes.object, - uuiRouter: PropTypes.object, - uuiLayout: PropTypes.object, - uuiLocks: PropTypes.object, - history: PropTypes.object, - uuiSkin: PropTypes.object, -}; diff --git a/uui-db/package.json b/uui-db/package.json index d4018974a4..d36e33ddf2 100644 --- a/uui-db/package.json +++ b/uui-db/package.json @@ -47,7 +47,6 @@ "ts-node": "10.9.1" }, "peerDependencies": { - "prop-types": "*", "react": ">=16.0.0", "react-dom": ">=16.0.0" }, diff --git a/uui-docs/package.json b/uui-docs/package.json index 9735d02ebf..599d34d721 100644 --- a/uui-docs/package.json +++ b/uui-docs/package.json @@ -21,7 +21,6 @@ "classnames": "^2.2.6" }, "peerDependencies": { - "prop-types": "*", "react": ">=16.0.0", "react-dom": ">=16.0.0" }, diff --git a/uui-docs/src/demoData/slateInitialValue.ts b/uui-docs/src/demoData/slateInitialValue.ts index c49873634d..f58f77ca4b 100644 --- a/uui-docs/src/demoData/slateInitialValue.ts +++ b/uui-docs/src/demoData/slateInitialValue.ts @@ -10,7 +10,7 @@ export const slateInitialValue = [ ], }, { - type: 'uui-richTextEditor-header-3', + type: 'uui-richTextEditor-header-2', data: {}, children: [ { @@ -24,8 +24,16 @@ export const slateInitialValue = [ data: {}, children: [ { - text: '@epam/uui-editor package contains a full-featured Rich Text Editor, based on open-source ', + text: 'The ', + }, + { + text: '@epam/uui-editor', 'uui-richTextEditor-span-mark': true, + 'uui-richTextEditor-code': true, + }, + { + 'uui-richTextEditor-span-mark': true, + text: ' package contains a full-featured Rich Text Editor, based on open-source ', }, { type: 'link', @@ -107,9 +115,7 @@ export const slateInitialValue = [ }, { type: 'uui-richTextEditor-header-3', - data: { - checked: false, - }, + data: {}, children: [ { text: 'Basic layout', @@ -151,13 +157,13 @@ export const slateInitialValue = [ 'uui-richTextEditor-underlined': true, }, { - text: ' several UUI-friendly text colors: ', + text: ' align with several UUI-friendly text colors: ', 'uui-richTextEditor-span-mark': true, }, { text: 'red', - color: '#FF4E33', 'uui-richTextEditor-span-mark': true, + color: 'var(--uui-text-critical)', }, { text: ', ', @@ -165,29 +171,35 @@ export const slateInitialValue = [ }, { text: 'yellow', - color: '#FFA21D', 'uui-richTextEditor-span-mark': true, + color: 'var(--uui-text-warning)', }, { text: ', and ', 'uui-richTextEditor-span-mark': true, }, { - text: 'green.', + text: 'green', + 'uui-richTextEditor-span-mark': true, + color: 'var(--uui-text-success)', + }, + { color: '#9BC837', 'uui-richTextEditor-span-mark': true, + text: '.', }, ], }, { - type: 'paragraph', + type: 'uui-richTextEditor-header-3', data: { checked: false, }, children: [ { - text: 'Numbered lists:', + text: 'Numbered lists', 'uui-richTextEditor-span-mark': true, + 'uui-richTextEditor-bold': true, }, ], }, @@ -206,9 +218,12 @@ export const slateInitialValue = [ }, children: [ { - text: "In edit mode, we detect '1.' and start list automatically", + text: 'In edit mode, ', 'uui-richTextEditor-span-mark': true, }, + { + text: "typing '1.' automatically starts a numbered list.", + }, ], }, ], @@ -224,9 +239,12 @@ export const slateInitialValue = [ }, children: [ { - text: "You can use 'tab' / 'shift/tab' to indent the list", + text: "You can use 'Tab' / 'Shift+Tab' to ", 'uui-richTextEditor-span-mark': true, }, + { + text: "adjust the list's indentation level.", + }, ], }, ], @@ -234,14 +252,15 @@ export const slateInitialValue = [ ], }, { - type: 'paragraph', + type: 'uui-richTextEditor-header-3', data: { checked: false, }, children: [ { - text: 'Bullet lists:', + text: 'Bullet lists', 'uui-richTextEditor-span-mark': true, + 'uui-richTextEditor-bold': true, }, ], }, @@ -260,9 +279,12 @@ export const slateInitialValue = [ }, children: [ { - text: "Type '- ' to start the list", + text: "Type '- ' ", 'uui-richTextEditor-span-mark': true, }, + { + text: 'to start a bullet list.', + }, ], }, ], @@ -278,7 +300,10 @@ export const slateInitialValue = [ }, children: [ { - text: "You can create multi-level lists with 'tab' / 'shift+tab'. Example:", + text: 'Create multi-level lists using', + }, + { + text: " 'Tab' / 'Shift+Tab'. Example:", 'uui-richTextEditor-span-mark': true, }, ], @@ -335,39 +360,113 @@ export const slateInitialValue = [ }, ], }, + { + type: 'h5', + children: [ + { + text: 'Headers and Links', + 'uui-richTextEditor-bold': true, + }, + ], + }, { type: 'paragraph', + children: [ + { + text: 'We also support three levels of headers, ', + }, + { + type: 'link', + url: 'https://uui.epam.com/', + target: '_blank', + children: [ + { + text: 'hyperlinks', + }, + ], + }, + { + text: ', ', + }, + { + text: 'superscript', + 'uui-richTextEditor-superscript': true, + }, + { + text: ', and more.', + }, + ], + }, + { + type: 'uui-richTextEditor-header-2', data: { checked: false, }, children: [ { - text: "There's also support 3 levels of headers, hyperlinks, superscript, and more.", + text: 'Embedded content', 'uui-richTextEditor-span-mark': true, }, ], }, { - type: 'uui-richTextEditor-header-3', + type: 'paragraph', data: { checked: false, }, children: [ { - text: 'Embedded content', - 'uui-richTextEditor-span-mark': true, + text: 'You can embed various types of content into the editor:', }, ], }, { - type: 'paragraph', + type: 'uui-richTextEditor-header-3', data: { checked: false, }, children: [ { - text: 'Files can be dropped directly into the editor. You can embed images (align and resizing is supported):', - 'uui-richTextEditor-span-mark': true, + text: 'Images', + 'uui-richTextEditor-bold': true, + }, + ], + }, + { + type: 'unordered-list', + children: [ + { + type: 'list-item', + children: [ + { + type: 'list-item-child', + children: [ + { + text: 'Embed images via the ', + }, + { + text: '"Add Image"', + 'uui-richTextEditor-bold': true, + }, + { + text: ' icon, drag-and-drop from your computer, or insert a direct internet address link.', + }, + ], + }, + ], + }, + { + type: 'list-item', + children: [ + { + type: 'list-item-child', + children: [ + { + text: 'Images support alignment and resizing.', + }, + ], + }, + ], }, ], }, @@ -383,7 +482,7 @@ export const slateInitialValue = [ }, url: '/static/uploads/blue-orange.jpg', align: 'center', - width: 800, + width: 862, height: 417, children: [ { @@ -393,72 +492,180 @@ export const slateInitialValue = [ ], caption: [ { - text: 'Image caption', + text: 'Picture from a file', }, ], }, { type: 'paragraph', - data: { - checked: false, - }, children: [ { - text: 'Video:', - 'uui-richTextEditor-span-mark': true, + text: '', + }, + ], + }, + { + align: 'center', + url: 'https://c.files.bbci.co.uk/D8CD/production/_117310555_16.jpg', + width: 862, + type: 'image', + children: [ + { + text: '', + }, + ], + caption: [ + { + text: 'Picture from the internet', + }, + ], + }, + { + type: 'uui-richTextEditor-header-3', + children: [ + { + text: 'PDFs', + 'uui-richTextEditor-bold': true, + }, + ], + }, + { + type: 'paragraph', + children: [ + { + text: 'Embed PDFs via the ', + }, + { + text: '"Add PDF" ', + 'uui-richTextEditor-bold': true, + }, + { + text: 'icon or drag-and-drop.', }, ], }, { type: 'iframe', - data: {}, - url: 'https://www.youtube.com/embed/5qap5aO4i9A', children: [ { text: '', - 'uui-richTextEditor-span-mark': true, + }, + ], + data: {}, + url: 'https://pdfobject.com/pdf/sample.pdf', + }, + { + type: 'uui-richTextEditor-header-3', + children: [ + { + text: 'Files', + 'uui-richTextEditor-bold': true, }, ], }, { type: 'paragraph', + children: [ + { + text: 'Upload arbitrary files using the ', + }, + { + text: '"Add Attachment"', + 'uui-richTextEditor-bold': true, + }, + { + text: ' icon. Files appear as downloadable links.', + }, + ], + }, + { + type: 'attachment', data: { - checked: false, + path: '/static/uploads/blue-orange.jpg', + name: 'Excel.xlsx', + size: 8710, + id: 1, + type: 'attachment', + extension: 'xlsx', + fileName: 'DemoExcelAttachment.xlsx', }, children: [ { - text: 'Arbitrary attachments:', - 'uui-richTextEditor-span-mark': true, + text: '', }, ], }, { type: 'attachment', data: { - path: '/static/uploads/DemoExcelAttachment.xlsx', - name: 'DemoExcelAttachment.xlsx', - size: 8669, - id: '100500', + path: '/static/uploads/blue-orange.jpg', + name: 'Word.docx', + size: 11943, + id: 2, type: 'attachment', - fileName: 'DemoExcelAttachment.xlsx', - extension: 'xlsx', + extension: 'docx', + fileName: 'DemoWordAttachment.docx', }, - url: '/static/uploads/DemoExcelAttachment.xlsx', children: [ { text: '', - 'uui-richTextEditor-span-mark': true, + }, + ], + }, + { + type: 'attachment', + data: { + path: '/static/uploads/blue-orange.jpg', + name: '5mb-file.txt', + size: 5000000, + id: 4, + type: 'attachment', + extension: 'txt', + fileName: 'DemoTxtAttachment.txt', + }, + children: [ + { + text: '', + }, + ], + }, + { + type: 'uui-richTextEditor-header-3', + data: { + checked: false, + }, + children: [ + { + text: 'Videos', + 'uui-richTextEditor-bold': true, }, ], }, { type: 'paragraph', - data: {}, children: [ { - text: 'You can also embed any arbitrary content, like PDF files, directly into the document, inside IFrame.', + text: 'Embed videos via the ', + }, + { + text: '"Add Video"', + 'uui-richTextEditor-bold': true, + }, + { + text: ' icon.', + }, + ], + }, + { + type: 'iframe', + children: [ + { + text: '', + 'uui-richTextEditor-span-mark': true, }, ], + data: {}, + url: 'https://www.youtube.com/embed/jfKfPfyJRdk', }, { type: 'uui-richTextEditor-header-3', @@ -480,22 +687,12 @@ export const slateInitialValue = [ }, { type: 'table', - data: {}, - colSizes: [ - 130, - 200, - 200, - 183, - 161, - ], children: [ { type: 'table_row', - data: {}, children: [ { type: 'table_header_cell', - data: {}, children: [ { type: 'paragraph', @@ -510,8 +707,6 @@ export const slateInitialValue = [ }, { type: 'table_header_cell', - data: {}, - colSpan: 2, children: [ { type: 'paragraph', @@ -523,10 +718,11 @@ export const slateInitialValue = [ ], }, ], + colSpan: 2, + rowSpan: 1, }, { type: 'table_header_cell', - data: {}, children: [ { type: 'paragraph', @@ -543,12 +739,9 @@ export const slateInitialValue = [ }, { type: 'table_row', - data: {}, children: [ { type: 'table_cell', - data: {}, - rowSpan: 2, children: [ { type: 'paragraph', @@ -560,10 +753,11 @@ export const slateInitialValue = [ ], }, ], + colSpan: 1, + rowSpan: 2, }, { type: 'table_cell', - data: {}, children: [ { type: 'paragraph', @@ -575,10 +769,11 @@ export const slateInitialValue = [ ], }, ], + rowSpan: 1, + colSpan: 1, }, { type: 'table_cell', - data: {}, children: [ { type: 'paragraph', @@ -590,10 +785,11 @@ export const slateInitialValue = [ ], }, ], + rowSpan: 1, + colSpan: 1, }, { type: 'table_cell', - data: {}, children: [ { type: 'paragraph', @@ -610,14 +806,13 @@ export const slateInitialValue = [ ], }, ], + size: 47, }, { type: 'table_row', - data: {}, children: [ { type: 'table_cell', - data: {}, children: [ { type: 'paragraph', @@ -629,10 +824,11 @@ export const slateInitialValue = [ ], }, ], + colSpan: 1, + rowSpan: 1, }, { type: 'table_cell', - data: {}, children: [ { type: 'paragraph', @@ -644,10 +840,11 @@ export const slateInitialValue = [ ], }, ], + colSpan: 1, + rowSpan: 1, }, { type: 'table_cell', - data: {}, children: [ { type: 'paragraph', @@ -662,17 +859,16 @@ export const slateInitialValue = [ ], }, ], + colSpan: 1, + rowSpan: 1, }, ], }, { type: 'table_row', - data: {}, children: [ { type: 'table_cell', - data: {}, - rowSpan: 1, children: [ { type: 'paragraph', @@ -684,11 +880,11 @@ export const slateInitialValue = [ ], }, ], + colSpan: 1, + rowSpan: 1, }, { type: 'table_cell', - data: {}, - rowSpan: 1, children: [ { type: 'paragraph', @@ -700,11 +896,11 @@ export const slateInitialValue = [ ], }, ], + colSpan: 1, + rowSpan: 1, }, { type: 'table_cell', - data: {}, - rowSpan: 1, children: [ { type: 'paragraph', @@ -716,11 +912,11 @@ export const slateInitialValue = [ ], }, ], + colSpan: 1, + rowSpan: 1, }, { type: 'table_cell', - data: {}, - rowSpan: 1, children: [ { type: 'paragraph', @@ -735,20 +931,20 @@ export const slateInitialValue = [ ], }, ], + colSpan: 1, + rowSpan: 1, }, ], + size: 47, }, { type: 'table_row', - data: {}, children: [ { type: 'table_cell', - data: {}, children: [ { type: 'paragraph', - data: {}, children: [ { text: '', @@ -756,11 +952,11 @@ export const slateInitialValue = [ ], }, ], + colSpan: 1, + rowSpan: 1, }, { type: 'table_cell', - data: {}, - colSpan: 3, children: [ { type: 'paragraph', @@ -772,17 +968,27 @@ export const slateInitialValue = [ ], }, ], + colSpan: 3, + rowSpan: 1, }, ], + size: 46, }, ], + data: {}, + colSizes: [ + 200, + 154, + 150, + 189, + ], }, { type: 'uui-richTextEditor-header-3', data: {}, children: [ { - text: 'Placeholders:', + text: 'Placeholders', }, ], }, @@ -791,7 +997,7 @@ export const slateInitialValue = [ data: {}, children: [ { - text: 'Allows to insert ', + text: '', }, { type: 'placeholder', @@ -806,16 +1012,7 @@ export const slateInitialValue = [ ], }, { - text: " into text. Can be used for editing templates, for example for emails. Placeholders can be then replaced with real values programmatically (currently that's done by some apps in back-end code).", - }, - ], - }, - { - type: 'paragraph', - data: {}, - children: [ - { - text: '', + text: ' can be inserted into text and are useful for creating editable templates, such as emails. These placeholders can be programmatically replaced with real values (currently handled by some apps in back-end code).', }, ], }, @@ -824,7 +1021,7 @@ export const slateInitialValue = [ data: {}, children: [ { - text: 'Misc features', + text: 'Miscellaneous Features', }, ], }, @@ -901,4 +1098,4 @@ export const slateInitialValue = [ }, ], }, -] as any; +]; diff --git a/uui-editor/src/migrations/normalizers.ts b/uui-editor/src/migrations/normalizers.ts index 5685652d95..2290d691d1 100644 --- a/uui-editor/src/migrations/normalizers.ts +++ b/uui-editor/src/migrations/normalizers.ts @@ -32,6 +32,7 @@ export const normalizeTableCellElement = (editor: PlateEditor, entry: TNo cellNode, { at: path }, ); + return; } }; diff --git a/uui-editor/src/plugins/tablePlugin/ToolbarContent.tsx b/uui-editor/src/plugins/tablePlugin/ToolbarContent.tsx index 04e0361382..99ff4b7aaf 100644 --- a/uui-editor/src/plugins/tablePlugin/ToolbarContent.tsx +++ b/uui-editor/src/plugins/tablePlugin/ToolbarContent.tsx @@ -14,6 +14,7 @@ import { ToolbarButton } from '../../implementation/ToolbarButton'; import { useEditorRef } from '@udecode/plate-common'; import { getTableEntries, insertTableColumn, insertTableRow, deleteRow, deleteTable, unmergeTableCells, deleteColumn } from '@udecode/plate-table'; import { TABLE_HEADER_CELL_TYPE } from './constants'; +import { temporaryFixDeleteRow } from './temporaryFixDeleteRow'; function StyledRemoveTable() { return ; @@ -72,7 +73,7 @@ export function TableToolbarContent({ canUnmerge }:{ canUnmerge:boolean }) { /> deleteRow(editor) } + onClick={ temporaryFixDeleteRow(editor, () => deleteRow(editor)) } icon={ RemoveRow } /> => if (isElement(node) && (TABLE_CELL_TYPE === node.type || TABLE_CELL_TYPE === node.type)) { normalizeTableCellElement(editor, entry); - return; } normalizeNode(entry); diff --git a/uui-editor/src/plugins/tablePlugin/temporaryFixDeleteRow.ts b/uui-editor/src/plugins/tablePlugin/temporaryFixDeleteRow.ts new file mode 100644 index 0000000000..18e78632fa --- /dev/null +++ b/uui-editor/src/plugins/tablePlugin/temporaryFixDeleteRow.ts @@ -0,0 +1,25 @@ +import { isType, type PlateEditor, getBlockAbove } from '@udecode/plate-common'; +import { TABLE_TYPE } from './constants'; +import type { TableElementType } from './types'; + +/** +* Remove fix wrapper function when `@udecode/plate-table` will be updated to 40.0.0 +* See {@link https://github.com/udecode/plate/blob/f8fa0e7f4c0b4dd3ab445fd0aa55738db1596de9/packages/table/CHANGELOG.md#4000} for details +*/ +export const temporaryFixDeleteRow = (editor: PlateEditor, deleteRowFn: () => void) => { + return () => { + const tableElement = getBlockAbove(editor, { match: (node) => isType(editor, node, TABLE_TYPE) }); + + if (!tableElement) { + return; + } + + const [tableNode] = tableElement; + + if (tableNode.children.length <= 1) { + return; + } + + deleteRowFn(); + }; +}; diff --git a/uui-editor/src/plugins/uploadFilePlugin/file_uploader.ts b/uui-editor/src/plugins/uploadFilePlugin/file_uploader.ts index 966e88f897..73d85dd3c0 100644 --- a/uui-editor/src/plugins/uploadFilePlugin/file_uploader.ts +++ b/uui-editor/src/plugins/uploadFilePlugin/file_uploader.ts @@ -82,14 +82,17 @@ const isValidFileType = (fileType?: string) => { const buildFragments = ( files: FileUploadResponse[], + blockType?: UploadType, ) => { return files.map((file: FileUploadResponse) => { const fileType = file.type; - const uploadType = ( - isValidFileType(fileType) ? fileType : ATTACHMENT_TYPE - ) as UploadType; + if (blockType) { + return UPLOAD_BLOCKS[blockType](file); + } else { + const blockTypeByFile = (isValidFileType(fileType) ? fileType : ATTACHMENT_TYPE) as UploadType; - return UPLOAD_BLOCKS[uploadType](file); + return UPLOAD_BLOCKS[blockTypeByFile](file); + } }); }; @@ -97,6 +100,7 @@ export const createFileUploader = (options?: UploadFileOptions) => async ( editor: PlateEditor, files: File[], + blockType: UploadType, ) => { const uploadFile = options?.uploadFile; if (!uploadFile) return; @@ -127,7 +131,7 @@ export const createFileUploader = (options?: UploadFileOptions) => } // build fragments - const fileFragments = buildFragments(res); + const fileFragments = buildFragments(res, blockType); // remove loader removeLoader(); @@ -138,14 +142,14 @@ export const createFileUploader = (options?: UploadFileOptions) => export const useFilesUploader = (editor: PlateEditor) => { return useCallback( - (files: File[], overriddenAction?: UploadType): Promise => { + (files: File[], blockType?: UploadType): Promise => { const callback = getPlugin(editor, UPLOAD_PLUGIN_KEY)?.options.uploadFiles; if (callback) { return callback( editor, files, - overriddenAction, + blockType, ); } diff --git a/uui/package.json b/uui/package.json index 7c4c684e72..5fda3cfaff 100644 --- a/uui/package.json +++ b/uui/package.json @@ -22,7 +22,6 @@ "react-popper": "2.3.0" }, "peerDependencies": { - "prop-types": "*", "react": ">=16.0.0", "react-dom": ">=16.0.0" },