Browse Source

Load properly the editor with document components. Fixes #6116

pull/6121/head
Artur Arseniev 2 years ago
parent
commit
b0dda8d2dc
  1. 6
      packages/core/src/dom_components/model/ComponentWrapper.ts
  2. 8
      packages/core/test/specs/dom_components/index.ts

6
packages/core/src/dom_components/model/ComponentWrapper.ts

@ -32,15 +32,17 @@ export default class ComponentWrapper extends Component {
constructor(...args: ConstructorParameters<typeof Component>) { constructor(...args: ConstructorParameters<typeof Component>) {
super(...args); super(...args);
const props = args[0] || {};
const opts = args[1]; const opts = args[1];
const cmp = opts?.em?.Components; const cmp = opts?.em?.Components;
const CmpHead = cmp?.getType(typeHead)?.model; const CmpHead = cmp?.getType(typeHead)?.model;
const CmpDef = cmp?.getType('default').model; const CmpDef = cmp?.getType('default').model;
if (CmpHead) { if (CmpHead) {
this.set( this.set(
{ {
head: new CmpHead({}, opts), head: new CmpHead({ ...props.head }, opts),
docEl: new CmpDef({ tagName: 'html' }, opts), docEl: new CmpDef({ tagName: 'html', ...props.docEl }, opts),
}, },
{ silent: true }, { silent: true },
); );

8
packages/core/test/specs/dom_components/index.ts

@ -390,8 +390,8 @@ describe('DOM Components', () => {
let projectData: ProjectData; let projectData: ProjectData;
const docHtml = ` const docHtml = `
<!DOCTYPE html> <!DOCTYPE html>
<html> <html lang="en">
<head> <head class="cls-head">
<title>ABC</title> <title>ABC</title>
</head> </head>
<body> <body>
@ -412,8 +412,8 @@ describe('DOM Components', () => {
const newRoot = editor.getWrapper()!; const newRoot = editor.getWrapper()!;
const { head, doctype } = newRoot; const { head, doctype } = newRoot;
// expect(head.components().length).toBe(1); expect(head.components().length).toBe(1);
// expect(doctype).toBe('<!DOCTYPE html>'); expect(doctype).toBe('<!DOCTYPE html>');
expect(newRoot.toHTML()).toBe(flattenHTML(docHtml)); expect(newRoot.toHTML()).toBe(flattenHTML(docHtml));
}); });

Loading…
Cancel
Save