@nuforge/editor 0.1.2 → 0.2.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/dist/react.cjs +13 -2
- package/dist/react.d.ts +7 -2
- package/dist/react.mjs +14 -4
- package/package.json +10 -10
package/dist/react.cjs
CHANGED
|
@@ -18,7 +18,17 @@ function dropPositionFromPointer(clientY, rect, opts = {}) {
|
|
|
18
18
|
return ratio < 0.5 ? 'before' : 'after';
|
|
19
19
|
}
|
|
20
20
|
|
|
21
|
-
const decorate = (view) => ({
|
|
21
|
+
const decorate = (view) => ({
|
|
22
|
+
'data-nu-id': view.template?.id,
|
|
23
|
+
});
|
|
24
|
+
const AMBIENT_CANVAS_WINDOW = {
|
|
25
|
+
doc: typeof document === 'undefined' ? null : document,
|
|
26
|
+
window: typeof window === 'undefined' ? null : window,
|
|
27
|
+
};
|
|
28
|
+
const CanvasWindowContext = react.createContext(AMBIENT_CANVAS_WINDOW);
|
|
29
|
+
function useCanvasWindow() {
|
|
30
|
+
return react.useContext(CanvasWindowContext);
|
|
31
|
+
}
|
|
22
32
|
const EditorView = react.memo(function EditorView({ view, }) {
|
|
23
33
|
const renderChildren = (views) => views.map((child) => react.createElement(EditorView, { key: child.key, view: child }));
|
|
24
34
|
return react$1.createViewElement(view, renderChildren, decorate);
|
|
@@ -194,7 +204,7 @@ function IframeCanvas({ frame, selectedId = null, hoveredId = null, revision = 0
|
|
|
194
204
|
setSelectedLabel(labelOf(selectedId));
|
|
195
205
|
}, [previewMode, selectedId, hoveredId, revision, tick, doc]);
|
|
196
206
|
return react.createElement('div', { className: containerClassName, style: { position: 'relative' } }, react.createElement('iframe', { ref: iframeRef, title: 'nuforge preview', className, srcDoc }, doc?.body
|
|
197
|
-
? reactDom.createPortal(react.createElement(EditorFrame, { frame }), doc.body)
|
|
207
|
+
? reactDom.createPortal(react.createElement(CanvasWindowContext.Provider, { value: { doc, window: doc.defaultView } }, react.createElement(EditorFrame, { frame })), doc.body)
|
|
198
208
|
: null), renderBox && !previewMode
|
|
199
209
|
? react.createElement('div', {
|
|
200
210
|
style: {
|
|
@@ -269,5 +279,6 @@ exports.EditorFrame = EditorFrame;
|
|
|
269
279
|
exports.IframeCanvas = IframeCanvas;
|
|
270
280
|
exports.PropFields = PropFields;
|
|
271
281
|
exports.templateIdFromElement = templateIdFromElement;
|
|
282
|
+
exports.useCanvasWindow = useCanvasWindow;
|
|
272
283
|
exports.useEditorRevision = useEditorRevision;
|
|
273
284
|
exports.useStructureRevision = useStructureRevision;
|
package/dist/react.d.ts
CHANGED
|
@@ -112,6 +112,11 @@ interface Rect {
|
|
|
112
112
|
width: number;
|
|
113
113
|
height: number;
|
|
114
114
|
}
|
|
115
|
+
interface CanvasWindow {
|
|
116
|
+
doc: Document | null;
|
|
117
|
+
window: Window | null;
|
|
118
|
+
}
|
|
119
|
+
declare function useCanvasWindow(): CanvasWindow;
|
|
115
120
|
declare const EditorFrame: (props: {
|
|
116
121
|
frame: Frame;
|
|
117
122
|
}) => ReactNode;
|
|
@@ -152,5 +157,5 @@ interface PropFieldsProps {
|
|
|
152
157
|
}
|
|
153
158
|
declare function PropFields({ fields, values, onChange, className, }: PropFieldsProps): ReactNode;
|
|
154
159
|
|
|
155
|
-
export { DEFAULT_CANVAS_CSS, EditorFrame, IframeCanvas, PropFields, templateIdFromElement, useEditorRevision, useStructureRevision };
|
|
156
|
-
export type { IframeCanvasProps, PropFieldValue, PropFieldsProps, Rect };
|
|
160
|
+
export { DEFAULT_CANVAS_CSS, EditorFrame, IframeCanvas, PropFields, templateIdFromElement, useCanvasWindow, useEditorRevision, useStructureRevision };
|
|
161
|
+
export type { CanvasWindow, IframeCanvasProps, PropFieldValue, PropFieldsProps, Rect };
|
package/dist/react.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
import { createViewElement, observer } from '@nuforge/react';
|
|
3
|
-
import { memo, createElement, Fragment, useRef, useState, useEffect, useLayoutEffect } from 'react';
|
|
3
|
+
import { createContext, memo, createElement, Fragment, useRef, useState, useEffect, useLayoutEffect, useContext } from 'react';
|
|
4
4
|
import { createPortal } from 'react-dom';
|
|
5
5
|
import '@nuforge/types';
|
|
6
6
|
|
|
@@ -16,7 +16,17 @@ function dropPositionFromPointer(clientY, rect, opts = {}) {
|
|
|
16
16
|
return ratio < 0.5 ? 'before' : 'after';
|
|
17
17
|
}
|
|
18
18
|
|
|
19
|
-
const decorate = (view) => ({
|
|
19
|
+
const decorate = (view) => ({
|
|
20
|
+
'data-nu-id': view.template?.id,
|
|
21
|
+
});
|
|
22
|
+
const AMBIENT_CANVAS_WINDOW = {
|
|
23
|
+
doc: typeof document === 'undefined' ? null : document,
|
|
24
|
+
window: typeof window === 'undefined' ? null : window,
|
|
25
|
+
};
|
|
26
|
+
const CanvasWindowContext = createContext(AMBIENT_CANVAS_WINDOW);
|
|
27
|
+
function useCanvasWindow() {
|
|
28
|
+
return useContext(CanvasWindowContext);
|
|
29
|
+
}
|
|
20
30
|
const EditorView = memo(function EditorView({ view, }) {
|
|
21
31
|
const renderChildren = (views) => views.map((child) => createElement(EditorView, { key: child.key, view: child }));
|
|
22
32
|
return createViewElement(view, renderChildren, decorate);
|
|
@@ -192,7 +202,7 @@ function IframeCanvas({ frame, selectedId = null, hoveredId = null, revision = 0
|
|
|
192
202
|
setSelectedLabel(labelOf(selectedId));
|
|
193
203
|
}, [previewMode, selectedId, hoveredId, revision, tick, doc]);
|
|
194
204
|
return createElement('div', { className: containerClassName, style: { position: 'relative' } }, createElement('iframe', { ref: iframeRef, title: 'nuforge preview', className, srcDoc }, doc?.body
|
|
195
|
-
? createPortal(createElement(EditorFrame, { frame }), doc.body)
|
|
205
|
+
? createPortal(createElement(CanvasWindowContext.Provider, { value: { doc, window: doc.defaultView } }, createElement(EditorFrame, { frame })), doc.body)
|
|
196
206
|
: null), renderBox && !previewMode
|
|
197
207
|
? createElement('div', {
|
|
198
208
|
style: {
|
|
@@ -262,4 +272,4 @@ function PropFieldControl({ field, value, onChange, }) {
|
|
|
262
272
|
return createElement('label', { htmlFor: id, 'data-nu-field': field.name }, createElement('span', null, label), control);
|
|
263
273
|
}
|
|
264
274
|
|
|
265
|
-
export { DEFAULT_CANVAS_CSS, EditorFrame, IframeCanvas, PropFields, templateIdFromElement, useEditorRevision, useStructureRevision };
|
|
275
|
+
export { DEFAULT_CANVAS_CSS, EditorFrame, IframeCanvas, PropFields, templateIdFromElement, useCanvasWindow, useEditorRevision, useStructureRevision };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nuforge/editor",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "High-level SDK for building visual page editors on nuforge (mutations, blocks, commands, selection)",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -24,15 +24,15 @@
|
|
|
24
24
|
"dist"
|
|
25
25
|
],
|
|
26
26
|
"dependencies": {
|
|
27
|
-
"@nuforge/reactivity": "0.1.
|
|
27
|
+
"@nuforge/reactivity": "0.1.3"
|
|
28
28
|
},
|
|
29
29
|
"peerDependencies": {
|
|
30
30
|
"react": "^18 || ^19",
|
|
31
31
|
"react-dom": "^18 || ^19",
|
|
32
|
-
"@nuforge/core": "0.1.
|
|
33
|
-
"@nuforge/parser": "0.1.
|
|
34
|
-
"@nuforge/
|
|
35
|
-
"@nuforge/
|
|
32
|
+
"@nuforge/core": "0.1.4",
|
|
33
|
+
"@nuforge/parser": "0.1.3",
|
|
34
|
+
"@nuforge/react": "0.1.4",
|
|
35
|
+
"@nuforge/types": "0.1.3"
|
|
36
36
|
},
|
|
37
37
|
"peerDependenciesMeta": {
|
|
38
38
|
"@nuforge/react": {
|
|
@@ -50,10 +50,10 @@
|
|
|
50
50
|
"@types/react-dom": "^19.2.0",
|
|
51
51
|
"react": "^19.2.0",
|
|
52
52
|
"react-dom": "^19.2.0",
|
|
53
|
-
"@nuforge/
|
|
54
|
-
"@nuforge/
|
|
55
|
-
"@nuforge/
|
|
56
|
-
"@nuforge/
|
|
53
|
+
"@nuforge/core": "0.1.4",
|
|
54
|
+
"@nuforge/parser": "0.1.3",
|
|
55
|
+
"@nuforge/react": "0.1.4",
|
|
56
|
+
"@nuforge/types": "0.1.3"
|
|
57
57
|
},
|
|
58
58
|
"publishConfig": {
|
|
59
59
|
"access": "public"
|