1
1
import { DataVariableType } from './../DataVariable' ;
2
2
import { isArray } from 'underscore' ;
3
- import Component from '../../../dom_components/model/Component' ;
3
+ import Component , { keySymbol , keySymbolOvrd , keySymbols } from '../../../dom_components/model/Component' ;
4
4
import { ComponentDefinition , ComponentOptions , ComponentProperties } from '../../../dom_components/model/types' ;
5
5
import { toLowerCase } from '../../../utils/mixins' ;
6
6
import DataSource from '../DataSource' ;
7
7
import { ObjectAny } from '../../../common' ;
8
8
import EditorModel from '../../../editor/model/Editor' ;
9
9
import { keyCollectionsStateMap } from '../../../dom_components/model/Component' ;
10
- import { CollectionDefinition , CollectionState , CollectionsStateMap } from './types' ;
10
+ import { CollectionComponentDefinition , CollectionDefinition , CollectionState , CollectionsStateMap } from './types' ;
11
11
import { keyCollectionDefinition , keyInnerCollectionState , CollectionComponentType } from './constants' ;
12
12
13
13
export default class CollectionComponent extends Component {
14
- constructor ( props : CollectionDefinition & ComponentProperties , opt : ComponentOptions ) {
14
+ constructor ( props : CollectionComponentDefinition , opt : ComponentOptions ) {
15
15
const em = opt . em ;
16
16
const { collection_name, block, config } = props [ keyCollectionDefinition ] ;
17
17
if ( ! block ) {
@@ -42,12 +42,13 @@ export default class CollectionComponent extends Component {
42
42
} ;
43
43
44
44
const collectionsStateMap : CollectionsStateMap = {
45
- ...props [ keyCollectionsStateMap ] ,
45
+ ...( props [ keyCollectionsStateMap ] || { } ) ,
46
46
...( collection_name && { [ collection_name ] : collectionState } ) ,
47
47
[ keyInnerCollectionState ] : collectionState ,
48
48
} ;
49
49
50
50
if ( index === start_index ) {
51
+ // @ts -ignore
51
52
const type = em . Components . getType ( block ?. type || 'default' ) ;
52
53
const model = type . model ;
53
54
blockComponent = new model (
@@ -70,13 +71,26 @@ export default class CollectionComponent extends Component {
70
71
components : components ,
71
72
dropbbable : false ,
72
73
} ;
74
+
73
75
// @ts -ignore
74
76
super ( conditionalCmptDef , opt ) ;
75
77
}
76
78
77
79
static isComponent ( el : HTMLElement ) {
78
80
return toLowerCase ( el . tagName ) === CollectionComponentType ;
79
81
}
82
+
83
+ toJSON ( opts ?: ObjectAny ) {
84
+ const json = super . toJSON ( opts ) as CollectionComponentDefinition ;
85
+
86
+ const firstChild = this . components ( ) . at ( 0 ) ?. toJSON ( ) || { } ;
87
+ const keysToRemove = [ 'attributes?.id' , keySymbol , keySymbols , keySymbolOvrd , keyCollectionsStateMap ] ;
88
+ keysToRemove . forEach ( ( key ) => delete firstChild [ key ] ) ;
89
+ json [ keyCollectionDefinition ] . block = firstChild ;
90
+
91
+ delete json . components ;
92
+ return json ;
93
+ }
80
94
}
81
95
82
96
function getDataSourceItems ( dataSource : any , em : EditorModel ) {
0 commit comments