|
|
|
@ -1,12 +1,13 @@ |
|
|
|
import { isEmpty, isArray, isString, isFunction, each, includes, extend, flatten, keys } from 'underscore'; |
|
|
|
import Component from './Component'; |
|
|
|
import { AddOptions, Collection, ObjectAny } from '../../common'; |
|
|
|
import { AddOptions, Collection, ObjectAny, OptionAsDocument } from '../../common'; |
|
|
|
import { DomComponentsConfig } from '../config/config'; |
|
|
|
import EditorModel from '../../editor/model/Editor'; |
|
|
|
import ComponentManager from '..'; |
|
|
|
import CssRule from '../../css_composer/model/CssRule'; |
|
|
|
import { ComponentAdd, ComponentProperties } from './types'; |
|
|
|
import ComponentText from './ComponentText'; |
|
|
|
import ComponentWrapper from './ComponentWrapper'; |
|
|
|
|
|
|
|
export const getComponentIds = (cmp?: Component | Component[] | Components, res: string[] = []) => { |
|
|
|
if (!cmp) return []; |
|
|
|
@ -228,12 +229,23 @@ Component> { |
|
|
|
return new model(attrs, options) as Component; |
|
|
|
} |
|
|
|
|
|
|
|
parseString(value: string, opt: AddOptions & { temporary?: boolean; keepIds?: string[] } = {}) { |
|
|
|
const { em, domc } = this; |
|
|
|
parseString(value: string, opt: AddOptions & OptionAsDocument & { temporary?: boolean; keepIds?: string[] } = {}) { |
|
|
|
const { em, domc, parent } = this; |
|
|
|
const asDocument = opt.asDocument && parent?.is('wrapper'); |
|
|
|
const cssc = em.Css; |
|
|
|
const parsed = em.Parser.parseHtml(value); |
|
|
|
const parsed = em.Parser.parseHtml(value, { asDocument }); |
|
|
|
let components = parsed.html; |
|
|
|
|
|
|
|
if (asDocument) { |
|
|
|
const root = parent as ComponentWrapper; |
|
|
|
components = (parsed.html as any).components; |
|
|
|
root.head.set(parsed.head as any, opt); |
|
|
|
root.docEl.set(parsed.root as any, opt); |
|
|
|
root.set({ doctype: parsed.doctype }); |
|
|
|
} |
|
|
|
|
|
|
|
// We need this to avoid duplicate IDs
|
|
|
|
Component.checkId(parsed.html!, parsed.css, domc!.componentsById, opt); |
|
|
|
Component.checkId(components, parsed.css, domc!.componentsById, opt); |
|
|
|
|
|
|
|
if (parsed.css && cssc && !opt.temporary) { |
|
|
|
const { at, ...optsToPass } = opt; |
|
|
|
@ -243,7 +255,7 @@ Component> { |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
return parsed.html; |
|
|
|
return components; |
|
|
|
} |
|
|
|
|
|
|
|
/** @ts-ignore */ |
|
|
|
|