@@ -752,11 +752,30 @@ simply = {
752
752
this . sfcClass . lifecycle . beforeConstruct ( ) ;
753
753
}
754
754
}
755
-
755
+ var open = false ;
756
+ if ( this . getAttribute ( "open" ) !== null ) {
757
+ open = true ;
758
+ }
759
+
756
760
var uid = "id" + Math . random ( ) . toString ( 16 ) . slice ( 2 )
757
761
var component = this ;
758
- var dom = this . attachShadow ( { mode : 'open' } ) ;
759
- var parent = this . getRootNode ( ) . host ;
762
+
763
+ if ( ! open ) {
764
+ var dom = this . attachShadow ( { mode : 'open' } ) ;
765
+ var parent = this . getRootNode ( ) . host ;
766
+ if ( ! parent ) {
767
+ parent = simply . findShadowRootOrCustomElement ( this ) ;
768
+ }
769
+ }
770
+ else {
771
+ var dom = this ;
772
+ var parent = simply . findShadowRootOrCustomElement ( this ) ;
773
+ }
774
+
775
+ if ( name == "home-comp" ) {
776
+ console . log ( "ehem" , parent ) ;
777
+ }
778
+
760
779
var data = this . sfcClass . data ? this . sfcClass . data : { } ;
761
780
var props = this . sfcClass . props ? this . sfcClass . props : { } ;
762
781
var methods = this . sfcClass . methods ;
@@ -773,6 +792,9 @@ simply = {
773
792
this . watch = watch ;
774
793
this . parent = parent ;
775
794
this . uid = uid ;
795
+ this . open = open ;
796
+
797
+ // console.log(name, open);
776
798
777
799
var geval = eval ;
778
800
for ( var key in sfcClass ) {
@@ -974,13 +996,19 @@ simply = {
974
996
if ( m . index === regex . lastIndex ) {
975
997
regex . lastIndex ++ ;
976
998
}
977
- if ( m . groups [ "match" ] . indexOf ( "this.getRootNode().host" ) == - 1 ) {
999
+ if ( this . open ) {
1000
+ var match = "simply.findShadowRootOrCustomElement(this)" ;
1001
+ }
1002
+ else {
1003
+ var match = "this.getRootNode().host" ;
1004
+ }
1005
+ if ( m . groups [ "match" ] . indexOf ( match ) == - 1 ) {
978
1006
var builtinVars = [ "state." , "parent." , "methods." , "lifecycle." , "data." , "props." , "component." , "dom." ] ;
979
1007
980
1008
var newValue = m [ 0 ] ;
981
1009
builtinVars . forEach ( v => {
982
- newValue = newValue . replaceAll ( v , "this.getRootNode().host ." + v ) ;
983
- newValue = newValue . replaceAll ( ".this.getRootNode().host" , "" ) ;
1010
+ newValue = newValue . replaceAll ( v , match + " ." + v ) ;
1011
+ newValue = newValue . replaceAll ( "." + match , "" ) ;
984
1012
} ) ;
985
1013
template = template . replaceAll ( m [ 0 ] , newValue ) ;
986
1014
}
@@ -1100,7 +1128,15 @@ simply = {
1100
1128
}
1101
1129
1102
1130
try {
1103
- this . sheet = this . dom . getRootNode ( ) . querySelector ( "style[simply-vars]" ) . sheet ;
1131
+ if ( ! this . open ) {
1132
+ //console.log("not open", this);
1133
+ this . sheet = this . dom . getRootNode ( ) . querySelector ( "style[simply-vars]" ) . sheet ;
1134
+ }
1135
+ else {
1136
+ //console.log("open", this);
1137
+ this . sheet = this . querySelector ( "style[simply-vars]" ) . sheet ;
1138
+ }
1139
+
1104
1140
//console.log(this.dom.getRootNode().styleSheets[1].cssRules[0].style.setProperty"--main-bg-color: yellow;";["--data-topAreaHeight"] = "3px");
1105
1141
1106
1142
var vars = ":host {" ;
@@ -1141,51 +1177,79 @@ simply = {
1141
1177
var newDom = parsedTemplate + "<style uno></style><style global>" + ( parsedGlobalStyle ? parsedGlobalStyle . style : "" ) + "</style>" + "<style simply>:host([hoak]) {display: none;} " + parsedStyle . style + "</style><style simply-vars></style>" ;
1142
1178
1143
1179
//childrenOnly: true,
1144
- simply . morphdom ( this . dom , "<div>" + newDom + "</div>" , {
1145
- onBeforeElUpdated : function ( fromEl , toEl ) {
1146
- // spec - https://dom.spec.whatwg.org/#concept-node-equals
1147
- if ( fromEl . isEqualNode ( toEl ) ) {
1148
- return false
1149
- }
1150
- return true
1151
- } ,
1152
- onBeforeNodeDiscarded : function ( node ) {
1153
-
1154
- } ,
1155
- onBeforeElChildrenUpdated : function ( fromEl , toEl ) {
1156
- if ( fromEl . tagName == "CHILD-COMPONENT" ) {
1157
- // console.log("dont again");
1158
- }
1159
- else if ( fromEl . tagName == "STYLE" ) {
1160
- return false ;
1161
- }
1162
- else if ( toEl . hasAttribute ( "passive" ) === true ) {
1163
- return false ;
1164
- }
1165
- else if ( toEl . tagName === 'INPUT' ) {
1166
- if ( toEl . type == 'RADIO' || toEl . type == 'CHECKBOX' ) {
1180
+
1181
+ if ( this . open ) {
1182
+ var newDomAsString = "<" + name + " open>" + newDom + "</" + name + ">" ;
1183
+ morphIt ( this . dom ) ;
1184
+ }
1185
+ else {
1186
+ var newDomAsString = "<" + name + ">" + newDom + "</" + name + ">" ;
1187
+ morphIt ( this . dom ) ;
1188
+ }
1189
+
1190
+ function morphIt ( dom ) {
1191
+ simply . morphdom ( dom , newDomAsString , {
1192
+ childrenOnly : true ,
1193
+ onBeforeElUpdated : function ( fromEl , toEl ) {
1194
+ // spec - https://dom.spec.whatwg.org/#concept-node-equals
1195
+
1196
+
1197
+ if ( fromEl . isSameNode ( toEl ) ) {
1167
1198
return false ;
1168
1199
}
1169
- else {
1170
- toEl . value = fromEl . value ;
1171
- }
1172
- }
1173
-
1174
- else if ( toEl . tagName === 'ROUTER' ) {
1175
- // DINAMIK BAKMAK LAZIM EL ROUTER MI DIYE
1176
- return false ;
1177
- }
1178
- else if ( toEl . tagName == 'LABEL' ) {
1179
1200
if ( fromEl . isEqualNode ( toEl ) ) {
1201
+ return false
1202
+ }
1203
+ return true
1204
+ } ,
1205
+ onBeforeNodeDiscarded : function ( node ) {
1206
+ } ,
1207
+ onBeforeElChildrenUpdated : function ( fromEl , toEl ) {
1208
+ // bu custom element'leri skip etmek için
1209
+ // shadowdom olanlara zaten dokunamıyor da
1210
+ // shadow'suz custom elementleri her seferinde render ediyor yoksa
1211
+ if ( customElements . get ( fromEl . tagName . toLowerCase ( ) ) ) {
1212
+ return false ;
1213
+ }
1214
+ if ( fromEl . isSameNode ( toEl ) ) {
1180
1215
return false ;
1216
+ }
1217
+ if ( fromEl . tagName == "CHILD-COMPONENT" ) {
1218
+ // console.log("dont again");
1181
1219
}
1220
+ else if ( fromEl . tagName == "STYLE" ) {
1221
+ return false ;
1222
+ }
1223
+ else if ( toEl . hasAttribute ( "passive" ) === true ) {
1224
+ return false ;
1225
+ }
1226
+ else if ( toEl . tagName === 'INPUT' ) {
1227
+ if ( toEl . type == 'RADIO' || toEl . type == 'CHECKBOX' ) {
1228
+ return false ;
1229
+ }
1230
+ else {
1231
+ toEl . value = fromEl . value ;
1232
+ }
1233
+ }
1234
+
1235
+ else if ( toEl . tagName === 'ROUTER' ) {
1236
+ // DINAMIK BAKMAK LAZIM EL ROUTER MI DIYE
1237
+ return false ;
1238
+ }
1239
+ else if ( toEl . tagName == 'LABEL' ) {
1240
+ if ( fromEl . isEqualNode ( toEl ) ) {
1241
+ return false ;
1242
+ }
1243
+ }
1244
+ else if ( toEl . tagName === 'OPTION' ) {
1245
+ toEl . selected = fromEl . selected ;
1246
+ }
1247
+ //console.log(toEl.tagName);
1182
1248
}
1183
- else if ( toEl . tagName === 'OPTION' ) {
1184
- toEl . selected = fromEl . selected ;
1185
- }
1186
- //console.log(toEl.tagName);
1187
- }
1188
- } ) ;
1249
+ } ) ;
1250
+ }
1251
+
1252
+
1189
1253
1190
1254
if ( this . globalStyle ) {
1191
1255
var parsedGlobalStyle = simply . parseStyle ( {
@@ -1230,26 +1294,21 @@ simply = {
1230
1294
var state = this . state ;
1231
1295
var parent = this . parent ;
1232
1296
1233
- this . state . __c_ . forEach ( function ( cb , i ) {
1234
- if ( cb . id == compId ) {
1235
- // console.log("bunu silem aga", cb, compName, i);
1236
- state . __c_ . splice ( i , 1 ) ;
1237
- }
1238
- } ) ;
1297
+ // Remove items from this.state.__c_
1298
+ this . state . __c_ = this . state . __c_ . filter ( function ( cb ) {
1299
+ return cb . id !== compId ;
1300
+ } ) ;
1301
+
1302
+ // Remove items from this.parent.data.__c_
1303
+ this . parent . data . __c_ = this . parent . data . __c_ . filter ( function ( cb ) {
1304
+ return cb . id !== compId ;
1305
+ } ) ;
1306
+
1307
+ // Remove items from this.parent.props.__c_
1308
+ this . parent . props . __c_ = this . parent . props . __c_ . filter ( function ( cb ) {
1309
+ return cb . id !== compId ;
1310
+ } ) ;
1239
1311
1240
- this . parent . data . __c_ . forEach ( function ( cb , i ) {
1241
- if ( cb . id == compId ) {
1242
- // console.log("bunu silem aga", cb, compName, i);
1243
- parent . data . __c_ . splice ( i , 1 ) ;
1244
- }
1245
- } ) ;
1246
-
1247
- this . parent . props . __c_ . forEach ( function ( cb , i ) {
1248
- if ( cb . id == compId ) {
1249
- // console.log("bunu silem aga", cb, compName, i);
1250
- parent . props . __c_ . splice ( i , 1 ) ;
1251
- }
1252
- } ) ;
1253
1312
1254
1313
if ( typeof this . lifecycle !== "undefined" ) {
1255
1314
if ( typeof this . lifecycle . disconnected !== "undefined" ) {
@@ -3135,12 +3194,20 @@ simply = {
3135
3194
3136
3195
// simply.js state & parent fix
3137
3196
let outlet = context . resolver . __outlet ;
3197
+
3138
3198
if ( outlet . getRootNode ( ) . host ) {
3139
3199
let parent = outlet . getRootNode ( ) . host ;
3140
3200
element . parent = parent ;
3141
3201
let state = parent . state ;
3142
3202
element . state = state ;
3143
3203
}
3204
+ else {
3205
+ let parent = document . querySelector ( "reframer-app" ) ; ;
3206
+ element . parent = parent ;
3207
+ let state = parent . state ;
3208
+ element . state = state ;
3209
+ //console.log(element);
3210
+ }
3144
3211
return element ;
3145
3212
}
3146
3213
@@ -4289,7 +4356,38 @@ simply = {
4289
4356
} ) ;
4290
4357
}
4291
4358
} ,
4359
+ findShadowRootOrCustomElement : function ( element ) {
4360
+ let parent = element . parentNode ;
4361
+
4362
+ while ( parent !== null ) {
4363
+ // Check if the parent is a shadow root
4364
+ if ( parent instanceof ShadowRoot ) {
4365
+ // console.log("Found shadow root:", parent);
4366
+ return parent . host ;
4367
+ }
4368
+ console . log ( element , parent ) ;
4369
+ // Check if the parent is a custom element
4370
+ // console.log(parent.tagName, customElements.get(parent.tagName));
4371
+ if ( parent . tagName ) {
4372
+ if ( parent . tagName . includes ( '-' ) && customElements . get ( parent . tagName . toLowerCase ( ) ) !== undefined ) {
4373
+ // console.log("Found custom element:", parent);
4374
+ return parent ;
4375
+ }
4376
+ }
4377
+ else {
4378
+ console . log ( "hi doc" , parent ) ;
4379
+ return undefined
4380
+ }
4292
4381
4382
+
4383
+ // Move to the next parent
4384
+ parent = parent . parentNode ;
4385
+ }
4386
+
4387
+ // If no shadow root or custom element is found
4388
+ console . log ( "No shadow root or custom element found." ) ;
4389
+ return null ;
4390
+ } ,
4293
4391
init : function ( ) {
4294
4392
this . Router ( ) ;
4295
4393
this . obaa ( ) ;
0 commit comments