Commit 977e2b4 1 parent e917c0f commit 977e2b4 Copy full SHA for 977e2b4
File tree 3 files changed +18
-11
lines changed
3 files changed +18
-11
lines changed Original file line number Diff line number Diff line change @@ -96,15 +96,24 @@ class UComponent extends HTMLElement {
96
96
97
97
98
98
window . loadComponent = ( function ( ) {
99
- console . debug ( 'LOADER' , `loadComponent...` ) ;
99
+ // plain script includes can read document.currentScript.src
100
+ // modules can use meta
101
+ const loaderURL = new URL ( document . currentScript . src ) ;
100
102
101
- async function fetchSFC ( tagName , folder = '' ) {
102
- let def ;
103
+ console . debug ( 'SFC' , `loadComponent...` ) ;
103
104
104
- if ( folder === undefined ) folder = '' ;
105
- if ( folder . length > 0 && ( ! folder . endsWith ( '/' ) ) ) folder += '/' ;
106
- const url = folder + tagName + '.vue' ;
107
- console . debug ( 'SFC' , `registerComponent(${ tagName } , ${ url } )` ) ;
105
+ async function fetchSFC ( tagName , folder = undefined ) {
106
+ let def ;
107
+
108
+ const sfcImpl = tagName + '.vue' ;
109
+ let baseUrl = loaderURL ;
110
+
111
+ if ( folder ) {
112
+ baseUrl = new URL ( folder , document . location . href ) ;
113
+ }
114
+
115
+ const url = new URL ( sfcImpl , baseUrl ) ;
116
+ console . debug ( 'SFC' , `loading module ${ tagName } from ${ url . href } ...` ) ;
108
117
109
118
// get DOM from sfc-file
110
119
const dom = await fetch ( url )
Original file line number Diff line number Diff line change @@ -23,15 +23,13 @@ the markdown-it.js is required to be loaded. Ir can be found in https://markdown
23
23
24
24
Open Topics:
25
25
26
- The foldername /sfc/ is still hardcoded. It should be replaced by a variable / placeholder.
26
+ The foldername /sfc/ is hardcoded. It should be replaced by a variable / placeholder.
27
27
28
28
References:
29
29
* https://developer.mozilla.org/en-US/docs/Web/Web_Components/Using_custom_elements
30
30
* https://zerodevx.github.io/zero-md/
31
31
* requestIdleCallback, SetTimeout VS RequestAnimationFrame
32
32
33
-
34
-
35
33
-->
36
34
37
35
Original file line number Diff line number Diff line change @@ -60,7 +60,7 @@ <h2>MD</h2>
60
60
< u-markdown src ="./test-md1.md " style =" background-color: azure; "> </ u-markdown >
61
61
62
62
< script >
63
- loadComponent ( 'u-markdown' , '/sfc/' ) . then ( ( ) => {
63
+ loadComponent ( 'u-markdown' ) . then ( ( ) => {
64
64
console . log ( 'Page' , "all components loaded." ) ;
65
65
} ) ;
66
66
You can’t perform that action at this time.
0 commit comments