|
|
|
@ -1,60 +1,53 @@ |
|
|
|
import { Model, ModelDestroyOptions } from 'backbone'; |
|
|
|
import { |
|
|
|
isUndefined, |
|
|
|
isFunction, |
|
|
|
bindAll, |
|
|
|
forEach, |
|
|
|
has, |
|
|
|
isArray, |
|
|
|
isEmpty, |
|
|
|
isBoolean, |
|
|
|
has, |
|
|
|
isEmpty, |
|
|
|
isFunction, |
|
|
|
isString, |
|
|
|
forEach, |
|
|
|
result, |
|
|
|
bindAll, |
|
|
|
isUndefined, |
|
|
|
keys, |
|
|
|
result, |
|
|
|
} from 'underscore'; |
|
|
|
import { |
|
|
|
shallowDiff, |
|
|
|
capitalize, |
|
|
|
isEmptyObj, |
|
|
|
isObject, |
|
|
|
toLowerCase, |
|
|
|
escapeAltQuoteAttrValue, |
|
|
|
escapeAttrValue, |
|
|
|
} from '../../utils/mixins'; |
|
|
|
import Frame from '../../canvas/model/Frame'; |
|
|
|
import { AddOptions, ExtractMethods, ObjectAny, PrevToNewIdMap, SetOptions } from '../../common'; |
|
|
|
import CssRule, { CssRuleJSON } from '../../css_composer/model/CssRule'; |
|
|
|
import { DataCollectionStateMap } from '../../data_sources/model/data_collection/types'; |
|
|
|
import { DataCollectionKeys } from '../../data_sources/types'; |
|
|
|
import { checkAndGetSyncableCollectionItemId } from '../../data_sources/utils'; |
|
|
|
import StyleableModel, { |
|
|
|
GetStyleOpts, |
|
|
|
StyleProps, |
|
|
|
UpdateStyleOptions, |
|
|
|
} from '../../domain_abstract/model/StyleableModel'; |
|
|
|
import { Model, ModelDestroyOptions } from 'backbone'; |
|
|
|
import Components from './Components'; |
|
|
|
import EditorModel from '../../editor/model/Editor'; |
|
|
|
import ItemView from '../../navigator/view/ItemView'; |
|
|
|
import Selector from '../../selector_manager/model/Selector'; |
|
|
|
import Selectors from '../../selector_manager/model/Selectors'; |
|
|
|
import Trait from '../../trait_manager/model/Trait'; |
|
|
|
import Traits from '../../trait_manager/model/Traits'; |
|
|
|
import EditorModel from '../../editor/model/Editor'; |
|
|
|
import { TraitProperties } from '../../trait_manager/types'; |
|
|
|
import { |
|
|
|
ComponentAdd, |
|
|
|
ComponentDefinition, |
|
|
|
ComponentDefinitionDefined, |
|
|
|
ComponentOptions, |
|
|
|
ComponentProperties, |
|
|
|
DragMode, |
|
|
|
ResetComponentsOptions, |
|
|
|
SymbolToUpOptions, |
|
|
|
ToHTMLOptions, |
|
|
|
} from './types'; |
|
|
|
import Frame from '../../canvas/model/Frame'; |
|
|
|
capitalize, |
|
|
|
escapeAltQuoteAttrValue, |
|
|
|
escapeAttrValue, |
|
|
|
isEmptyObj, |
|
|
|
isObject, |
|
|
|
shallowDiff, |
|
|
|
toLowerCase, |
|
|
|
} from '../../utils/mixins'; |
|
|
|
import { DomComponentsConfig } from '../config/config'; |
|
|
|
import ComponentView from '../view/ComponentView'; |
|
|
|
import { AddOptions, ExtractMethods, ObjectAny, PrevToNewIdMap, SetOptions } from '../../common'; |
|
|
|
import CssRule, { CssRuleJSON } from '../../css_composer/model/CssRule'; |
|
|
|
import Trait from '../../trait_manager/model/Trait'; |
|
|
|
import { ToolbarButtonProps } from './ToolbarButton'; |
|
|
|
import { TraitProperties } from '../../trait_manager/types'; |
|
|
|
import { ActionLabelComponents, ComponentsEvents } from '../types'; |
|
|
|
import ItemView from '../../navigator/view/ItemView'; |
|
|
|
import ComponentView from '../view/ComponentView'; |
|
|
|
import Components from './Components'; |
|
|
|
import { DataWatchersOptions } from './ModelResolverWatcher'; |
|
|
|
import { |
|
|
|
getSymbolMain, |
|
|
|
getSymbolInstances, |
|
|
|
getSymbolMain, |
|
|
|
getSymbolsToUpdate, |
|
|
|
initSymbol, |
|
|
|
isSymbol, |
|
|
|
isSymbolMain, |
|
|
|
@ -62,12 +55,19 @@ import { |
|
|
|
updateSymbolCls, |
|
|
|
updateSymbolComps, |
|
|
|
updateSymbolProps, |
|
|
|
getSymbolsToUpdate, |
|
|
|
} from './SymbolUtils'; |
|
|
|
import { DataWatchersOptions } from './ModelResolverWatcher'; |
|
|
|
import { DataCollectionStateMap } from '../../data_sources/model/data_collection/types'; |
|
|
|
import { checkAndGetSyncableCollectionItemId } from '../../data_sources/utils'; |
|
|
|
import { keyRootData } from '../constants'; |
|
|
|
import { ToolbarButtonProps } from './ToolbarButton'; |
|
|
|
import { |
|
|
|
ComponentAdd, |
|
|
|
ComponentDefinition, |
|
|
|
ComponentDefinitionDefined, |
|
|
|
ComponentOptions, |
|
|
|
ComponentProperties, |
|
|
|
DragMode, |
|
|
|
ResetComponentsOptions, |
|
|
|
SymbolToUpOptions, |
|
|
|
ToHTMLOptions, |
|
|
|
} from './types'; |
|
|
|
|
|
|
|
export interface IComponent extends ExtractMethods<Component> {} |
|
|
|
export interface SetAttrOptions extends SetOptions, UpdateStyleOptions, DataWatchersOptions {} |
|
|
|
@ -434,7 +434,7 @@ export default class Component extends StyleableModel<ComponentProperties> { |
|
|
|
['status', 'open', 'toolbar', 'traits'].forEach((name) => delete changed[name]); |
|
|
|
// Propagate component prop changes
|
|
|
|
if (!isEmptyObj(changed)) { |
|
|
|
this.__changesUp(opts); |
|
|
|
this.__changesUp(opts, { changed }); |
|
|
|
this.__propSelfToParent({ component: this, changed, options: opts }); |
|
|
|
} |
|
|
|
} |
|
|
|
@ -449,7 +449,7 @@ export default class Component extends StyleableModel<ComponentProperties> { |
|
|
|
this.emitWithEditor(ComponentsEvents.styleUpdate, this, pros); |
|
|
|
styleKeys.forEach((key) => this.emitWithEditor(`${ComponentsEvents.styleUpdateProperty}${key}`, this, pros)); |
|
|
|
|
|
|
|
const parentCollectionIds = Object.keys(collectionsStateMap).filter((key) => key !== keyRootData); |
|
|
|
const parentCollectionIds = Object.keys(collectionsStateMap).filter((key) => key !== DataCollectionKeys.rootData); |
|
|
|
|
|
|
|
if (parentCollectionIds.length === 0) return; |
|
|
|
|
|
|
|
@ -472,9 +472,11 @@ export default class Component extends StyleableModel<ComponentProperties> { |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
__changesUp(opts: any) { |
|
|
|
__changesUp(options: any, data: Record<string, any> = {}) { |
|
|
|
const { em, frame } = this; |
|
|
|
[frame, em].forEach((md) => md && md.changesUp(opts)); |
|
|
|
[frame, em].forEach((md) => { |
|
|
|
md?.changesUp(options, { component: this, options, ...data }); |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
__propSelfToParent(props: any) { |
|
|
|
@ -1657,7 +1659,6 @@ export default class Component extends StyleableModel<ComponentProperties> { |
|
|
|
delete obj[keySymbol]; |
|
|
|
delete obj[keySymbolOvrd]; |
|
|
|
delete obj[keySymbols]; |
|
|
|
delete obj.attributes.id; |
|
|
|
} |
|
|
|
|
|
|
|
if (!opts.fromUndo) { |
|
|
|
@ -2242,10 +2243,15 @@ export default class Component extends StyleableModel<ComponentProperties> { |
|
|
|
components: ComponentDefinitionDefined | ComponentDefinitionDefined[], |
|
|
|
styles: CssRuleJSON[] = [], |
|
|
|
list: ObjectAny = {}, |
|
|
|
opts: { keepIds?: string[]; idMap?: PrevToNewIdMap } = {}, |
|
|
|
opts: { |
|
|
|
keepIds?: string[]; |
|
|
|
idMap?: PrevToNewIdMap; |
|
|
|
updatedIds?: Record<string, ComponentDefinitionDefined[]>; |
|
|
|
} = {}, |
|
|
|
) { |
|
|
|
opts.updatedIds = opts.updatedIds || {}; |
|
|
|
const comps = isArray(components) ? components : [components]; |
|
|
|
const { keepIds = [], idMap = {} } = opts; |
|
|
|
const { keepIds = [], idMap = {}, updatedIds } = opts; |
|
|
|
comps.forEach((comp) => { |
|
|
|
comp.attributes; |
|
|
|
const { attributes = {}, components } = comp; |
|
|
|
@ -2254,6 +2260,7 @@ export default class Component extends StyleableModel<ComponentProperties> { |
|
|
|
// Check if we have collisions with current components
|
|
|
|
if (id && list[id] && keepIds.indexOf(id) < 0) { |
|
|
|
const newId = Component.getIncrementId(id, list); |
|
|
|
updatedIds[id] = updatedIds[id] ? [...updatedIds[id], comp] : [comp]; |
|
|
|
idMap[id] = newId; |
|
|
|
attributes.id = newId; |
|
|
|
// Update passed styles
|
|
|
|
@ -2268,5 +2275,9 @@ export default class Component extends StyleableModel<ComponentProperties> { |
|
|
|
|
|
|
|
components && Component.checkId(components, styles, list, opts); |
|
|
|
}); |
|
|
|
|
|
|
|
return { |
|
|
|
updatedIds: opts.updatedIds, |
|
|
|
}; |
|
|
|
} |
|
|
|
} |
|
|
|
|