astro-async-loader 0.0.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.md ADDED
@@ -0,0 +1,75 @@
1
+ # Astro Component Template 🧑‍🚀
2
+
3
+ This is [an unofficial template](#how-is-this-different-from-the-official-component-template) meant to ease the development of components for [Astro](https://astro.build/) that are intended for distribution. It does so by providing you with:
4
+
5
+ - A clear default directory structure
6
+ - Proper TypeScript settings for working with Astro
7
+ - Default settings for ESLint, Prettier and EditorConfig inspired by the formatting used in the Astro project itself (also, [the config files are typed 👀](https://princesseuh.netlify.app/article/youshouldtypeyourconfigfiles/))
8
+ - Ready-to-use testing tools powered by the libraries also used by the Astro project (Mocha and Chai), also contains [astro-component-tester](https://github.com/Princesseuh/astro-component-tester) to help you test the output of your component(s)
9
+ - Preconfigured VS Code workspace settings file with settings meant to make development cozy and nice
10
+ - Use a example folder to help previewing the Component without npm link
11
+
12
+ Hopefully, all of this together will provide you with a fun and comfortable development environnement for working on your Astro component! 🚀 Also, never forget that this is only a template to get you started, if you don't agree with any of the choices made, feel free to change it to fit your project better!
13
+
14
+ **⚠️ Don't forget:** You should edit `package.json` with the info relevant to your project, such as a proper `name`, a license, a link to the repository for the npm website and other settings. You should also adjust the Astro `peerDependency` to the lowest version of Astro you support.
15
+
16
+ ## Folder Structure
17
+
18
+ ```plaintext
19
+ ├── .vscode/ # VS Code settings folder
20
+ │ ├── settings.json # Workspace settings
21
+ │ └── extensions.json # Recommended extensions to install
22
+ ├── example/ # Preview Your component here
23
+ ├── src/ # Your component source code
24
+ │ ├── Component.astro # Example component file
25
+ │ └── main.ts # Example source code file
26
+ ├── test/ # Your component tests
27
+ │ └── example.test.js # Example tests
28
+ └── index.ts # Should contain all the exports your component provide to users
29
+ ```
30
+
31
+ ESLint, Prettier and EditorConfig settings are respectively located in the following files: `.eslintrc.js`, `.prettierrc.js` and `.editorconfig` at the root of this template project.
32
+
33
+ ## Commands
34
+
35
+ The following npm scripts are provided to lint and format your project:
36
+
37
+ | Command | Action |
38
+ | :--------------- | :------------------------------------------------------------ |
39
+ | `npm run test` | Run tests using Mocha |
40
+ | `npm run format` | Format your project using Prettier, this edits files in-place |
41
+ | `npm run lint` | Lint your project using ESLint |
42
+ | `npm run dev` | Run dev inside example project |
43
+
44
+ In VS Code, you can access those commands in the Explorer in the `NPM Scripts` section.
45
+
46
+ ## Frequently asked questions
47
+
48
+ ### How is this different from [the official component template](https://github.com/withastro/astro/tree/main/examples/component)?
49
+
50
+ At the end of the day, they both have the same goal: Giving you a template to start from to build a component for Astro. However, they have slightly different philosophies.
51
+
52
+ Notably, the official template uses a mono-repo structure, whereas this template uses a normal, straightforward repo. Additionally, this template is a bit more opinionated than the official one, giving you preconfigured support for ESLint, Prettier, VS Code and EditorConfig, as well as testing support.
53
+
54
+ It's up to you to choose which one you prefer, they're both good options!
55
+
56
+ ### How do I try my component in development?
57
+
58
+ > `npm` is used here for brevity, the same concept applies to other package managers!
59
+
60
+ This template is a normal npm package, which mean that you can install it as a local folder or using [npm link](https://docs.npmjs.com/cli/v8/commands/npm-link).
61
+
62
+ For example, with the following folder structure:
63
+
64
+ ```plaintext
65
+ ├── component/ # Your component using this template
66
+ └── project/ # A standard Astro project
67
+ ```
68
+
69
+ You can go into `project` and type the following command: `npm link ../component`. Changes to your component will be automatically reflected in your Astro project!
70
+
71
+ ### Which package manager should I use?
72
+
73
+ The one you prefer! This template makes no assumption.
74
+
75
+ The only package-manager-related thing in this repo is that the prettier plugin has the proper configuration needed to work with pnpm (but it works with the other too, pnpm just needs [additional settings](https://github.com/withastro/prettier-plugin-astro#pnpm-support)).
package/index.ts ADDED
@@ -0,0 +1,3 @@
1
+ import AstroAsyncIframe from './src/AsyncIframe.astro';
2
+
3
+ export { AstroAsyncIframe };
package/package.json ADDED
@@ -0,0 +1,40 @@
1
+ {
2
+ "name": "astro-async-loader",
3
+ "version": "0.0.0",
4
+ "description": "Astro components for elements, that load asynchronously, and should have loading indicators.",
5
+ "repository": "https://github.com/jonasfroeller/astro.async.loader",
6
+ "license": "MIT",
7
+ "type": "module",
8
+ "exports": {
9
+ ".": "./index.ts"
10
+ },
11
+ "files": [
12
+ "src",
13
+ "index.ts"
14
+ ],
15
+ "keywords": [
16
+ "astro-component"
17
+ ],
18
+ "scripts": {
19
+ "test": "mocha --parallel --timeout 15000",
20
+ "format": "prettier -w .",
21
+ "lint": "eslint . --ext .ts,.js,.astro src",
22
+ "dev": "cd example && astro dev"
23
+ },
24
+ "devDependencies": {
25
+ "@types/chai": "^5.0.1",
26
+ "@types/eslint": "^9.6.1",
27
+ "@types/mocha": "^10.0.10",
28
+ "@types/node": "^22.10.5",
29
+ "@types/prettier": "^3.0.0",
30
+ "@typescript-eslint/parser": "^8.19.0",
31
+ "astro": "^5.1.2",
32
+ "chai": "^5.1.2",
33
+ "eslint": "^9.17.0",
34
+ "eslint-plugin-astro": "^1.3.1",
35
+ "mocha": "^11.0.1",
36
+ "prettier": "^3.4.2",
37
+ "prettier-plugin-astro": "^0.14.1",
38
+ "typescript": "^5.7.2"
39
+ }
40
+ }
@@ -0,0 +1,93 @@
1
+ <div class="async-iframe-wrapper">
2
+ <div class="loader-container">
3
+ <div class="loader"></div>
4
+ </div>
5
+
6
+ <div class="iframe-container">
7
+ <slot />
8
+ </div>
9
+ </div>
10
+
11
+ <script>
12
+ function setupIframe() {
13
+ const wrapper = document.getElementsByClassName('async-iframe-wrapper')[0];
14
+ const loaderContainer = wrapper.getElementsByClassName('loader-container')[0];
15
+ const iframe = wrapper.querySelector('iframe');
16
+
17
+ if (iframe && loaderContainer) {
18
+ const handleLoad = () => {
19
+ loaderContainer.classList.add('hidden');
20
+ iframe.removeEventListener('load', handleLoad);
21
+ };
22
+
23
+ iframe.addEventListener('load', handleLoad);
24
+ }
25
+ }
26
+
27
+ if (document.readyState === 'loading') {
28
+ const handleDOMContentLoaded = () => {
29
+ setupIframe();
30
+ document.removeEventListener('DOMContentLoaded', handleDOMContentLoaded);
31
+ };
32
+
33
+ document.addEventListener('DOMContentLoaded', handleDOMContentLoaded);
34
+ } else {
35
+ setupIframe();
36
+ }
37
+ </script>
38
+
39
+ <style>
40
+ .async-iframe-wrapper {
41
+ position: relative;
42
+ padding-top: 85%;
43
+ height: 0;
44
+ overflow: hidden;
45
+ }
46
+
47
+ .loader-container {
48
+ position: absolute;
49
+ top: 0;
50
+ left: 0;
51
+ right: 0;
52
+ bottom: 0;
53
+ display: flex;
54
+ align-items: center;
55
+ justify-content: center;
56
+ z-index: 10;
57
+ }
58
+
59
+ .loader {
60
+ width: 2rem;
61
+ height: 2rem;
62
+ border-radius: 50%;
63
+ border: 0.125rem solid transparent;
64
+ border-top-color: #3b82f6;
65
+ animation: spin 1s linear infinite;
66
+ }
67
+
68
+ @keyframes spin {
69
+ 0% { transform: rotate(0deg); }
70
+ 100% { transform: rotate(360deg); }
71
+ }
72
+
73
+ .iframe-container {
74
+ position: absolute;
75
+ top: 0px;
76
+ left: 0px;
77
+ right: 0px;
78
+ bottom: 0px;
79
+ }
80
+
81
+ :global(iframe) {
82
+ position: absolute;
83
+ top: 0px;
84
+ left: 0px;
85
+ width: 100%;
86
+ height: 100%;
87
+ border: 0px;
88
+ }
89
+
90
+ .hidden {
91
+ display: none !important;
92
+ }
93
+ </style>
package/src/env.d.ts ADDED
@@ -0,0 +1 @@
1
+ /// <reference types="astro/client" />