@wcstack/autoloader 4.5.0 → 4.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.ja.md +22 -0
- package/README.md +22 -0
- package/dist/auto.d.ts +2 -0
- package/package.json +5 -2
package/README.ja.md
CHANGED
|
@@ -152,6 +152,28 @@ export default class UiButton extends HTMLElement {
|
|
|
152
152
|
}
|
|
153
153
|
```
|
|
154
154
|
|
|
155
|
+
### wcstack 自身のタグを読み込む
|
|
156
|
+
|
|
157
|
+
wcstack のパッケージはクラスを `default` でなく名前で出し、いくつかのパッケージは 2 つ以上のタグを定義します。`<wcs-fetch>` には `<wcs-fetch-header>` と `<wcs-fetch-body>` が付きます。パッケージごとに包みのファイルを 1 つ作り、パッケージの `/auto` を読み込んで(パッケージのタグがすべて定義されます)、定義されたクラスを autoloader に渡してください:
|
|
158
|
+
|
|
159
|
+
```javascript
|
|
160
|
+
// components/wcs/fetch.js: <wcs-fetch> と、それに付く <wcs-fetch-header> / <wcs-fetch-body>
|
|
161
|
+
import "https://esm.run/@wcstack/fetch/auto";
|
|
162
|
+
export default customElements.get("wcs-fetch");
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
```json
|
|
166
|
+
{
|
|
167
|
+
"imports": {
|
|
168
|
+
"@components/wcs/": "./components/wcs/"
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
autoloader はタグを 1 つずつ順に読み込み、すでに定義されたタグは飛ばすので、`<wcs-fetch-header>` に自分のファイルは要りません。ファイルの名前はパッケージでなくタグから付けます: `<wcs-ws>`(`@wcstack/websocket`)は `ws.js`、`<wcs-geo>`(`@wcstack/geolocation`)は `geo.js` です。
|
|
174
|
+
|
|
175
|
+
クラスを 1 つだけ出し直す包み(`export { WcsFetch as default } from "https://esm.run/@wcstack/fetch"`)では補助のタグが定義されず、autoloader は `fetch-header.js` を探しに行きます。`<wcs-fetch>` はそのヘッダーや本文なしで要求を送ります。4.6 から、`[wcs/fetch-helper-undefined]` で警告します。
|
|
176
|
+
|
|
155
177
|
## カスタマイズドビルトイン要素(`is`属性)
|
|
156
178
|
|
|
157
179
|
オートローダーは`is`属性を使用したカスタマイズドビルトイン要素を検出します:
|
package/README.md
CHANGED
|
@@ -152,6 +152,28 @@ export default class UiButton extends HTMLElement {
|
|
|
152
152
|
}
|
|
153
153
|
```
|
|
154
154
|
|
|
155
|
+
### Loading wcstack's own tags
|
|
156
|
+
|
|
157
|
+
The wcstack packages export their classes by name, not as `default`, and some packages define more than one tag: `<wcs-fetch>` comes with `<wcs-fetch-header>` and `<wcs-fetch-body>`. Give each package one wrapper file that imports the package's `/auto` entry, which defines every tag of the package, and hands the autoloader the class it defined:
|
|
158
|
+
|
|
159
|
+
```javascript
|
|
160
|
+
// components/wcs/fetch.js: <wcs-fetch>, and with it <wcs-fetch-header> / <wcs-fetch-body>
|
|
161
|
+
import "https://esm.run/@wcstack/fetch/auto";
|
|
162
|
+
export default customElements.get("wcs-fetch");
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
```json
|
|
166
|
+
{
|
|
167
|
+
"imports": {
|
|
168
|
+
"@components/wcs/": "./components/wcs/"
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
The autoloader loads one tag after another and skips a tag that is already defined, so `<wcs-fetch-header>` needs no file of its own. The file is named after the tag, not the package: `<wcs-ws>` (`@wcstack/websocket`) is `ws.js`, `<wcs-geo>` (`@wcstack/geolocation`) is `geo.js`.
|
|
174
|
+
|
|
175
|
+
A wrapper that re-exports one class (`export { WcsFetch as default } from "https://esm.run/@wcstack/fetch"`) leaves the helper tags undefined, and the autoloader then looks for `fetch-header.js`. `<wcs-fetch>` sends its request without their header or body; since 4.6 it warns `[wcs/fetch-helper-undefined]`.
|
|
176
|
+
|
|
155
177
|
## Customized Built-in Elements (`is` attribute)
|
|
156
178
|
|
|
157
179
|
The autoloader detects customized built-in elements using the `is` attribute:
|
package/dist/auto.d.ts
ADDED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wcstack/autoloader",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.6.0",
|
|
4
4
|
"description": "Auto-detect and dynamically import undefined custom elements via Import Maps. Zero dependencies, buildless.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.esm.js",
|
|
@@ -11,7 +11,10 @@
|
|
|
11
11
|
"types": "./dist/index.d.ts",
|
|
12
12
|
"import": "./dist/index.esm.js"
|
|
13
13
|
},
|
|
14
|
-
"./auto":
|
|
14
|
+
"./auto": {
|
|
15
|
+
"types": "./dist/auto.d.ts",
|
|
16
|
+
"import": "./dist/auto.min.js"
|
|
17
|
+
}
|
|
15
18
|
},
|
|
16
19
|
"files": [
|
|
17
20
|
"dist"
|