Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 0 additions & 6 deletions .eslintignore

This file was deleted.

49 changes: 0 additions & 49 deletions .eslintrc.cjs

This file was deleted.

6 changes: 3 additions & 3 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ jobs:

- uses: actions/setup-node@v4
with:
cache: 'pnpm'
registry-url: 'https://registry.npmjs.org'
node-version-file: '.node-version'
cache: "pnpm"
registry-url: "https://registry.npmjs.org"
node-version-file: ".node-version"

- run: make

Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ name: Unit Tests (PR)

on:
pull_request:
branches: ['canary', 'master']
branches: ["canary", "master"]

jobs:
test:
strategy:
matrix:
node-version: ['18', '20', '22']
node-version: ["20", "22"]

runs-on: ubuntu-latest
steps:
Expand All @@ -19,8 +19,8 @@ jobs:
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v4
with:
cache: 'pnpm'
registry-url: 'https://registry.npmjs.org'
cache: "pnpm"
registry-url: "https://registry.npmjs.org"
node-version: ${{ matrix.node-version }}

- run: make test
2 changes: 1 addition & 1 deletion .node-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
20
22
1 change: 1 addition & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
public-hoist-pattern[]=workbox-window
18 changes: 8 additions & 10 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,18 @@ clean: node_modules
distclean: clean
rm -rf node_modules

.PHONY: lint
lint: node_modules
pnpm exec eslint .
pnpm exec prettier --check .

node_modules: package.json
pnpm install

.PHONY: test
test: node_modules
pnpm run -r test

.PHONY: pretty
pretty: node_modules
pnpm exec eslint --fix . || true
pnpm exec prettier --write .
pnpx sort-package-json package.json packages/*/package.json examples/*/package.json
.PHONY: format
format: node_modules
pnpm exec biome format . --fix

.PHONY: lint
lint: node_modules
pnpm exec biome lint . --fix
pnpx sort-package-json package.json packages/*/package.json examples/*/package.json
38 changes: 38 additions & 0 deletions biome.jsonc
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{
"$schema": "./node_modules/@biomejs/biome/configuration_schema.json",

"vcs": {
"enabled": false,
"clientKind": "git",
"useIgnoreFile": true
},
"files": {
"ignoreUnknown": false,
"ignore": ["dev-dist"]
},
"json": {
"parser": {
"allowComments": true,
"allowTrailingCommas": true
}
},
"formatter": {
"enabled": true,
"indentStyle": "space",
"indentWidth": 2
},
"organizeImports": {
"enabled": true
},
"linter": {
"enabled": true,
"rules": {
"recommended": true
}
},
"javascript": {
"formatter": {
"quoteStyle": "single"
}
}
}
2 changes: 1 addition & 1 deletion examples/browser/.env
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# WARN: these keys are not secure, generate your own!
VITE_SERVER_VAPID_PUBLIC_KEY=BKKXE3jJV5UJ6c8HVPam6DvMPGZK26r-M7ojsO2T_KdjdeMT2d7oQpaO-VI3o3wn33mQ8JlHta3OSJ5f67Ac5ZY
VITE_SERVER_URL=http://localhost:3000
VITE_SERVER_URL=http://localhost:3065
37 changes: 24 additions & 13 deletions examples/browser/index.html
Original file line number Diff line number Diff line change
@@ -1,18 +1,29 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta name="color-scheme" content="dark" />
</head>

<style>
@import 'the-new-css-reset';
@import '@block65/react-design-system/css';
</style>
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta name="color-scheme" content="dark" />

<!-- inter -->
<link rel="stylesheet" href="https://rsms.me/inter/inter.css" />

<title>
Web Push Example
</title>

</head>

<style>
body {
font-family: 'Inter', sans-serif;
}
</style>

<body>
<div id="root"></div>
<script type="module" src="/src/main.tsx"></script>
</body>

<body>
<div id="root"></div>
<script type="module" src="/src/main.tsx"></script>
</body>
</html>
23 changes: 12 additions & 11 deletions examples/browser/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,20 @@
"dev": "vite dev"
},
"dependencies": {
"@block65/react-design-system": "^0.32.0",
"react": "^18.3.1",
"react-dom": "^18.3.1",
"the-new-css-reset": "^1.11.2",
"vite-plugin-pwa": "^0.20.0",
"workbox-window": "^7.1.0"
"react": "^19.0.0",
"react-dom": "^19.0.0",
"the-new-css-reset": "^1.11.3"
},
"devDependencies": {
"@block65/webcrypto-web-push": "workspace:*",
"@types/react": "^18.3.3",
"@types/react-dom": "^18.3.0",
"@vitejs/plugin-react": "^4.3.1",
"typescript": "^5.4.5",
"vite": "^5.2.13"
"@types/react": "^19.0.1",
"@types/react-dom": "^19.0.2",
"@vitejs/plugin-react": "^4.3.4",
"autoprefixer": "^10.4.20",
"postcss": "^8.4.49",
"tailwindcss": "^3.4.16",
"typescript": "^5.7.2",
"vite": "^6.0.3",
"vite-plugin-pwa": "^0.21.1"
}
}
10 changes: 3 additions & 7 deletions examples/browser/public/push-sw.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
/// <reference lib="webworker" />

declare const selfie: ServiceWorkerGlobalScope;

selfie.addEventListener('push', async (event) => {
self.addEventListener('push', async (event) => {
// Keep the service worker alive until the notification is shown.
event.waitUntil(
selfie.registration.pushManager.getSubscription().then((subscription) => {
self.registration.pushManager.getSubscription().then((subscription) => {
if (!subscription) {
throw new Error('No subscription found.');
}

selfie.registration.showNotification('Web Push', {
self.registration.showNotification('Web Push', {
// event.data?.json()
body: event.data?.text() || '<empty>',
requireInteraction: false, // can dismiss itself automatically
Expand Down
98 changes: 39 additions & 59 deletions examples/browser/src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,26 +1,7 @@
import {
Block,
Button,
Code,
DesignSystem,
Heading,
Panel,
Strong,
Text,
interFontThemeClassName,
} from '@block65/react-design-system';
import type { PushMessage } from '@block65/webcrypto-web-push';
import { useCallback, useState, type FC } from 'react';
import { type FC, useCallback, useState } from 'react';
import { useRegisterSW } from 'virtual:pwa-register/react';

function invariant<T>(
condition: T | undefined | null | '' | 0 | false,
message: string,
): asserts condition {
if (!condition) {
throw new Error(message);
}
}
import { invariant } from './utils.ts';

async function getSubscription(
registration: ServiceWorkerRegistration | undefined,
Expand Down Expand Up @@ -144,55 +125,54 @@ export const App: FC = () => {
}, [subscription]);

return (
<DesignSystem
flexDirection="column"
className={interFontThemeClassName}
style={{ minHeight: '100%' }}
>
<Block
flexGrow
alignSelf="center"
margin="10"
style={{ maxWidth: '30rem' }}
>
<Heading level="2">Web Push</Heading>

<Panel>
<Strong>Server Public Key</Strong>
<Code>{publicKey}</Code>
</Panel>

<Panel>
<Text>
<Strong>Service Worker Registered</Strong>: {String(!!registration)}
</Text>

<Text>
<Strong>Subscribed</Strong>: {String(!!subscription)}
</Text>

<Button
busy={subscribeBusy}
<div className="flex-grow mx-auto m-15 max-w-screen-sm gap-4 flex flex-col">
<h1 className="my-4 font-semibold text-xl">Web Push Example</h1>

<div className="flex flex-col">
<b>Server Public Key</b>
<code className="font-mono fg">{publicKey}</code>
</div>

<div className="flex flex-col gap-4">
<p className="flex flex-row gap-1">
<span className="font-semibold">Service Worker Registered:</span>
{registration ? 'Yes' : <span className="text-orange-600 ">No</span>}
</p>

<p className="flex flex-row gap-1">
<span className="font-semibold">Subscribed:</span>{' '}
{subscription ? 'Yes' : 'No'}
</p>

<div className="flex flex-row gap-4">
<button
className="bg-blue-500 hover:bg-blue-700 text-white py-2 px-4 rounded cursor-pointer flex-grow disabled:opacity-50"
type="button"
disabled={!registration || !!subscription}
onClick={() => subscribe()}
>
Subscribe
</Button>
<Button
{subscribeBusy ? 'busy' : 'Subscribe'}
</button>

<button
className="bg-blue-500 hover:bg-blue-700 text-white py-2 px-4 rounded cursor-pointer flex-grow disabled:opacity-50"
type="button"
disabled={!registration || !subscription}
onClick={() => unsubscribe()}
>
Unsubscribe
</Button>
</Panel>
</button>
</div>

<Button
<button
className="bg-gray-500 hover:bg-gray-700 text-white py-2 px-4 rounded cursor-pointer flex-grow disabled:opacity-50"
type="button"
disabled={!registration || !subscription}
onClick={() => send()}
>
Send Myself A Push Message
</Button>
</Block>
</DesignSystem>
</button>
</div>
</div>
);
};
3 changes: 3 additions & 0 deletions examples/browser/src/input.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
@tailwind base;
@tailwind components;
@tailwind utilities;
Loading
Loading