@weavour/react 0.0.0-stage → 0.1.1

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 Weavour contributors
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/README.md CHANGED
@@ -1,3 +1,19 @@
1
- # Temporary Holding Version
1
+ # @weavour/react
2
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.
3
+ MIT-licensed React 18.3/19 wrapper for the hosted Weavour email editor.
4
+ Install with `npm install @weavour/react`; React is a peer dependency.
5
+
6
+ ```tsx
7
+ import { WeavourEditor } from '@weavour/react';
8
+
9
+ <WeavourEditor editorKey="YOUR_PUBLIC_EDITOR_KEY" userId="user-123" style={{ height: 700 }} />
10
+ ```
11
+
12
+ The wrapper uses `@weavour/editor`, mounts in a client effect, cleans up on unmount,
13
+ and updates live configuration without replacing email content. Callback props
14
+ always use the latest handlers. Identity and initial content require an explicit
15
+ keyed remount. Imports are SSR safe; the bundle preserves its `use client` boundary.
16
+
17
+ The hosted editor and services remain private. Your application handles delivery.
18
+ Full API, identity/scoping rules, examples and release compatibility:
19
+ <https://github.com/weavour/editor-sdk>
@@ -0,0 +1,19 @@
1
+ import { type HTMLAttributes } from 'react';
2
+ import { type EditorInstance, type MountOptions, type EditorConfig } from '@weavour/editor';
3
+ export type WeavourEditorProps = MountOptions & Omit<HTMLAttributes<HTMLDivElement>, keyof MountOptions | 'children'>;
4
+ export type WeavourEditorRef = Omit<EditorInstance, 'destroy'>;
5
+ /** Mount-only props require an explicit React key change to replace the session. */
6
+ export declare const WeavourEditor: import("react").ForwardRefExoticComponent<EditorConfig & import("@weavour/editor").EditorCallbacks & {
7
+ editorKey: string;
8
+ userId?: string;
9
+ organizationId?: string;
10
+ document?: Record<string, unknown>;
11
+ emailDocument?: import("@weavour/editor").EmailDocument;
12
+ subject?: string;
13
+ preheader?: string;
14
+ draftId?: string;
15
+ editorConfig?: EditorConfig;
16
+ editorUrl?: string;
17
+ apiUrl?: string;
18
+ demo?: boolean;
19
+ } & Omit<HTMLAttributes<HTMLDivElement>, "subject" | "preheader" | "demo" | "editorKey" | "userId" | "draftId" | "organizationId" | "document" | "emailDocument" | keyof EditorConfig | keyof import("@weavour/editor").EditorCallbacks | "editorConfig" | "editorUrl" | "apiUrl" | "children"> & import("react").RefAttributes<WeavourEditorRef>>;
package/dist/index.js ADDED
@@ -0,0 +1,81 @@
1
+ "use client";
2
+
3
+ // packages/react/src/index.tsx
4
+ import { forwardRef, createElement, useEffect, useImperativeHandle, useRef } from "react";
5
+ import { mount, EditorError } from "@weavour/editor";
6
+ var liveKeys = ["theme", "locale", "mergeTags", "allowedBlocks", "enableAi", "aiPaidOrigin", "enableTemplates", "enableAutosave"];
7
+ var mountKeys = ["editorKey", "userId", "organizationId", "document", "emailDocument", "subject", "preheader", "draftId", "editorUrl", "apiUrl", "editorConfig", "demo"];
8
+ var WeavourEditor = forwardRef(function WeavourEditor2(props, ref) {
9
+ const container = useRef(null);
10
+ const editor = useRef(null);
11
+ const latest = useRef(props);
12
+ latest.current = props;
13
+ const initial = useRef(null);
14
+ const previousLive = useRef("");
15
+ const active = () => {
16
+ if (!editor.current) throw new EditorError("not_ready", "Editor is not mounted.");
17
+ return editor.current;
18
+ };
19
+ useImperativeHandle(ref, () => ({
20
+ get ready() {
21
+ return active().ready;
22
+ },
23
+ exportHTML: () => active().exportHTML(),
24
+ previewTemplate: () => active().previewTemplate(),
25
+ flushAutosave: () => active().flushAutosave(),
26
+ updateConfig: (next) => active().updateConfig(next)
27
+ }), []);
28
+ useEffect(() => {
29
+ initial.current = latest.current;
30
+ const value = latest.current;
31
+ let instance;
32
+ try {
33
+ instance = mount(container.current, {
34
+ ...value,
35
+ onReady: () => latest.current.onReady?.(),
36
+ onError: (error) => latest.current.onError?.(error),
37
+ onChange: (document) => latest.current.onChange?.(document),
38
+ onDocumentChange: (document) => latest.current.onDocumentChange?.(document),
39
+ onSaveStatusChange: (status) => latest.current.onSaveStatusChange?.(status),
40
+ onDraftChange: (draft) => latest.current.onDraftChange?.(draft),
41
+ onTestEmail: value.onTestEmail ? (request) => {
42
+ if (!latest.current.onTestEmail) throw new Error("Test email delivery is unavailable.");
43
+ return latest.current.onTestEmail(request);
44
+ } : void 0
45
+ });
46
+ editor.current = instance;
47
+ } catch (error) {
48
+ latest.current.onError?.(error instanceof Error ? error : new Error(String(error)));
49
+ return;
50
+ }
51
+ return () => {
52
+ instance.destroy();
53
+ if (editor.current === instance) editor.current = null;
54
+ };
55
+ }, []);
56
+ useEffect(() => {
57
+ const config = { mergeTags: props.mergeTags };
58
+ for (const key of liveKeys) if (Object.hasOwn(props, key)) Object.assign(config, { [key]: props[key] });
59
+ const serialized = JSON.stringify(config);
60
+ if (serialized !== previousLive.current) {
61
+ try {
62
+ editor.current?.updateConfig(config);
63
+ previousLive.current = serialized;
64
+ } catch (error) {
65
+ latest.current.onError?.(error instanceof Error ? error : new Error(String(error)));
66
+ }
67
+ }
68
+ const first = initial.current;
69
+ if (first && mountKeys.some((key) => JSON.stringify(props[key]) !== JSON.stringify(first[key]))) {
70
+ latest.current.onError?.(new EditorError("invalid_config", "Mount-only props changed. Use a new React key after saving current work."));
71
+ }
72
+ });
73
+ const attributes = {};
74
+ for (const [key, value] of Object.entries(props)) {
75
+ if (key === "id" || key === "className" || key === "style" || key === "title" || key === "role" || key === "tabIndex" || key.startsWith("aria-") || key.startsWith("data-")) attributes[key] = value;
76
+ }
77
+ return createElement("div", { ...attributes, ref: container });
78
+ });
79
+ export {
80
+ WeavourEditor
81
+ };
package/package.json CHANGED
@@ -1,6 +1,38 @@
1
1
  {
2
+ "version": "0.1.1",
3
+ "type": "module",
4
+ "license": "MIT",
5
+ "repository": {
6
+ "type": "git",
7
+ "url": "git+https://github.com/weavour/editor-sdk.git"
8
+ },
9
+ "homepage": "https://github.com/weavour/editor-sdk#readme",
10
+ "bugs": "https://github.com/weavour/editor-sdk/issues",
11
+ "publishConfig": {
12
+ "access": "public"
13
+ },
14
+ "files": [
15
+ "dist",
16
+ "LICENSE",
17
+ "README.md"
18
+ ],
19
+ "engines": {
20
+ "node": ">=22.12"
21
+ },
2
22
  "name": "@weavour/react",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
23
+ "description": "React bindings for the hosted Weavour email editor.",
24
+ "main": "./dist/index.js",
25
+ "types": "./dist/index.d.ts",
26
+ "exports": {
27
+ ".": {
28
+ "types": "./dist/index.d.ts",
29
+ "import": "./dist/index.js"
30
+ }
31
+ },
32
+ "dependencies": {
33
+ "@weavour/editor": "0.1.1"
34
+ },
35
+ "peerDependencies": {
36
+ "react": "^18.3.1 || ^19.0.0"
37
+ }
38
+ }