@@ -1081,7 +1081,8 @@ function () {
1081
1081
key : "runListenerHandler" ,
1082
1082
value : function runListenerHandler ( expression , e ) {
1083
1083
this . evaluateCommandExpression ( expression , {
1084
- '$event' : e
1084
+ '$event' : e ,
1085
+ '$refs' : this . getRefsProxy ( )
1085
1086
} ) ;
1086
1087
}
1087
1088
} , {
@@ -1170,6 +1171,28 @@ function () {
1170
1171
option . selected = arrayWrappedValue . includes ( option . value || option . text ) ;
1171
1172
} ) ;
1172
1173
}
1174
+ } , {
1175
+ key : "getRefsProxy" ,
1176
+ value : function getRefsProxy ( ) {
1177
+ var self = this ; // One of the goals of this project is to not hold elements in memory, but rather re-evaluate
1178
+ // the DOM when the system needs something from it. This way, the framework is flexible and
1179
+ // friendly to outside DOM changes from libraries like Vue/Livewire.
1180
+ // For this reason, I'm using an "on-demand" proxy to fake a "$refs" object.
1181
+
1182
+ return new Proxy ( { } , {
1183
+ get : function get ( object , property ) {
1184
+ var ref ; // We can't just query the DOM because it's hard to filter out refs in
1185
+ // nested components.
1186
+
1187
+ Object ( _utils__WEBPACK_IMPORTED_MODULE_0__ [ "walkSkippingNestedComponents" ] ) ( self . el , function ( el ) {
1188
+ if ( el . hasAttribute ( 'x-ref' ) && el . getAttribute ( 'x-ref' ) === property ) {
1189
+ ref = el ;
1190
+ }
1191
+ } ) ;
1192
+ return ref ;
1193
+ }
1194
+ } ) ;
1195
+ }
1173
1196
} ] ) ;
1174
1197
1175
1198
return Component ;
@@ -1331,7 +1354,7 @@ function walkSkippingNestedComponents(el, callback) {
1331
1354
1332
1355
while ( node ) {
1333
1356
if ( node . hasAttribute ( 'x-data' ) ) return ;
1334
- walk ( node , callback ) ;
1357
+ walkSkippingNestedComponents ( node , callback ) ;
1335
1358
node = node . nextElementSibling ;
1336
1359
}
1337
1360
}
@@ -1365,12 +1388,12 @@ function saferEvalNoReturn(expression, dataContext) {
1365
1388
return new Function ( [ '$data' ] . concat ( _toConsumableArray ( Object . keys ( additionalHelperVariables ) ) ) , "with($data) { " . concat ( expression , " }" ) ) . apply ( void 0 , [ dataContext ] . concat ( _toConsumableArray ( Object . values ( additionalHelperVariables ) ) ) ) ;
1366
1389
}
1367
1390
function isXAttr ( attr ) {
1368
- var xAttrRE = / x - ( o n | b i n d | d a t a | t e x t | m o d e l | c l o a k ) / ;
1391
+ var xAttrRE = / x - ( o n | b i n d | d a t a | t e x t | m o d e l | c l o a k | r e f ) / ;
1369
1392
return xAttrRE . test ( attr . name ) ;
1370
1393
}
1371
1394
function getXAttrs ( el , type ) {
1372
1395
return Array . from ( el . attributes ) . filter ( isXAttr ) . map ( function ( attr ) {
1373
- var typeMatch = attr . name . match ( / x - ( o n | b i n d | d a t a | t e x t | m o d e l | c l o a k ) / ) ;
1396
+ var typeMatch = attr . name . match ( / x - ( o n | b i n d | d a t a | t e x t | m o d e l | c l o a k | r e f ) / ) ;
1374
1397
var valueMatch = attr . name . match ( / : ( [ a - z A - Z \- ] + ) / ) ;
1375
1398
var modifiers = attr . name . match ( / \. [ ^ . \] ] + (? = [ ^ \] ] * $ ) / g) || [ ] ;
1376
1399
return {
0 commit comments