@webwriter/react 0.0.0-stage → 1.0.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Frederic Salmen
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/index.d.ts ADDED
@@ -0,0 +1,10 @@
1
+ import type {ComponentType} from "react"
2
+ import type {WidgetHost, WidgetSnapshot} from "@webwriter/widget"
3
+
4
+ export * from "@webwriter/widget"
5
+
6
+ export function useWidget(host: WidgetHost): WidgetSnapshot
7
+ export function createReactWidget<Host extends WidgetHost = WidgetHost>(
8
+ component: ComponentType<{host: Host}>,
9
+ shadowOptions?: Omit<ShadowRootInit, "mode">,
10
+ ): CustomElementConstructor & {new (): WidgetHost, readonly widgetAttributes: readonly string[]}
package/index.js ADDED
@@ -0,0 +1,39 @@
1
+ import {createElement, useSyncExternalStore} from "react"
2
+ import {createRoot} from "react-dom/client"
3
+ import {withWidgetRuntime} from "@webwriter/widget"
4
+
5
+ export function useWidget(host) {
6
+ const {subscribe, getSnapshot} = host.widgetRuntime
7
+ return useSyncExternalStore(subscribe, getSnapshot)
8
+ }
9
+
10
+ /** Return a custom-element class whose shadow UI is rendered by React. */
11
+ export function createReactWidget(Component, shadowOptions) {
12
+ return class ReactWidget extends withWidgetRuntime(HTMLElement) {
13
+ #root
14
+
15
+ constructor() {
16
+ super()
17
+ this.attachShadow({...shadowOptions, mode: "open"})
18
+ }
19
+
20
+ connectedCallback() {
21
+ super.connectedCallback()
22
+ if(this.#root) return
23
+ this.#root = createRoot(this.shadowRoot)
24
+ this.#root.render(createElement(Component, {host: this}))
25
+ }
26
+
27
+ disconnectedCallback() {
28
+ super.disconnectedCallback()
29
+ // A synchronous DOM move keeps its React tree and transient UI state.
30
+ queueMicrotask(() => {
31
+ if(this.isConnected) return
32
+ this.#root?.unmount()
33
+ this.#root = undefined
34
+ })
35
+ }
36
+ }
37
+ }
38
+
39
+ export * from "@webwriter/widget"
package/package.json CHANGED
@@ -1,6 +1,27 @@
1
1
  {
2
2
  "name": "@webwriter/react",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "1.0.0",
4
+ "description": "React adapter for WebWriter widgets",
5
+ "license": "MIT",
6
+ "type": "module",
7
+ "publishConfig": {
8
+ "access": "public"
9
+ },
10
+ "exports": {
11
+ ".": {
12
+ "types": "./index.d.ts",
13
+ "default": "./index.js"
14
+ }
15
+ },
16
+ "files": [
17
+ "index.js",
18
+ "index.d.ts"
19
+ ],
20
+ "dependencies": {
21
+ "@webwriter/widget": "^1.0.0"
22
+ },
23
+ "peerDependencies": {
24
+ "react": "^19.0.0",
25
+ "react-dom": "^19.0.0"
26
+ }
27
+ }
package/README.md DELETED
@@ -1,3 +0,0 @@
1
- # Temporary Holding Version
2
-
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.