@webwriter/angular 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,14 @@
1
+ import type {ApplicationRef, Signal, Type} from "@angular/core"
2
+ import type {WidgetHost, WidgetSnapshot} from "@webwriter/widget"
3
+
4
+ export * from "@webwriter/widget"
5
+
6
+ export function injectWidgetHost(): WidgetHost
7
+ export function injectWidget(): Signal<WidgetSnapshot>
8
+ export function createAngularWidget(
9
+ component: Type<unknown>,
10
+ options?: {application?: ApplicationRef, styles?: string},
11
+ ): Promise<{
12
+ new (): WidgetHost
13
+ readonly widgetAttributes: readonly string[]
14
+ }>
package/index.js ADDED
@@ -0,0 +1,91 @@
1
+ import {createComponent, DestroyRef, inject, InjectionToken, Injector, signal} from "@angular/core"
2
+ import {createApplication} from "@angular/platform-browser"
3
+ import {withWidgetRuntime} from "@webwriter/widget"
4
+
5
+ const widgetHost = new InjectionToken("WebWriter widget host")
6
+ let defaultApplication
7
+
8
+ export function injectWidgetHost() {
9
+ return inject(widgetHost)
10
+ }
11
+
12
+ export function injectWidget() {
13
+ const {getSnapshot, subscribe} = injectWidgetHost().widgetRuntime
14
+ const state = signal(getSnapshot())
15
+ inject(DestroyRef).onDestroy(subscribe(() => state.set(getSnapshot())))
16
+ return state.asReadonly()
17
+ }
18
+
19
+ /** Create a widget class that mounts an Angular component in its shadow root. */
20
+ export async function createAngularWidget(Component, {application, styles} = {}) {
21
+ if(!application) {
22
+ defaultApplication ??= createApplication().catch(error => {
23
+ defaultApplication = undefined
24
+ throw error
25
+ })
26
+ application = await defaultApplication
27
+ }
28
+
29
+ return class AngularWidget extends withWidgetRuntime(HTMLElement) {
30
+ #view
31
+ #mount
32
+
33
+ constructor() {
34
+ super()
35
+ const shadow = this.attachShadow({mode: "open"})
36
+ if(styles) {
37
+ const style = this.ownerDocument.createElement("style")
38
+ style.textContent = styles
39
+ shadow.append(style)
40
+ }
41
+ }
42
+
43
+ connectedCallback() {
44
+ super.connectedCallback()
45
+ if(!this.isConnected || this.#view) return
46
+ const mount = this.ownerDocument.createElement("div")
47
+ const injector = Injector.create({
48
+ parent: application.injector,
49
+ providers: [{provide: widgetHost, useValue: this}],
50
+ })
51
+ try {
52
+ // Angular can stamp its host and render freely inside this element.
53
+ this.shadowRoot.append(mount)
54
+ this.#mount = mount
55
+ const view = this.#view = createComponent(Component, {
56
+ hostElement: mount,
57
+ environmentInjector: application.injector,
58
+ elementInjector: injector,
59
+ })
60
+ view.onDestroy(() => injector.destroy())
61
+ application.attachView(view.hostView)
62
+ view.changeDetectorRef.detectChanges()
63
+ }
64
+ catch(error) {
65
+ if(this.#view) this.#destroyView()
66
+ else {
67
+ injector.destroy()
68
+ mount.remove()
69
+ this.#mount = undefined
70
+ }
71
+ throw error
72
+ }
73
+ }
74
+
75
+ disconnectedCallback() {
76
+ super.disconnectedCallback()
77
+ queueMicrotask(() => {
78
+ if(!this.isConnected) this.#destroyView()
79
+ })
80
+ }
81
+
82
+ #destroyView() {
83
+ const view = this.#view, mount = this.#mount
84
+ this.#view = this.#mount = undefined
85
+ try { view?.destroy() }
86
+ finally { mount?.remove() }
87
+ }
88
+ }
89
+ }
90
+
91
+ export * from "@webwriter/widget"
package/package.json CHANGED
@@ -1,6 +1,27 @@
1
1
  {
2
2
  "name": "@webwriter/angular",
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": "Angular 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
+ "@angular/core": "^22.2.0",
25
+ "@angular/platform-browser": "^22.2.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.