@popgrids/embed 0.0.6 → 0.0.8
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/AGENTS.md +19 -4
- package/README.md +19 -3
- package/dist/loader.js +1 -0
- package/package.json +4 -3
package/AGENTS.md
CHANGED
|
@@ -13,11 +13,12 @@ This project contains the embeddable Web Component discussion widget for PopGrid
|
|
|
13
13
|
- **Build System**: Vite.
|
|
14
14
|
- `vite.config.ts` builds the library version.
|
|
15
15
|
- `vite.embed.config.ts` builds the single self-contained embeddable JS script.
|
|
16
|
+
- `vite.loader.config.ts` builds `dist/loader.js` from [loader.ts](./src/loader.ts): the tiny classic script served at `https://cdn.popgrids.io/embed.js`, which loads this release's `embed.js`.
|
|
16
17
|
|
|
17
18
|
## Core Development Commands
|
|
18
19
|
|
|
19
20
|
- `pnpm run dev` — Watch-builds both library and embed scripts.
|
|
20
|
-
- `pnpm run build` — Clean and build
|
|
21
|
+
- `pnpm run build` — Clean and build all three targets (`dist/`).
|
|
21
22
|
- `pnpm run demo:dev` — Launches concurrently the dev watch compiler and a live-reload server (`live-server`) on port 5500.
|
|
22
23
|
|
|
23
24
|
## Component Conventions
|
|
@@ -124,13 +125,27 @@ This package publishes to npm as [`@popgrids/embed`](https://www.npmjs.com/packa
|
|
|
124
125
|
through the monorepo's changesets flow; see "Releasing ui and embed" in the root `AGENTS.md`.
|
|
125
126
|
|
|
126
127
|
- **Every change that affects the published output** needs a changeset (`pnpm changeset` from the
|
|
127
|
-
root).
|
|
128
|
-
|
|
128
|
+
root). web's Composer preview bundles the workspace copy, so it picks up an embed change on the
|
|
129
|
+
next deploy, released or not; customer sites get it only once it's released.
|
|
129
130
|
- **Auth is npm OIDC trusted publishing** — no `NPM_TOKEN`. The trusted publisher on npmjs.com
|
|
130
131
|
points at repo `popgrids/popgrids`, workflow `release.yml`.
|
|
131
132
|
- `prepublishOnly` runs `check` + `build`. The root `.github/workflows/ci.yml` runs embed's `check`
|
|
132
133
|
and `build` on every PR that touches it.
|
|
133
134
|
- The published package ships both entries: `.` (the library, deps external) and `./embed` /
|
|
134
|
-
`dist/embed.js` (the self-contained CDN bundle, also the `unpkg`/`jsdelivr` target)
|
|
135
|
+
`dist/embed.js` (the self-contained CDN bundle, also the `unpkg`/`jsdelivr` target), plus
|
|
136
|
+
`dist/loader.js`. `pnpm run dev` doesn't rebuild the loader: it always points at the CDN, so
|
|
137
|
+
local demos load `dist/embed.js` directly.
|
|
138
|
+
- **Customer sites load releases from `cdn.popgrids.io`**, never from `main`. After a release,
|
|
139
|
+
`.github/workflows/embed-cdn.yml` copies the npm tarball's `embed.js`, its map and `loader.js` to
|
|
140
|
+
`embed/<version>/` in the `popgrids` R2 bucket (cached for a year), then that `loader.js` to
|
|
141
|
+
`embed.js` (cached 5 minutes). To roll back, run that workflow by hand with an earlier version
|
|
142
|
+
(0.0.7 or later; older releases have no loader). It uses the `CLOUDFLARE_R2_API_TOKEN` secret, an
|
|
143
|
+
R2 token scoped to the `popgrids` bucket. That token can write anywhere in the bucket, which
|
|
144
|
+
also serves the marketing videos, so the workflow's object keys are fixed: `embed.js` and
|
|
145
|
+
`embed/<version>/`, nothing else.
|
|
146
|
+
- **CORS:** the loader loads the bundle as a cross-origin module, which browsers refuse without
|
|
147
|
+
`Access-Control-Allow-Origin`. A Transform Rule in the `popgrids.io` zone (Rules → Transform
|
|
148
|
+
Rules → Modify Response Header) sets `Access-Control-Allow-Origin: *` on `cdn.popgrids.io`
|
|
149
|
+
paths starting with `/embed`. Without it, every customer embed fails silently.
|
|
135
150
|
|
|
136
151
|
Issues, triage labels, domain docs, and Plan Mode are shared across the monorepo; see the root `AGENTS.md`.
|
package/README.md
CHANGED
|
@@ -38,15 +38,31 @@ import type { AuthUser, Comment, CommentAuthor, Grid } from "@popgrids/embed";
|
|
|
38
38
|
|
|
39
39
|
### Script tag / CDN
|
|
40
40
|
|
|
41
|
-
|
|
42
|
-
to load:
|
|
41
|
+
Add one tag where the grid should appear:
|
|
43
42
|
|
|
44
43
|
```html
|
|
45
|
-
<script
|
|
44
|
+
<script src="https://cdn.popgrids.io/embed.js" data-key="pk_your_public_key" async></script>
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
The grid renders right after the tag and takes its `data-*` attributes (see below), so
|
|
48
|
+
`data-id="article-hero"` on the tag names the thread. Repeat the tag for more grids; the widget
|
|
49
|
+
loads once.
|
|
50
|
+
|
|
51
|
+
`https://cdn.popgrids.io/embed.js` always serves the latest release, cached for 5 minutes. It's a
|
|
52
|
+
tiny loader for that release's bundle, which lives at an immutable, versioned URL. To pin a version,
|
|
53
|
+
load its loader instead: `https://cdn.popgrids.io/embed/0.0.7/loader.js`.
|
|
54
|
+
|
|
55
|
+
To place grids yourself, leave out `data-key` and add `<pop-grid>` elements anywhere on the page:
|
|
56
|
+
|
|
57
|
+
```html
|
|
58
|
+
<script src="https://cdn.popgrids.io/embed.js" async></script>
|
|
46
59
|
|
|
47
60
|
<pop-grid data-key="pk_your_public_key"></pop-grid>
|
|
48
61
|
```
|
|
49
62
|
|
|
63
|
+
The `./embed` subpath (`dist/embed.js`) is the bundle itself: a self-contained ES module with every
|
|
64
|
+
dependency inlined, also on unpkg and jsDelivr.
|
|
65
|
+
|
|
50
66
|
## `<pop-grid>` attributes
|
|
51
67
|
|
|
52
68
|
| Attribute | Required | Description |
|
package/dist/loader.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
(function(){var e=document.currentScript;if(e instanceof HTMLScriptElement&&e.dataset.key)if(e.closest(`head`))console.warn(`PopGrids: the embed script is in <head>, so there's nowhere to show the Grid. Move the script to where the Grid should appear, or add a <pop-grid> element there.`);else{let t=document.createElement(`pop-grid`);for(let{name:n,value:r}of Array.from(e.attributes))n.startsWith(`data-`)&&t.setAttribute(n,r);e.after(t)}var t=new URL(`..`,`https://cdn.popgrids.io/embed/0.0.8/embed.js`).href;if(!customElements.get(`pop-grid`)&&!document.querySelector(`script[type="module"][src^="${t}"]`)){let e=document.createElement(`script`);e.type=`module`,e.src=`https://cdn.popgrids.io/embed/0.0.8/embed.js`,document.head.append(e)}})();
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@popgrids/embed",
|
|
3
3
|
"description": "PopGrids embeddable discussion widget",
|
|
4
|
-
"version": "0.0.
|
|
4
|
+
"version": "0.0.8",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"author": "PopGrids",
|
|
@@ -62,10 +62,11 @@
|
|
|
62
62
|
"scripts": {
|
|
63
63
|
"build:lib": "vite build",
|
|
64
64
|
"build:embed": "vite build --config vite.embed.config.ts",
|
|
65
|
-
"build": "
|
|
65
|
+
"build:loader": "vite build --config vite.loader.config.ts",
|
|
66
|
+
"build": "rm -rf dist && pnpm run build:lib && pnpm run build:embed && pnpm run build:loader",
|
|
66
67
|
"dev": "concurrently -k \"vite build --watch\" \"vite build --config vite.embed.config.ts --watch\"",
|
|
67
68
|
"demo": "pnpm run build && npx serve . -p 5500 --cors",
|
|
68
|
-
"demo:dev": "concurrently -k \"pnpm run dev\" \"live-server --port=5500 --open=demo --watch=dist,demo\"",
|
|
69
|
+
"demo:dev": "concurrently -k \"pnpm run dev\" \"live-server --host=localhost --port=5500 --open=demo --watch=dist,demo\"",
|
|
69
70
|
"clean": "rm -rf node_modules dist",
|
|
70
71
|
"check": "tsc --noEmit"
|
|
71
72
|
}
|