Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/develop' into authoring-react-po…
Browse files Browse the repository at this point in the history
…st-broadcasting
  • Loading branch information
petrjasek committed Oct 6, 2023
2 parents 1e5b20b + 24e7cdc commit 2e4296c
Show file tree
Hide file tree
Showing 12 changed files with 969 additions and 111 deletions.
3 changes: 3 additions & 0 deletions .fireq.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"superdesk_branch": "release/2.5"
}
2 changes: 1 addition & 1 deletion e2e/server/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM python:3.8
FROM python:3.10

ADD requirements.txt .
RUN pip3 install -U pip wheel setuptools
Expand Down
2 changes: 1 addition & 1 deletion e2e/server/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#
# This file is autogenerated by pip-compile with Python 3.10
# This file is autogenerated by pip-compile with Python 3.8
# by the following command:
#
# pip-compile requirements.in
Expand Down
249 changes: 146 additions & 103 deletions package-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "superdesk-core",
"version": "2.6.1",
"version": "2.6.2",
"license": "AGPL-3.0",
"repository": {
"type": "git",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,7 @@ export function ArticleEditDirective(
scope.item.body_footer = scope.item.body_footer + scope.extra.body_footer_value.value;
mainEditScope.dirty = true;
autosave.save(scope.item, scope.origItem);
scope.refreshTrigger++;
scope.refresh();
}

scope.refresh(); // reload footer editorState from HTML that was set here
Expand Down
2 changes: 1 addition & 1 deletion scripts/core/editor3/components/handlePastedText.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ export function handlePastedText(text: string, _html: string): DraftHandleValue
return 'handled';
}

if (htmlComesFromDraftjsEditor(html)) {
if (htmlComesFromDraftjsEditor(html, false)) {
return 'not-handled';
}

Expand Down
19 changes: 19 additions & 0 deletions scripts/core/editor3/components/tests/handlePastedText.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import {cursorAtEndPosition, cursorAtPosition} from './utils';
import {insertContentInState, createHtmlFromText} from '../handlePastedText';
import {getAnnotationsFromContentState} from 'core/editor3/helpers/editor3CustomData';
import {getContentStateFromHtml} from 'core/editor3/html/from-html';
import {htmlComesFromDraftjsEditor} from 'core/editor3/helpers/htmlComesFromDraftjsEditor';
import HTML_WITH_TABLE from './pastedHtmlWithTable.html';

describe('editor3.handlePastedText', () => {
it('should insert text without selection', () => {
Expand Down Expand Up @@ -111,4 +113,21 @@ describe('editor3.handlePastedText', () => {

expect(contentState.getPlainText('\n')).toEqual(text);
});

it('should handle table blocks', () => {
const contentState = getContentStateFromHtml(HTML_WITH_TABLE);
const blocks = contentState.getBlocksAsArray();

expect(htmlComesFromDraftjsEditor(HTML_WITH_TABLE, false)).toBe(false);

expect(blocks.length).toBe(2);
expect(blocks[0].getType()).toBe("atomic");

const entity = contentState.getEntity(blocks[0].getEntityAt(0));
expect(entity.getType()).toBe("TABLE");

const tableData = entity.getData().data;
expect(tableData.numRows).toBe(6);
expect(tableData.numCols).toBe(4);
});
});
765 changes: 765 additions & 0 deletions scripts/core/editor3/components/tests/pastedHtmlWithTable.html

Large diffs are not rendered by default.

9 changes: 7 additions & 2 deletions scripts/core/editor3/helpers/htmlComesFromDraftjsEditor.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,7 @@
export const htmlComesFromDraftjsEditor = (html: string) =>
new DOMParser().parseFromString(html, 'text/html').querySelector('[data-offset-key]') != null;
export const htmlComesFromDraftjsEditor = (html: string, allowTables = true) => {
const tree = new DOMParser().parseFromString(html, 'text/html');

return tree.querySelector('[data-offset-key]') != null && (
allowTables || tree.getElementsByClassName('table-inside').length === 0
);
};
22 changes: 22 additions & 0 deletions scripts/core/editor3/html/from-html/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,8 @@ class HTMLParser {
* about the HTML that was extracted.
*/
pruneNodes() {
this.cleanUpDraftTables();

this.tree.html(this.manageEmbeds(this.tree.html()));

this.tree.find('iframe').each((i, node) => {
Expand Down Expand Up @@ -357,6 +359,26 @@ class HTMLParser {

return atomicBlock(block, 'MEDIA', 'MUTABLE', mediaJson);
}

/**
* When copy&pasting between windows without editor instance around
* we just get internal draft html with editors inside table which
* is not feasible for parsing, so replace the inner editor markup
* with the contents of the span inside.
*/
cleanUpDraftTables() {
const handleInnerEditor = (i, elem) => {
const content = elem.querySelector('span[data-text="true"]').innerHTML;

elem.innerHTML = content;
};

this.tree.find('.table-inside > table').each((i, table) => {
$(table).find('th').each(handleInnerEditor);
$(table).find('td').each(handleInnerEditor);
$(table).closest('figure').replaceWith(table);
});
}
}

export function getContentStateFromHtml(html: string, associations: object = {}): ContentState {
Expand Down
3 changes: 2 additions & 1 deletion scripts/core/superdesk-api.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1479,7 +1479,7 @@ declare module 'superdesk-api' {
preffered_items?: boolean;
tags?: Array<IVocabularyTag>;
disable_entire_category_selection?: boolean;
selection_type?: any;
selection_type?: 'single selection' | 'multi selection' | 'do not show';
}

export interface IArticleField extends IVocabulary {
Expand Down Expand Up @@ -2845,6 +2845,7 @@ declare module 'superdesk-api' {
): string;
};
privileges: {
getOwnPrivileges(): Promise<IUserPrivileges>;
hasPrivilege(privilege: string): boolean;
};
preferences: {
Expand Down

0 comments on commit 2e4296c

Please sign in to comment.