backpage
Advanced tools
Comparing version 0.0.2-3 to 0.0.2-4
@@ -21,2 +21,3 @@ import type { ReactNode } from 'react'; | ||
private connected; | ||
private eventsEnabled; | ||
constructor({ title, notify: notifyOptions, events, ...options }?: BackPageOptions); | ||
@@ -34,3 +35,3 @@ getURL(): Promise<string>; | ||
registerAction<T extends object>(name: string, action: ActionCallback<T>): () => void; | ||
private lastElementDataId; | ||
private lastEventTargetId; | ||
private updateHTML; | ||
@@ -37,0 +38,0 @@ private handleNotifyTimeout; |
@@ -13,3 +13,3 @@ import { createRequire } from 'module'; | ||
const NOTIFY_TIMEOUT_DEFAULT = 30000; | ||
const EVENTS_DEFAULT = ['click', 'input']; | ||
const EVENTS_DEFAULT = []; | ||
export class BackPage { | ||
@@ -60,6 +60,12 @@ constructor({ title, notify: notifyOptions, events = EVENTS_DEFAULT, ...options } = {}) { | ||
}); | ||
Object.defineProperty(this, "lastElementDataId", { | ||
Object.defineProperty(this, "eventsEnabled", { | ||
enumerable: true, | ||
configurable: true, | ||
writable: true, | ||
value: void 0 | ||
}); | ||
Object.defineProperty(this, "lastEventTargetId", { | ||
enumerable: true, | ||
configurable: true, | ||
writable: true, | ||
value: 0 | ||
@@ -99,2 +105,3 @@ }); | ||
}); | ||
this.eventsEnabled = events.length > 0; | ||
if (title !== undefined) { | ||
@@ -162,5 +169,7 @@ tunnel.update({ title }); | ||
} | ||
let { content, tunnel } = this; | ||
for (const element of content.querySelectorAll(`:not([${PAGE_EVENT_TARGET_ID_KEY}])`)) { | ||
element.setAttribute(PAGE_EVENT_TARGET_ID_KEY, (++this.lastElementDataId).toString()); | ||
let { content, tunnel, eventsEnabled } = this; | ||
if (eventsEnabled) { | ||
for (const element of content.querySelectorAll(`:not([${PAGE_EVENT_TARGET_ID_KEY}])`)) { | ||
element.setAttribute(PAGE_EVENT_TARGET_ID_KEY, (++this.lastEventTargetId).toString()); | ||
} | ||
} | ||
@@ -167,0 +176,0 @@ content = content.cloneNode(true); |
{ | ||
"name": "backpage", | ||
"version": "0.0.2-3", | ||
"version": "0.0.2-4", | ||
"description": "Naive static HTML streaming based on React for Node.js CLI applications.", | ||
@@ -5,0 +5,0 @@ "repository": "https://github.com/vilicvane/backpage.git", |
@@ -29,2 +29,4 @@ [![NPM version](https://img.shields.io/npm/v/backpage?color=%23cb3837&style=flat-square)](https://www.npmjs.com/package/backpage) | ||
- [Events](#events) | ||
- [click](#click) | ||
- [input](#input) | ||
- [Browser Notification](#browser-notification) | ||
@@ -91,5 +93,9 @@ - [Public URL](#public-url) | ||
BackPage can proxy events that bubble to `document` from the browser to your Node.js React application. But currently no event data is passed and by default only `click` and `input` event is proxied. | ||
BackPage can proxy explicitly specified events that bubble to `document` from the browser to your Node.js React application. | ||
```tsx | ||
const page = new BackPage({ | ||
events: ['click'], | ||
}); | ||
page.render( | ||
@@ -106,10 +112,2 @@ <div | ||
To proxy other events, you can specify `events` in `BackPage` options: | ||
```ts | ||
const page = new BackPage({ | ||
events: ['click', 'dblclick'], | ||
}); | ||
``` | ||
> Events are proxied asynchronously, and just for the purpose of triggering actions in your Node.js application. | ||
@@ -119,2 +117,17 @@ | ||
### click | ||
Properties: | ||
- `altKey` | ||
- `ctrlKey` | ||
- `metaKey` | ||
- `shiftKey` | ||
### input | ||
Effects: | ||
- Sets `event.target.value` to the value of the input element. | ||
## Browser Notification | ||
@@ -121,0 +134,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
243797
5091
275