diff --git a/.github/workflows/release-please.yml b/.github/workflows/release-please.yml
new file mode 100644
index 0000000..066bb0e
--- /dev/null
+++ b/.github/workflows/release-please.yml
@@ -0,0 +1,18 @@
+on:
+ push:
+ branches:
+ - master
+
+permissions:
+ contents: write
+ pull-requests: write
+
+name: release-please
+
+jobs:
+ release-please:
+ runs-on: ubuntu-latest
+ steps:
+ - uses: google-github-actions/release-please-action@v3
+ with:
+ release-type: node
diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml
index 8925e59..a5acdf5 100644
--- a/.github/workflows/test.yml
+++ b/.github/workflows/test.yml
@@ -8,11 +8,11 @@ jobs:
test:
runs-on: ubuntu-latest
steps:
- - uses: actions/checkout@v2
+ - uses: actions/checkout@v4
- name: Setup Node.js
- uses: actions/setup-node@v1
+ uses: actions/setup-node@v3
with:
- node-version: 14
+ node-version: 18
- run: npm install
- name: Lint
run: npm test
diff --git a/dialog.js b/dialog.js
index be08ad1..47ab07d 100644
--- a/dialog.js
+++ b/dialog.js
@@ -1,82 +1,82 @@
import ShadowElement, {template, html, htmlNode, define} from '@cfware/shadow-element';
class CFWareDialog extends ShadowElement {
- get [template]() {
- return html`
-
-
-
- `;
- }
+ get [template]() {
+ return html`
+
+
+
+ `;
+ }
}
CFWareDialog[define]('c-d');
const createDialogNode = (title, body, buttons) => htmlNode`
-
- ${title}
- ${body}
- ${buttons}
-
+
+ ${title}
+ ${body}
+ ${buttons}
+
`;
const findActiveElement = () => {
- let {activeElement} = document;
- while (activeElement?.shadowRoot?.activeElement) {
- activeElement = activeElement.shadowRoot.activeElement;
- }
+ let {activeElement} = document;
+ while (activeElement?.shadowRoot?.activeElement) {
+ activeElement = activeElement.shadowRoot.activeElement;
+ }
- return activeElement;
+ return activeElement;
};
const eventKeys = {
- Enter: true,
- Escape: false
+ Enter: true,
+ Escape: false
};
export const escapeEnterHandler = event => eventKeys[event.key];
@@ -84,84 +84,84 @@ export const escapeEnterHandler = event => eventKeys[event.key];
let abortSignalers = [];
export const abortDialogs = () => {
- for (const signaler of abortSignalers) {
- signaler();
- }
+ for (const signaler of abortSignalers) {
+ signaler();
+ }
};
export const runDialog = (title, body, buttons, onkeyup = escapeEnterHandler) => {
- const activeElement = findActiveElement();
-
- return new Promise(resolve => {
- const node = createDialogNode(title, body, buttons);
- const elements = [...document.body.children];
- const cleanup = result => {
- abortSignalers = abortSignalers.filter(fn => fn !== cleanup);
- for (const element of elements) {
- element.removeAttribute('tabindex');
- }
-
- window.removeEventListener('keydown', keydownHandler);
- window.removeEventListener('keyup', keyupHandler);
- node.remove();
- setTimeout(() => activeElement?.focus());
- resolve(result);
- };
-
- abortSignalers.push(cleanup);
- for (const element of elements) {
- element.tabIndex = -1;
- }
-
- let keydown;
- const keydownHandler = event => {
- keydown = event.key;
- };
-
- const keyupHandler = event => {
- if (!event.isClick && keydown !== event.key) {
- return;
- }
-
- keydown = null;
- const result = onkeyup(event);
- if (result !== undefined) {
- cleanup(result);
- }
- };
-
- document.body.append(node);
- for (const button of node.querySelectorAll('button')) {
- button.addEventListener('click', () => keyupHandler({
- key: button.getAttribute('key'),
- isClick: true
- }));
- }
-
- setTimeout(() => {
- const autofocus = node.querySelector('[autofocus]') ?? node.querySelector('[name]');
- autofocus?.focus();
- window.addEventListener('keydown', keydownHandler);
- window.addEventListener('keyup', keyupHandler);
- });
- });
+ const activeElement = findActiveElement();
+
+ return new Promise(resolve => {
+ const node = createDialogNode(title, body, buttons);
+ const elements = [...document.body.children];
+ const cleanup = result => {
+ abortSignalers = abortSignalers.filter(fn => fn !== cleanup);
+ for (const element of elements) {
+ element.removeAttribute('tabindex');
+ }
+
+ window.removeEventListener('keydown', keydownHandler);
+ window.removeEventListener('keyup', keyupHandler);
+ node.remove();
+ setTimeout(() => activeElement?.focus());
+ resolve(result);
+ };
+
+ abortSignalers.push(cleanup);
+ for (const element of elements) {
+ element.tabIndex = -1;
+ }
+
+ let keydown;
+ const keydownHandler = event => {
+ keydown = event.key;
+ };
+
+ const keyupHandler = event => {
+ if (!event.isClick && keydown !== event.key) {
+ return;
+ }
+
+ keydown = null;
+ const result = onkeyup(event);
+ if (result !== undefined) {
+ cleanup(result);
+ }
+ };
+
+ document.body.append(node);
+ for (const button of node.querySelectorAll('button')) {
+ button.addEventListener('click', () => keyupHandler({
+ key: button.getAttribute('key'),
+ isClick: true
+ }));
+ }
+
+ setTimeout(() => {
+ const autofocus = node.querySelector('[autofocus]') ?? node.querySelector('[name]');
+ autofocus?.focus();
+ window.addEventListener('keydown', keydownHandler);
+ window.addEventListener('keyup', keyupHandler);
+ });
+ });
};
export const dialogAlert = (title, body) => {
- return runDialog(
- title,
- body,
- html``
- );
+ return runDialog(
+ title,
+ body,
+ html``
+ );
};
export const dialogConfirm = (title, body, yesLabel = 'OK', noLabel = 'Cancel') => {
- return runDialog(
- title,
- body,
- html`
-
-
- `
- );
+ return runDialog(
+ title,
+ body,
+ html`
+
+
+ `
+ );
};
diff --git a/package.json b/package.json
index ec792c3..93b6d5b 100644
--- a/package.json
+++ b/package.json
@@ -1,30 +1,30 @@
{
- "name": "@cfware/dialog",
- "version": "0.2.0",
- "description": "Dialog overlays",
- "type": "module",
- "main": "dialog.js",
- "exports": "./dialog.js",
- "scripts": {
- "test": "cfware-lint ."
- },
- "engines": {
- "node": ">=14.0.0"
- },
- "author": "Corey Farrell",
- "license": "MIT",
- "repository": {
- "type": "git",
- "url": "git+https://github.com/cfware/dialog.git"
- },
- "bugs": {
- "url": "https://github.com/cfware/dialog/issues"
- },
- "homepage": "https://github.com/cfware/dialog#readme",
- "dependencies": {
- "@cfware/shadow-element": "^0.16.0"
- },
- "devDependencies": {
- "@cfware/lint": "^2.0.4"
- }
+ "name": "@cfware/dialog",
+ "version": "0.2.0",
+ "description": "Dialog overlays",
+ "type": "module",
+ "main": "dialog.js",
+ "exports": "./dialog.js",
+ "scripts": {
+ "test": "cfware-lint ."
+ },
+ "engines": {
+ "node": ">=18"
+ },
+ "author": "Corey Farrell",
+ "license": "MIT",
+ "repository": {
+ "type": "git",
+ "url": "git+https://github.com/cfware/dialog.git"
+ },
+ "bugs": {
+ "url": "https://github.com/cfware/dialog/issues"
+ },
+ "homepage": "https://github.com/cfware/dialog#readme",
+ "dependencies": {
+ "@cfware/shadow-element": "^1"
+ },
+ "devDependencies": {
+ "@cfware/lint": "^4"
+ }
}