@enquio/astro-popup 1.1.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 +45 -0
- package/dist/EnquioPopup.astro +13 -0
- package/dist/browser.js +48 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/package.json +37 -0
package/README.md
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
# @enquio/astro-popup
|
|
2
|
+
|
|
3
|
+
For prerendered Astro websites, with ordinary navigation or `ClientRouter`.
|
|
4
|
+
Supports Astro >=7.3.5 <8; the pinned verification version is 7.3.5. SSR adapters
|
|
5
|
+
are outside this release's support scope.
|
|
6
|
+
|
|
7
|
+
After the coordinated public release:
|
|
8
|
+
|
|
9
|
+
```sh
|
|
10
|
+
npm install @enquio/astro-popup
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
Add the import and component to your existing shared layout:
|
|
14
|
+
|
|
15
|
+
<!-- example:astro -->
|
|
16
|
+
```astro
|
|
17
|
+
---
|
|
18
|
+
import { EnquioPopup } from '@enquio/astro-popup';
|
|
19
|
+
---
|
|
20
|
+
|
|
21
|
+
<EnquioPopup projectId="YOUR_PROJECT_ID" />
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
Keep the layout's existing content and router choice. Use one component per page.
|
|
25
|
+
No configuration integration, `client:*` directive or copied helper script is needed.
|
|
26
|
+
An empty project ID renders no popup and makes no runtime request.
|
|
27
|
+
The package handles popup identity for the same project and runtime/style persistence
|
|
28
|
+
with ClientRouter. A different project replaces the popup; leaving a layout without
|
|
29
|
+
the component removes it. Shared resources can remain until the document closes.
|
|
30
|
+
|
|
31
|
+
Verify direct loads, reload, links, Back/Forward and your form's visibility rules.
|
|
32
|
+
To remove the integration, remove the import and component from your layout.
|
|
33
|
+
|
|
34
|
+
<details>
|
|
35
|
+
<summary>Diagnostics</summary>
|
|
36
|
+
|
|
37
|
+
The [core loader](../core/README.md) owns readiness, timeout, retry and console
|
|
38
|
+
diagnostics. Check the browser console and Network panel for popup.js, main.js
|
|
39
|
+
and polyfills.js. A timeout does not cancel a pending load. See
|
|
40
|
+
[troubleshooting](../../docs/troubleshooting.md).
|
|
41
|
+
|
|
42
|
+
</details>
|
|
43
|
+
|
|
44
|
+
Local tarball tests do not establish public npm availability or hosted deployment.
|
|
45
|
+
See the [release procedure](../../docs/npm-release.md).
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
---
|
|
2
|
+
export interface Props {
|
|
3
|
+
projectId: string;
|
|
4
|
+
}
|
|
5
|
+
const { projectId } = Astro.props;
|
|
6
|
+
const id = projectId.trim();
|
|
7
|
+
---
|
|
8
|
+
{id && <div data-enquio-astro-owner transition:persist={`enquio-project-${encodeURIComponent(id)}`}>
|
|
9
|
+
<enquio-popup project-id={id}></enquio-popup>
|
|
10
|
+
</div>}
|
|
11
|
+
<script>
|
|
12
|
+
import './browser.js';
|
|
13
|
+
</script>
|
package/dist/browser.js
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { loadEnquioScript } from '@enquio/popup-core';
|
|
2
|
+
|
|
3
|
+
// Symbol.for also protects against a second copy of the package in a host bundle.
|
|
4
|
+
const installed = Symbol.for('@enquio/astro-popup');
|
|
5
|
+
if (typeof document !== 'undefined' && !document[installed]) {
|
|
6
|
+
document[installed] = true;
|
|
7
|
+
const owners = new WeakSet();
|
|
8
|
+
const resources = new Map();
|
|
9
|
+
const scopes = new Set();
|
|
10
|
+
let resourceNumber = 0;
|
|
11
|
+
function mount() {
|
|
12
|
+
const owner = document.querySelector('[data-enquio-astro-owner]');
|
|
13
|
+
if (!owner || owners.has(owner) || !owner.querySelector('enquio-popup[project-id]')) return;
|
|
14
|
+
owners.add(owner);
|
|
15
|
+
void loadEnquioScript().catch(() => {});
|
|
16
|
+
}
|
|
17
|
+
function runtimeScript(script) {
|
|
18
|
+
return script.id === 'enquio-popup-script' || /^https:\/\/public\.newapp\.enquio\.eu\/(main|polyfills)\.js(?:\?enquio-retry=[1-9]\d*)?$/.test(script.src);
|
|
19
|
+
}
|
|
20
|
+
document.addEventListener('astro:before-swap', (event) => {
|
|
21
|
+
const host = document.querySelector('[data-enquio-astro-owner] enquio-popup');
|
|
22
|
+
// Remember scopes even on pages without a popup, so a later return retains styles.
|
|
23
|
+
if (host)
|
|
24
|
+
for (const element of [host, ...host.querySelectorAll('*')]) {
|
|
25
|
+
for (const name of element.getAttributeNames()) {
|
|
26
|
+
if (name.startsWith('_ngcontent-') || name.startsWith('_nghost-')) scopes.add(name);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
const nodes = [
|
|
30
|
+
...Array.from(document.head.querySelectorAll('script[src]')).filter(runtimeScript),
|
|
31
|
+
...Array.from(document.head.querySelectorAll('style')).filter((style) => [...scopes].some((scope) => style.textContent.includes(`[${scope}]`))),
|
|
32
|
+
];
|
|
33
|
+
for (const node of nodes) if (!resources.has(node)) resources.set(node, `enquio-resource-${++resourceNumber}`);
|
|
34
|
+
for (const [node, id] of resources) {
|
|
35
|
+
if (!node.isConnected) {
|
|
36
|
+
resources.delete(node);
|
|
37
|
+
continue;
|
|
38
|
+
}
|
|
39
|
+
node.setAttribute('data-astro-transition-persist', id);
|
|
40
|
+
if (node instanceof HTMLScriptElement) node.setAttribute('data-astro-exec', '');
|
|
41
|
+
const placeholder = event.newDocument.createElement('meta');
|
|
42
|
+
placeholder.setAttribute('data-astro-transition-persist', id);
|
|
43
|
+
event.newDocument.head.append(placeholder);
|
|
44
|
+
}
|
|
45
|
+
});
|
|
46
|
+
document.addEventListener('astro:page-load', mount);
|
|
47
|
+
mount();
|
|
48
|
+
}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default as EnquioPopup } from './EnquioPopup.astro';
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default as EnquioPopup } from './EnquioPopup.astro';
|
package/package.json
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@enquio/astro-popup",
|
|
3
|
+
"version": "1.1.0",
|
|
4
|
+
"description": "Enquio popup component for prerendered Astro websites",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "https://github.com/skutam/EnquioWrappers.git",
|
|
10
|
+
"directory": "packages/astro"
|
|
11
|
+
},
|
|
12
|
+
"files": [
|
|
13
|
+
"dist"
|
|
14
|
+
],
|
|
15
|
+
"exports": {
|
|
16
|
+
".": {
|
|
17
|
+
"types": "./dist/index.d.ts",
|
|
18
|
+
"default": "./dist/index.js"
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
"types": "./dist/index.d.ts",
|
|
22
|
+
"scripts": {
|
|
23
|
+
"build": "node build.cjs",
|
|
24
|
+
"prepublishOnly": "npm run build"
|
|
25
|
+
},
|
|
26
|
+
"dependencies": {
|
|
27
|
+
"@enquio/popup-core": "1.1.0"
|
|
28
|
+
},
|
|
29
|
+
"peerDependencies": {
|
|
30
|
+
"astro": ">=7.3.5 <8"
|
|
31
|
+
},
|
|
32
|
+
"devDependencies": {
|
|
33
|
+
"astro": "7.3.5",
|
|
34
|
+
"@astrojs/check": "0.9.9",
|
|
35
|
+
"typescript": "5.9.3"
|
|
36
|
+
}
|
|
37
|
+
}
|