1
1
/**
2
- * vue-meta v3.0.0-alpha.2
2
+ * vue-meta v3.0.0-alpha.3
3
3
* (c) 2021
4
4
* - Pim (@pimlie)
5
5
* - All the amazing contributors
@@ -12,7 +12,19 @@ Object.defineProperty(exports, '__esModule', { value: true });
12
12
13
13
var vue = require ( 'vue' ) ;
14
14
15
- const resolveOption = predicament => ( options , contexts ) => {
15
+ function _interopNamespace ( e ) {
16
+ if ( e && e . __esModule ) return e ;
17
+ var n = Object . create ( null ) ;
18
+ if ( e ) {
19
+ Object . keys ( e ) . forEach ( function ( k ) {
20
+ n [ k ] = e [ k ] ;
21
+ } ) ;
22
+ }
23
+ n [ 'default' ] = e ;
24
+ return Object . freeze ( n ) ;
25
+ }
26
+
27
+ const resolveOption = ( predicament , initialValue ) => ( options , contexts ) => {
16
28
let resolvedIndex = - 1 ;
17
29
contexts . reduce ( ( acc , context , index ) => {
18
30
const retval = predicament ( acc , context ) ;
@@ -21,7 +33,7 @@ const resolveOption = predicament => (options, contexts) => {
21
33
return retval ;
22
34
}
23
35
return acc ;
24
- } , undefined ) ;
36
+ } , initialValue ) ;
25
37
if ( resolvedIndex > - 1 ) {
26
38
return options [ resolvedIndex ] ;
27
39
}
@@ -40,14 +52,15 @@ function setup(context) {
40
52
}
41
53
context . depth = depth ;
42
54
}
43
- const resolve = resolveOption ( ( acc , context ) => {
55
+ const resolve = resolveOption ( ( currentValue , context ) => {
44
56
const { depth } = context ;
45
- if ( ! acc || depth > acc ) {
46
- return acc ;
57
+ if ( ! currentValue || depth > currentValue ) {
58
+ return depth ;
47
59
}
60
+ return currentValue ;
48
61
} ) ;
49
62
50
- var deepest = /*#__PURE__*/ Object . freeze ( {
63
+ var defaultResolver = /*#__PURE__*/ Object . freeze ( {
51
64
__proto__ : null ,
52
65
setup : setup ,
53
66
resolve : resolve
@@ -161,10 +174,9 @@ function getTagConfigItem(tagOrName, key) {
161
174
* \/\*#\_\_PURE\_\_\*\/
162
175
* So that rollup can tree-shake them if necessary.
163
176
*/
164
- ( process . env . NODE_ENV !== 'production' )
165
- ? Object . freeze ( { } )
166
- : { } ;
167
- ( process . env . NODE_ENV !== 'production' ) ? Object . freeze ( [ ] ) : [ ] ;
177
+ Object . freeze ( { } )
178
+ ;
179
+ Object . freeze ( [ ] ) ;
168
180
const isArray = Array . isArray ;
169
181
const isFunction = ( val ) => typeof val === 'function' ;
170
182
const isString = ( val ) => typeof val === 'string' ;
@@ -252,20 +264,23 @@ const recompute = (context, sources, target, path = []) => {
252
264
}
253
265
for ( const key of keys ) {
254
266
// This assumes consistent types usages for keys across sources
267
+ // @ts -ignore
255
268
if ( isPlainObject ( sources [ 0 ] [ key ] ) ) {
256
269
if ( ! target [ key ] ) {
257
270
target [ key ] = { } ;
258
271
}
259
272
const keySources = [ ] ;
260
273
for ( const source of sources ) {
261
274
if ( key in source ) {
275
+ // @ts -ignore
262
276
keySources . push ( source [ key ] ) ;
263
277
}
264
278
}
265
279
recompute ( context , keySources , target [ key ] , [ ...path , key ] ) ;
266
280
continue ;
267
281
}
268
282
// Ensure the target is an array if source is an array and target is empty
283
+ // @ts -ignore
269
284
if ( ! target [ key ] && isArray ( sources [ 0 ] [ key ] ) ) {
270
285
target [ key ] = [ ] ;
271
286
}
@@ -309,7 +324,7 @@ const createHandler = (context, resolveContext, pathSegments = []) => ({
309
324
if ( ! value [ IS_PROXY ] ) {
310
325
const keyPath = [ ...pathSegments , key ] ;
311
326
value = createProxy ( context , value , resolveContext , keyPath ) ;
312
- target [ key ] = value ;
327
+ Reflect . set ( target , key , value ) ;
313
328
}
314
329
return value ;
315
330
} ,
@@ -381,6 +396,7 @@ const createHandler = (context, resolveContext, pathSegments = []) => ({
381
396
let active = context . active ;
382
397
let index = 0 ;
383
398
for ( const segment of pathSegments ) {
399
+ // @ts -ignore
384
400
proxies = proxies . map ( proxy => proxy [ segment ] ) ;
385
401
if ( isArrayItem && index === pathSegments . length - 1 ) {
386
402
activeSegmentKey = segment ;
@@ -421,11 +437,8 @@ const createHandler = (context, resolveContext, pathSegments = []) => ({
421
437
}
422
438
} ) ;
423
439
424
- const createMergedObject = ( resolve , active = { } ) => {
440
+ const createMergedObject = ( resolve , active ) => {
425
441
const sources = [ ] ;
426
- if ( ! active ) {
427
- active = { } ;
428
- }
429
442
const context = {
430
443
active,
431
444
resolve,
@@ -443,7 +456,7 @@ const createMergedObject = (resolve, active = {}) => {
443
456
return proxy ;
444
457
} ,
445
458
delSource : ( sourceOrProxy , recompute = true ) => {
446
- const index = sources . findIndex ( src => src === sourceOrProxy || src [ PROXY_TARGET ] === sourceOrProxy ) ;
459
+ const index = sources . findIndex ( source => source === sourceOrProxy || source [ PROXY_TARGET ] === sourceOrProxy ) ;
447
460
if ( index > - 1 ) {
448
461
sources . splice ( index , 1 ) ;
449
462
if ( recompute ) {
@@ -727,7 +740,7 @@ function addVnode(teleports, to, vnodes) {
727
740
}
728
741
teleports [ to ] . push ( ...nodes ) ;
729
742
}
730
- const createMetaManager = ( config , resolver ) => MetaManager . create ( config , resolver ) ;
743
+ const createMetaManager = ( config , resolver ) => MetaManager . create ( config || defaultConfig , resolver || defaultResolver ) ;
731
744
class MetaManager {
732
745
constructor ( config , target , resolver ) {
733
746
this . ssrCleanedUp = false ;
@@ -850,9 +863,8 @@ MetaManager.create = (config, resolver) => {
850
863
return manager ;
851
864
} ;
852
865
853
- // rollup doesnt like an import as it cant find the export so use require
854
- const { renderToString } = require ( '@vue/server-renderer' ) ;
855
866
async function renderToStringWithMeta ( app ) {
867
+ const { renderToString } = await Promise . resolve ( ) . then ( function ( ) { return /*#__PURE__*/ _interopNamespace ( require ( '@vue/server-renderer' ) ) ; } ) ;
856
868
const ctx = { } ;
857
869
const html = await renderToString ( app , ctx ) ;
858
870
// TODO: better way of determining whether meta was rendered with the component or not
@@ -872,7 +884,7 @@ async function renderToStringWithMeta(app) {
872
884
}
873
885
874
886
exports . createMetaManager = createMetaManager ;
875
- exports . deepestResolver = deepest ;
887
+ exports . deepestResolver = defaultResolver ;
876
888
exports . defaultConfig = defaultConfig ;
877
889
exports . getCurrentManager = getCurrentManager ;
878
890
exports . renderToStringWithMeta = renderToStringWithMeta ;
0 commit comments