@ -7,17 +7,30 @@
/ * *
* ExtStorage : = Extensions storage ( type )
* Extensions in this context are stylings and scripts ( currently only javascript ) .
* internalized : the extensions are part of the element code / attributes - only styling
* internalized : the extensions are part of the element code / attributes - works obviously only with styling
* individually : an individual tag is created / used
* collected : the extension can / will be collected with others in a higher position of the element hierarchy
* ( but not document - root )
* centralized : the extensions are send to the Page to be joined in a centralized tag / position of the document
* ( either head or footer tag )
* /
const ExtStorageType = Object . freeze ( {
INDIVIDUALLY : 1 ,
COLLECTED : 2 ,
CENTRALIZED : 3 ,
const ExtStoreType = Object . freeze ( {
INTERNALIZED_WITHIN : 0 ,
INDIVIDUALLY_WITHIN : 1 ,
INDIVIDUALLY_BEFORE : 2 ,
INDIVIDUALLY_SEGMENT_BEGIN : 3 ,
INDIVIDUALLY_DOC_HEAD : 4 ,
INDIVIDUALLY_DOC_FOOTER : 5 ,
COLLECTED_BEFORE : 6 ,
COLLECTED_SEGMENT_BEGIN : 7 ,
COLLECTED_DOC_HEAD : 8 ,
COLLECTED_DOC_FOOTER : 9 ,
CENTRALIZED_DOC_HEAD : 10 ,
CENTRALIZED_SEGMENT_BEGIN : 11 ,
CENTRALIZED_DOC_FOOTER : 12 ,
} ) ;
/ * *
@ -27,105 +40,243 @@ const ExtStorageType = Object.freeze({
* Only relevant if ExtStorage is not 'internalized' .
* Determines where the tag ( if individually ) or the extensions are positioned .
* /
const ExtStorag ePos = Object . freeze ( {
WITHIN : 0 ,
BEFORE : 1 ,
SEGMENT_BEGIN : 2 ,
BEGINNING : 3 ,
END : 4
const ExtStorePosition = Object . freeze ( {
WITHIN : "WITHIN" ,
BEFORE : "BEFORE" ,
SEGMENT_BEGIN : "SEGMENT_BEGIN" ,
DOC_HEAD : "DOC_HEAD" ,
DOC_FOOTER : "DOC_FOOTER"
} ) ;
/ * *
* Extension class for setting the ExternalStorage definitions
* in a chained manner .
* Defines how an identified dupplication should be "resolved" / dealt with .
* REPLACE :
* RENAME :
* RENAME_OLD :
* DROP_NEW :
* MOVE_ELEMENT_SPECIFIC : @ ATTENTION implementation pending
* /
const OverwriteBehaviour = Object . freeze ( {
REPLACE : "REPLACE" ,
RENAME : "RENAME" ,
RENAME_OLD : "RENAME_OLD" ,
DROP_NEW : "DROP_NEW" ,
MOVE_ELEMENT_SPECIFIC : "MOVE_ELEMENT_SPECIFIC"
} ) ;
/ * *
* Extracted this super class to differentiate between
* internal and external store .
* /
class ExtStoragePositioned {
# extStore ;
class ExtStorage {
constructor ( type = null , behaviour = null ) {
/ * *
* @ type { ExtStorageType }
* /
this . _ type = ( ! type ? ExtStoreType . INDIVIDUALLY_WITHING : type ) ;
/ * *
* @ type { OverwriteBehaviour }
* /
this . _ overwriteBehaviour = ( ! behaviour ? OverwriteBehaviour . REPLACE : behaviour ) ;
}
/ * *
*
* @ param { ExtStore } extStore
* @ param { OverwriteBehaviour } behave
* @ returns { EXPosConfer }
* /
constructor ( extStore ) {
this . # extStore = extStore ;
}
WITHIN ( ) {
this . # extStore . position = ExtStoragePos . WITHIN ;
return this . # extStore ;
overwriteBehaviour ( behave ) {
this . _ overwriteBehaviour = behave ;
return this ;
}
BEFORE ( ) {
this . # extStore . position = ExtStoragePos . BEFORE ;
return this . # extStore ;
}
SEGMENT_BEGIN ( ) {
this . # extStore . position = ExtStoragePos . SEGMENT_BEGIN ;
return this . # extStore ;
/ * *
*
* @ param { ExtStoreType } type
* /
setExtStoreType ( type ) {
this . _ type = type ;
return this ;
}
BEGINNING ( ) {
this . # extStore . position = ExtStoragePos . BEGINNING ;
return this . # extStore ;
/ * *
*
* @ param { ExtStorage } extStore
* @ returns { boolean }
* /
equals ( extStore = null ) {
if ( ! extStore ) return false ;
return extStore . _ type === this . _ type
&& extStore . _ overwriteBehaviour === this . _ overwriteBehaviour ;
}
END ( ) {
this . # extStore . position = ExtStoragePos . END ;
return this . # extStore ;
/ * *
*
* @ returns { boolean }
* /
isMissing ( ) {
return this . _ type === null || this . _ overwriteBehaviour === null ;
}
}
/ * *
* Extracted this super class to differentiate between
* internal and external store .
* /
class ExtStore {
type ;
position ;
/ * *
*
* @ param { string } type
* @ param { ExtStorage } otherExtStore
* @ returns { ExtStorage }
* /
constructor ( typeName ) {
this . type = typeName ;
fillBy ( otherExtStore ) {
if ( this . _ type === null ) {
this . _ type = otherExtStore . _ type ;
}
if ( this . _ overwriteBehaviour === null ) {
this . _ overwriteBehaviour = otherExtStore . _ overwriteBehaviour ;
}
return this ;
}
/ * *
* Takes the singleValue and an ExtStore object to copy all values from .
* Then the singleValue will be compared to the three enums for the type of value .
* After the type is identified the corresponding ( copied ) value will be updated .
* @ param { ExtStoreType | ExtStorePosition | OverwriteBehaviour } singleValue
* @ param { ExtStorage } extStoreToClone
* @ returns { ExtStorage }
* /
setSingleValueToClone ( singleValue , extStoreToClone ) {
this . _ type = extStoreToClone . _ type ;
this . _ position = extStoreToClone . _ position ;
this . _ overwriteBehaviour = extStoreToClone . _ overwriteBehaviour ;
let target = [
... Object . values ( ExtStoreType ) . map ( text => Object ( { "value" : text , "ref" : "type" } ) ) ,
... Object . values ( ExtStorePosition ) . map ( text => Object ( { "value" : text , "ref" : "pos" } ) ) ,
... Object . values ( OverwriteBehaviour ) . map ( text => Object ( { "value" : text , "ref" : "over" } ) )
]
. find ( compareObj => compareObj [ "value" ] === singleValue ) ;
if ( target ) {
switch ( target [ "ref" ] ) {
case "type" :
this . _ type = singleValue ;
break ;
case "pos" :
this . _ position = singleValue ;
break ;
case "over" :
this . _ overwriteBehaviour = singleValue ;
break ;
}
}
return this ;
}
}
class InternalExtStore extends ExtStore {
/ * *
*
* @ param { string } type
* @ returns { ExtStorage } this extStore ( updated if rules were used , that don ' t work for functions )
* /
constructor ( typeName ) {
super ( typeName ) ;
this . position = ExtStoragePos . WITHIN ;
updateForFunctions ( ) {
if ( this . _ type === ExtStoreType . INTERNALIZED_WITHIN ) {
console . log ( "Updated Functions extstore from INTERNALIZED_WITHIN to INDIVIDUALLY_BEFORE" )
this . _ type = ExtStoreType . INDIVIDUALLY_BEFORE ;
}
return this ;
}
}
class ExtExtStorage extends ExtStore {
/ * *
*
* @ param { string } type
* @ returns { ExtStorage }
* /
constructor ( typeName ) {
super ( typeName ) ;
this . type = typeName ;
updateForGeneralStyling ( ) {
switch ( this . _ type ) {
case ExtStoreType . INTERNALIZED_WITHIN :
break ;
case ExtStoreType . INDIVIDUALLY_WITHIN :
case ExtStoreType . INDIVIDUALLY_BEFORE :
case ExtStoreType . INDIVIDUALLY_SEGMENT_BEGIN :
case ExtStoreType . INDIVIDUALLY_DOC_FOOTER :
this . _ type = ExtStoreType . INDIVIDUALLY_DOC_HEAD ;
case ExtStoreType . INDIVIDUALLY_DOC_HEAD :
break ;
case ExtStoreType . COLLECTED_BEFORE :
case ExtStoreType . COLLECTED_SEGMENT_BEGIN :
case ExtStoreType . COLLECTED_DOC_FOOTER :
this . _ type = ExtStoreType . COLLECTED_DOC_HEAD ;
case ExtStoreType . COLLECTED_DOC_HEAD :
break ;
case ExtStoreType . CENTRALIZED_SEGMENT_BEGIN :
case ExtStoreType . CENTRALIZED_DOC_FOOTER :
this . _ type = ExtStoreType . CENTRALIZED_DOC_HEAD ;
case ExtStoreType . CENTRALIZED_DOC_HEAD :
break
}
return this ;
}
positionedAt ( ) {
return new ExtStoragePositioned ( this ) ;
/ * *
* Currently it works the same as the "updateForFunctions()" since the same rules won ' t work .
* @ returns { ExtStorage } this extStore ( updated if rules were used , that won ' t work for StyleClasses )
* /
updateForStyleClass ( ) {
/ *
const positionedAfter = [
COLLECTED_DOC_FOOTER ,
INDIVIDUALLY_DOC_FOOTER ,
CENTRALIZED_DOC_FOOTER
] ;
if ( positionedAfter . includes ( this . _ type ) ) {
this . _ type = ExtStoreType . INTERNALIZED_WITHIN ;
}
* /
return this . updateForGeneralStyling ( ) ;
}
}
const StoreExtAs = Object . freeze ( {
INTERNALIZED : new InternalExtStore ( ExtStorageType . INTERNALIZED ) ,
INDIVIDUALLY : new ExtExtStorage ( ExtStorageType . INDIVIDUALLY ) ,
COLLECTED : new ExtExtStorage ( ExtStorageType . COLLECTED ) ,
CENTRALIZED : new ExtExtStorage ( ExtStorageType . CENTRALIZED ) ,
} ) ;
/ * *
* Style or Script Store Definition
* @ property { string } _ identifier ;
* @ property { any } _ definition ;
* @ property { any } _ additionaly ;
* @ property { ExtStorage } _ extStore ;
* /
class SStoreDefinition {
constructor ( identifier , definition , extStore = null , additions = null ) {
/ * *
* Usually the name or the selector
* @ type { string } _ identifier ;
* /
this . _ identifier = identifier ;
/ * *
* the values
* @ type { any } _ definition ;
* /
this . _ definition = definition ;
/ * *
* additional values , if needed . E . g . funciton args
* @ type { any } _ additionaly ;
* /
this . _ additions = additions ;
/ * *
* The corresponding extStore
* @ type { ExtStorage } _ extStore ;
* /
this . _ extStore = extStore ;
}
}
const OverwriteBehaviour = Object . freeze ( {
REPLACE : 0 ,
RENAME : 1 ,
RENAME_OLD : 2
} ) ;
/ * *
* Resolves an overwrite case for a map / object .
@ -155,3 +306,27 @@ function resolveOverwrite(key, container, overwriteBehaviour) {
return key ;
}
/ * *
* Will resolve the compareKey according to the overwriteBehaviour
* and add the newValue to the targetContainer with it .
* @ param { Object } targetContainer
* @ param { string } compareKey
* @ param { Object } newValue
* @ param { OverwriteBehaviour } overwriteBehaviour
* @ returns { string } the "resolved" compareKey
* /
function identifyAndResolveOverwrite ( targetContainer , compareKey , newValue , overwriteBehaviour ) {
let keys = Object . keys ( targetContainer ) ;
if ( keys . includes ( compareKey ) ) {
if ( overwriteBehaviour === OverwriteBehaviour . DROP_NEW ) {
console . log ( "Not Adding, because overwrite is set to DROP_NEW" ) ;
return compareKey ;
}
compareKey = resolveOverwrite ( compareKey , targetContainer , overwriteBehaviour ) ;
}
targetContainer [ compareKey ] = newValue ;
return compareKey ;
}