@@ -4,7 +4,6 @@ import { updateStyleDefinition, removeStyleDefinition, coalesce, adjustmentsEqua
4
4
5
5
const spaceDefaults : Partial < ISpaceDefinition > = {
6
6
id : "" ,
7
- order : 0 ,
8
7
zIndex : 0 ,
9
8
scrollable : false ,
10
9
resizing : false ,
@@ -21,6 +20,8 @@ const spaceDefaults: Partial<ISpaceDefinition> = {
21
20
anchoredChildren : ( ) => [ ] ,
22
21
} ;
23
22
23
+ const anchorTypes = [ AnchorType . Left , AnchorType . Top , AnchorType . Right , AnchorType . Bottom ] ;
24
+
24
25
function getPosition ( type : Type ) {
25
26
if ( type === Type . ViewPort ) {
26
27
return "fixed" ;
@@ -74,14 +75,37 @@ export function createStore(): ISpaceStore {
74
75
const getSpaces = ( ) => spaces ;
75
76
76
77
const recalcSpaces = ( parent : ISpaceDefinition ) => {
77
- for ( var i = 0 , len = parent . children . length ; i < len ; i ++ ) {
78
- const space = parent . children [ i ] ;
78
+ const onlyUnique = ( value : number , index : number , self : number [ ] ) => {
79
+ return self . indexOf ( value ) === index ;
80
+ } ;
81
+
82
+ const addDefaultOrders = ( spaces : ISpaceDefinition [ ] ) => {
83
+ let result : ISpaceDefinition [ ] = [ ] ;
84
+
85
+ anchorTypes . forEach ( ( t ) => {
86
+ const anchoredSpaces = spaces . filter ( ( s ) => s . anchor !== undefined && s . anchor === t ) ;
87
+ const zIndices = anchoredSpaces . map ( ( s ) => s . zIndex ) . filter ( onlyUnique ) ;
88
+ zIndices . forEach ( ( i ) => {
89
+ const anchoredSpacesInLayer = anchoredSpaces . filter ( ( s ) => s . zIndex === i ) ;
90
+ const orderedSpaces = anchoredSpacesInLayer . filter ( ( c ) => c . order !== undefined ) ;
91
+ const unorderedSpaces = anchoredSpacesInLayer . filter ( ( c ) => c . order === undefined ) ;
92
+ var maxOrder = orderedSpaces . length > 0 ? orderedSpaces . map ( ( a ) => a . order ! ) . reduce ( ( a , b ) => Math . max ( a , b ) ) : 0 ;
93
+ result = [ ...result , ...[ ...orderedSpaces , ...unorderedSpaces . map ( ( c , idx ) => ( { ...c , ...{ order : maxOrder + idx + 1 } } ) ) ] ] ;
94
+ } ) ;
95
+ } ) ;
96
+
97
+ return [ ...result , ...spaces . filter ( ( s ) => s . anchor === undefined ) ] ;
98
+ } ;
99
+
100
+ const orderedSpaces = addDefaultOrders ( parent . children ) ;
101
+ for ( var i = 0 , len = orderedSpaces . length ; i < len ; i ++ ) {
102
+ const space = orderedSpaces [ i ] ;
79
103
let changed = false ;
80
104
81
105
if ( space . type === Type . Fill ) {
82
106
anchorUpdates ( space ) . forEach ( ( info ) => {
83
107
const adjusted : SizeUnit [ ] = [ ] ;
84
- const anchoredSpaces = parent . anchoredChildren ( info . anchor , space . zIndex ) ;
108
+ const anchoredSpaces = parent . anchoredChildren ( orderedSpaces , info . anchor , space . zIndex ) ;
85
109
86
110
anchoredSpaces . forEach ( ( as ) => {
87
111
if ( as . orientation === Orientation . Vertical ) {
@@ -108,8 +132,8 @@ export function createStore(): ISpaceStore {
108
132
} else if ( space . type === Type . Anchored ) {
109
133
const adjusted : SizeUnit [ ] = [ ] ;
110
134
const anchoredSpaces = parent
111
- . anchoredChildren ( space . anchor ! , space . zIndex )
112
- . filter ( ( s ) => s . id !== space . id && s . order <= space . order ) ;
135
+ . anchoredChildren ( orderedSpaces , space . anchor ! , space . zIndex )
136
+ . filter ( ( s ) => s . id !== space . id && s . order ! <= space . order ! ) ;
113
137
114
138
anchoredSpaces . forEach ( ( as ) => {
115
139
if ( as . orientation === Orientation . Vertical ) {
@@ -191,7 +215,7 @@ export function createStore(): ISpaceStore {
191
215
maximumSize,
192
216
handleSize,
193
217
touchHandleSize,
194
- handlePlacement
218
+ handlePlacement,
195
219
} = props ;
196
220
const canResizeLeft = ( position && position . rightResizable ) || false ;
197
221
const canResizeRight = ( position && position . leftResizable ) || false ;
@@ -382,13 +406,9 @@ export function createStore(): ISpaceStore {
382
406
} ,
383
407
} as ISpaceDefinition ;
384
408
385
- newSpace . anchoredChildren = ( anchor , zIndex ) => {
386
- const children = newSpace . children . filter ( ( s ) => s . type === Type . Anchored && s . anchor === anchor && s . zIndex === zIndex ) ;
387
- const orderedChildren = children . filter ( c => c . order !== undefined ) ;
388
- const unorderedChildren = children . filter ( c => c . order === undefined ) ;
389
- var maxOrder = orderedChildren . length > 0 ? orderedChildren . map ( a => a . order ) . reduce ( ( a , b ) => Math . max ( a , b ) ) : 0 ;
390
- return [ ...orderedChildren , ...unorderedChildren . map ( ( c , idx ) => ( { ...c , ...{ order : maxOrder + idx + 1 } } ) ) ] ;
391
- }
409
+ newSpace . anchoredChildren = ( children , anchor , zIndex ) => {
410
+ return children . filter ( ( s ) => s . type === Type . Anchored && s . anchor === anchor && s . zIndex === zIndex ) ;
411
+ } ;
392
412
393
413
newSpace . adjustLeft = ( adjusted ) => {
394
414
if ( adjustmentsEqual ( newSpace . left . adjusted , adjusted ) ) {
0 commit comments