@webstudio-is/react-sdk 0.5.0 → 0.6.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/lib/arg-types/utils.d.ts +19 -1
- package/lib/arg-types/utils.d.ts.map +1 -1
- package/lib/arg-types/utils.js +7 -6
- package/lib/canvas/canvas.d.ts +8 -0
- package/lib/canvas/canvas.d.ts.map +1 -0
- package/lib/canvas/canvas.js +13 -0
- package/lib/canvas/index.d.ts +2 -0
- package/lib/canvas/index.d.ts.map +1 -0
- package/lib/canvas/index.js +17 -0
- package/lib/components/body.d.ts +3 -0
- package/lib/components/body.d.ts.map +1 -0
- package/lib/components/body.js +8 -0
- package/lib/components/body.props.json +2234 -0
- package/lib/components/body.stories.d.ts +7 -0
- package/lib/components/body.stories.d.ts.map +1 -0
- package/lib/components/body.stories.js +16 -0
- package/lib/components/body.ws.d.ts +5 -0
- package/lib/components/body.ws.d.ts.map +1 -0
- package/lib/components/body.ws.js +64 -0
- package/lib/components/bold.props.json +37 -7
- package/lib/components/bold.ws.d.ts +5 -0
- package/lib/components/bold.ws.d.ts.map +1 -0
- package/lib/components/bold.ws.js +14 -0
- package/lib/components/box.d.ts +7 -2
- package/lib/components/box.d.ts.map +1 -1
- package/lib/components/box.js +3 -2
- package/lib/components/box.props.json +102 -7
- package/lib/components/box.stories.d.ts +6 -2
- package/lib/components/box.stories.d.ts.map +1 -1
- package/lib/components/box.ws.d.ts +5 -0
- package/lib/components/box.ws.d.ts.map +1 -0
- package/lib/components/box.ws.js +21 -0
- package/lib/components/button.d.ts +1 -4
- package/lib/components/button.d.ts.map +1 -1
- package/lib/components/button.props.json +42 -8
- package/lib/components/button.ws.d.ts +5 -0
- package/lib/components/button.ws.d.ts.map +1 -0
- package/lib/components/button.ws.js +15 -0
- package/lib/components/component-type.d.ts +17 -0
- package/lib/components/component-type.d.ts.map +1 -0
- package/lib/components/component-type.js +28 -0
- package/lib/components/form.props.json +37 -7
- package/lib/components/form.ws.d.ts +5 -0
- package/lib/components/form.ws.d.ts.map +1 -0
- package/lib/components/form.ws.js +26 -0
- package/lib/components/heading.d.ts +2 -2
- package/lib/components/heading.d.ts.map +1 -1
- package/lib/components/heading.js +1 -4
- package/lib/components/heading.props.json +45 -8
- package/lib/components/heading.stories.d.ts +2 -2
- package/lib/components/heading.ws.d.ts +5 -0
- package/lib/components/heading.ws.d.ts.map +1 -0
- package/lib/components/heading.ws.js +15 -0
- package/lib/components/index.d.ts +11 -10
- package/lib/components/index.d.ts.map +1 -1
- package/lib/components/index.js +25 -23
- package/lib/components/index.test.d.ts +2 -0
- package/lib/components/index.test.d.ts.map +1 -0
- package/lib/components/index.test.js +33 -0
- package/lib/components/input.props.json +46 -8
- package/lib/components/input.ws.d.ts +5 -0
- package/lib/components/input.ws.d.ts.map +1 -0
- package/lib/components/input.ws.js +14 -0
- package/lib/components/italic.props.json +37 -7
- package/lib/components/italic.ws.d.ts +5 -0
- package/lib/components/italic.ws.d.ts.map +1 -0
- package/lib/components/italic.ws.js +14 -0
- package/lib/components/link.d.ts +2 -2
- package/lib/components/link.d.ts.map +1 -1
- package/lib/components/link.props.json +37 -7
- package/lib/components/link.stories.d.ts +6 -2
- package/lib/components/link.stories.d.ts.map +1 -1
- package/lib/components/link.ws.d.ts +5 -0
- package/lib/components/link.ws.d.ts.map +1 -0
- package/lib/components/link.ws.js +27 -0
- package/lib/components/meta.d.ts +1 -0
- package/lib/components/meta.d.ts.map +1 -1
- package/lib/components/meta.js +3 -1
- package/lib/components/paragraph.props.json +37 -7
- package/lib/components/paragraph.ws.d.ts +5 -0
- package/lib/components/paragraph.ws.d.ts.map +1 -0
- package/lib/components/paragraph.ws.js +15 -0
- package/lib/components/text-block.props.json +37 -7
- package/lib/components/text-block.ws.d.ts +5 -0
- package/lib/components/text-block.ws.d.ts.map +1 -0
- package/lib/components/text-block.ws.js +23 -0
- package/lib/css/categories.d.ts +1 -1
- package/lib/css/categories.js +1 -1
- package/lib/css/get-browser-style.js +1 -1
- package/lib/css/keyword-values.d.ts.map +1 -1
- package/lib/css/keyword-values.js +1149 -396
- package/lib/css/properties.d.ts +6 -4
- package/lib/css/properties.d.ts.map +1 -1
- package/lib/css/properties.js +3196 -3194
- package/lib/css/units.js +1 -1
- package/lib/db/instance.d.ts +5 -2
- package/lib/db/instance.d.ts.map +1 -1
- package/lib/db/instance.js +9 -1
- package/lib/db/types.d.ts +1 -2
- package/lib/db/types.d.ts.map +1 -1
- package/lib/index.d.ts +1 -0
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +1 -0
- package/lib/pubsub/create.d.ts +28 -0
- package/lib/pubsub/create.d.ts.map +1 -0
- package/lib/pubsub/create.js +58 -0
- package/lib/pubsub/index.d.ts +1 -2
- package/lib/pubsub/index.d.ts.map +1 -1
- package/lib/pubsub/index.js +1 -2
- package/lib/stitches/css.d.ts.map +1 -1
- package/lib/stitches/css.js +1 -0
- package/lib/stitches/to-css.js +2 -3
- package/lib/tree/create-elements-tree.d.ts.map +1 -1
- package/lib/tree/create-elements-tree.js +43 -12
- package/lib/tree/root.d.ts +1 -1
- package/lib/tree/root.d.ts.map +1 -1
- package/lib/tree/root.js +6 -6
- package/lib/tree/wrapper-component.js +2 -2
- package/lib/user-props/all-user-props.d.ts.map +1 -1
- package/lib/user-props/all-user-props.js +5 -4
- package/lib/user-props/use-user-props.js +1 -1
- package/package.json +13 -14
- package/lib/prisma.server.d.ts +0 -3
- package/lib/prisma.server.d.ts.map +0 -1
- package/lib/prisma.server.js +0 -8
- package/lib/pubsub/publish.d.ts +0 -17
- package/lib/pubsub/publish.d.ts.map +0 -1
- package/lib/pubsub/publish.js +0 -27
- package/lib/pubsub/subscribe.d.ts +0 -8
- package/lib/pubsub/subscribe.d.ts.map +0 -1
- package/lib/pubsub/subscribe.js +0 -31
- package/prisma/schema.prisma +0 -71
package/lib/css/units.js
CHANGED
package/lib/db/instance.d.ts
CHANGED
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
2
|
import * as components from "../components";
|
|
3
3
|
import { type CssRule } from "../css";
|
|
4
|
-
export declare type
|
|
4
|
+
export declare type BaseInstance = {
|
|
5
5
|
id: string;
|
|
6
6
|
component: keyof typeof components;
|
|
7
|
-
children: Array<Instance | string>;
|
|
8
7
|
cssRules: Array<CssRule>;
|
|
9
8
|
};
|
|
9
|
+
export declare type Instance = BaseInstance & {
|
|
10
|
+
children: Array<Instance | string>;
|
|
11
|
+
};
|
|
12
|
+
export declare const toBaseInstance: (instance: Instance) => BaseInstance;
|
|
10
13
|
export declare const InstanceSchema: z.ZodType<Instance, z.ZodTypeDef, Instance>;
|
|
11
14
|
//# sourceMappingURL=instance.d.ts.map
|
package/lib/db/instance.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"instance.d.ts","sourceRoot":"","sources":["../../src/db/instance.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,KAAK,UAAU,MAAM,eAAe,CAAC;AAC5C,OAAO,EAAE,KAAK,OAAO,EAAiB,MAAM,QAAQ,CAAC;
|
|
1
|
+
{"version":3,"file":"instance.d.ts","sourceRoot":"","sources":["../../src/db/instance.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,KAAK,UAAU,MAAM,eAAe,CAAC;AAC5C,OAAO,EAAE,KAAK,OAAO,EAAiB,MAAM,QAAQ,CAAC;AAIrD,oBAAY,YAAY,GAAG;IACzB,EAAE,EAAE,MAAM,CAAC;IACX,SAAS,EAAE,MAAM,OAAO,UAAU,CAAC;IACnC,QAAQ,EAAE,KAAK,CAAC,OAAO,CAAC,CAAC;CAC1B,CAAC;AAEF,oBAAY,QAAQ,GAAG,YAAY,GAAG;IACpC,QAAQ,EAAE,KAAK,CAAC,QAAQ,GAAG,MAAM,CAAC,CAAC;CACpC,CAAC;AAEF,eAAO,MAAM,cAAc,aAAc,QAAQ,KAAG,YAMnD,CAAC;AAEF,eAAO,MAAM,cAAc,6CASH,CAAC"}
|
package/lib/db/instance.js
CHANGED
|
@@ -1,8 +1,16 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.InstanceSchema = void 0;
|
|
3
|
+
exports.InstanceSchema = exports.toBaseInstance = void 0;
|
|
4
4
|
const zod_1 = require("zod");
|
|
5
5
|
const css_1 = require("../css");
|
|
6
|
+
const toBaseInstance = (instance) => {
|
|
7
|
+
return {
|
|
8
|
+
id: instance.id,
|
|
9
|
+
component: instance.component,
|
|
10
|
+
cssRules: instance.cssRules,
|
|
11
|
+
};
|
|
12
|
+
};
|
|
13
|
+
exports.toBaseInstance = toBaseInstance;
|
|
6
14
|
exports.InstanceSchema = zod_1.z.lazy(() => zod_1.z.object({
|
|
7
15
|
id: zod_1.z.string(),
|
|
8
16
|
component: zod_1.z.string(),
|
package/lib/db/types.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { InstanceProps as DbInstanceProps
|
|
1
|
+
import type { InstanceProps as DbInstanceProps } from "@webstudio-is/prisma-client";
|
|
2
2
|
import type { UserProp } from "../user-props";
|
|
3
3
|
import type { Instance } from "./instance";
|
|
4
4
|
export declare type Tree = {
|
|
@@ -8,5 +8,4 @@ export declare type Tree = {
|
|
|
8
8
|
export declare type InstanceProps = Omit<DbInstanceProps, "props"> & {
|
|
9
9
|
props: Array<UserProp>;
|
|
10
10
|
};
|
|
11
|
-
export type { DbInstanceProps, Project, User, Breakpoints, Asset };
|
|
12
11
|
//# sourceMappingURL=types.d.ts.map
|
package/lib/db/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/db/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/db/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,IAAI,eAAe,EAAE,MAAM,6BAA6B,CAAC;AACpF,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAC9C,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAE3C,oBAAY,IAAI,GAAG;IACjB,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,QAAQ,CAAC;CAChB,CAAC;AAEF,oBAAY,aAAa,GAAG,IAAI,CAAC,eAAe,EAAE,OAAO,CAAC,GAAG;IAC3D,KAAK,EAAE,KAAK,CAAC,QAAQ,CAAC,CAAC;CACxB,CAAC"}
|
package/lib/index.d.ts
CHANGED
package/lib/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,OAAO,CAAC;AACtB,cAAc,QAAQ,CAAC;AACvB,cAAc,YAAY,CAAC;AAC3B,OAAO,KAAK,UAAU,MAAM,cAAc,CAAC;AAC3C,OAAO,KAAK,cAAc,MAAM,mBAAmB,CAAC;AACpD,cAAc,cAAc,CAAC;AAC7B,cAAc,UAAU,CAAC;AACzB,cAAc,MAAM,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,OAAO,CAAC;AACtB,cAAc,QAAQ,CAAC;AACvB,cAAc,YAAY,CAAC;AAC3B,OAAO,KAAK,UAAU,MAAM,cAAc,CAAC;AAC3C,OAAO,KAAK,cAAc,MAAM,mBAAmB,CAAC;AACpD,cAAc,cAAc,CAAC;AAC7B,cAAc,UAAU,CAAC;AACzB,cAAc,MAAM,CAAC;AACrB,cAAc,UAAU,CAAC"}
|
package/lib/index.js
CHANGED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
export declare const createPubsub: <PublishMap>() => {
|
|
3
|
+
/**
|
|
4
|
+
* To publish a postMessage event on the current window and parent window from the iframe.
|
|
5
|
+
*/
|
|
6
|
+
publish<Type extends keyof PublishMap>(action: undefined extends PublishMap[Type] ? {
|
|
7
|
+
type: Type;
|
|
8
|
+
payload?: PublishMap[Type] | undefined;
|
|
9
|
+
} : {
|
|
10
|
+
type: Type;
|
|
11
|
+
payload: PublishMap[Type];
|
|
12
|
+
}): void;
|
|
13
|
+
/**
|
|
14
|
+
* To publish a postMessage event on the iframe and parent window from the parent window.
|
|
15
|
+
*/
|
|
16
|
+
usePublish(): readonly [<Type_1 extends keyof PublishMap>(action: undefined extends PublishMap[Type_1] ? {
|
|
17
|
+
type: Type_1;
|
|
18
|
+
payload?: PublishMap[Type_1] | undefined;
|
|
19
|
+
} : {
|
|
20
|
+
type: Type_1;
|
|
21
|
+
payload: PublishMap[Type_1];
|
|
22
|
+
}) => void, import("react").MutableRefObject<HTMLIFrameElement | null>];
|
|
23
|
+
/**
|
|
24
|
+
* To subscribe a message event on the current window.
|
|
25
|
+
*/
|
|
26
|
+
useSubscribe<Type_2 extends keyof PublishMap>(type: Type_2, onAction: (payload: PublishMap[Type_2]) => void): void;
|
|
27
|
+
};
|
|
28
|
+
//# sourceMappingURL=create.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"create.d.ts","sourceRoot":"","sources":["../../src/pubsub/create.ts"],"names":[],"mappings":";AAGA,eAAO,MAAM,YAAY;IA0BrB;;OAEG;;;;;;;;IAMH;;OAEG;;;;;;;;IAeH;;OAEG;2GAGwC,IAAI;CAUlD,CAAC"}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.createPubsub = void 0;
|
|
7
|
+
const mitt_1 = __importDefault(require("mitt"));
|
|
8
|
+
const react_1 = require("react");
|
|
9
|
+
const createPubsub = () => {
|
|
10
|
+
// `mitt` has a somewhat annoying overload for `*` type that makes it hard to wrap in a generic context
|
|
11
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
12
|
+
const emitter = (0, mitt_1.default)();
|
|
13
|
+
if (typeof window === "object") {
|
|
14
|
+
window.addEventListener("message", (event) => {
|
|
15
|
+
// @todo this has no type safety built in, could be anything from any source.
|
|
16
|
+
// we could potentially maintain a list of valid event types at runtime
|
|
17
|
+
// at the very least we could add a brand property or something to our events
|
|
18
|
+
if (typeof event.data?.type === "string") {
|
|
19
|
+
emitter.emit(event.data.type, event.data.payload);
|
|
20
|
+
}
|
|
21
|
+
}, false);
|
|
22
|
+
}
|
|
23
|
+
return {
|
|
24
|
+
/**
|
|
25
|
+
* To publish a postMessage event on the current window and parent window from the iframe.
|
|
26
|
+
*/
|
|
27
|
+
publish(action) {
|
|
28
|
+
window.parent.postMessage(action, "*");
|
|
29
|
+
window.postMessage(action, "*");
|
|
30
|
+
},
|
|
31
|
+
/**
|
|
32
|
+
* To publish a postMessage event on the iframe and parent window from the parent window.
|
|
33
|
+
*/
|
|
34
|
+
usePublish() {
|
|
35
|
+
const iframeRef = (0, react_1.useRef)(null);
|
|
36
|
+
const publishCallback = (0, react_1.useCallback)((action) => {
|
|
37
|
+
const element = iframeRef.current;
|
|
38
|
+
if (element?.contentWindow == null)
|
|
39
|
+
return;
|
|
40
|
+
element.contentWindow.postMessage(action, "*");
|
|
41
|
+
window.postMessage(action, "*");
|
|
42
|
+
}, [iframeRef]);
|
|
43
|
+
return [publishCallback, iframeRef];
|
|
44
|
+
},
|
|
45
|
+
/**
|
|
46
|
+
* To subscribe a message event on the current window.
|
|
47
|
+
*/
|
|
48
|
+
useSubscribe(type, onAction) {
|
|
49
|
+
(0, react_1.useEffect)(() => {
|
|
50
|
+
emitter.on(type, onAction);
|
|
51
|
+
return () => {
|
|
52
|
+
emitter.off(type, onAction);
|
|
53
|
+
};
|
|
54
|
+
}, [type, onAction]);
|
|
55
|
+
},
|
|
56
|
+
};
|
|
57
|
+
};
|
|
58
|
+
exports.createPubsub = createPubsub;
|
package/lib/pubsub/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/pubsub/index.ts"],"names":[],"mappings":"AAAA,cAAc,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/pubsub/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC"}
|
package/lib/pubsub/index.js
CHANGED
|
@@ -14,5 +14,4 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./
|
|
18
|
-
__exportStar(require("./subscribe"), exports);
|
|
17
|
+
__exportStar(require("./create"), exports);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"css.d.ts","sourceRoot":"","sources":["../../src/stitches/css.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,SAAS,
|
|
1
|
+
{"version":3,"file":"css.d.ts","sourceRoot":"","sources":["../../src/stitches/css.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,SAAS,EACT,KAAK,GAAG,EACR,GAAG,IAAI,SAAS,EACjB,MAAM,gBAAgB,CAAC;AACxB,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAC;AAQzC,eAAO,MAAM,eAAe,WAK3B,CAAC;AAEF,eAAO,MAAM,GAAG,EAAE,OAAO,SAExB,CAAC;AAEF,OAAO,EAAE,SAAS,EAAE,CAAC;AACrB,OAAO,EAAE,KAAK,GAAG,EAAE,CAAC;AAEpB,eAAO,MAAM,UAAU,QAAO,MAE7B,CAAC;AAEF,eAAO,MAAM,cAAc,gBAAiB,MAAM,UAAU,CAAC,SAO5D,CAAC"}
|
package/lib/stitches/css.js
CHANGED
|
@@ -5,6 +5,7 @@ const core_1 = require("@stitches/core");
|
|
|
5
5
|
Object.defineProperty(exports, "globalCss", { enumerable: true, get: function () { return core_1.globalCss; } });
|
|
6
6
|
let media = {};
|
|
7
7
|
// @todo needs fixing
|
|
8
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
8
9
|
let stitches;
|
|
9
10
|
const getCachedConfig = () => {
|
|
10
11
|
if (stitches === undefined) {
|
package/lib/stitches/to-css.js
CHANGED
|
@@ -18,11 +18,10 @@ const toCss = (cssRules, breakpoints) => {
|
|
|
18
18
|
breakpointsMap[breakpoint.id] = breakpoint.minWidth;
|
|
19
19
|
}
|
|
20
20
|
const sortedCssRules = [...cssRules].sort((ruleA, ruleB) => {
|
|
21
|
-
var _a, _b;
|
|
22
21
|
// If a rule references a breakpoint that was not found in breakpoints,
|
|
23
22
|
// we must have removed the breakpoint and now we fall back to 0.
|
|
24
|
-
const maxWidthA =
|
|
25
|
-
const maxWidthB =
|
|
23
|
+
const maxWidthA = breakpointsMap[ruleA.breakpoint] ?? 0;
|
|
24
|
+
const maxWidthB = breakpointsMap[ruleB.breakpoint] ?? 0;
|
|
26
25
|
return maxWidthA - maxWidthB;
|
|
27
26
|
});
|
|
28
27
|
for (const cssRule of sortedCssRules) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"create-elements-tree.d.ts","sourceRoot":"","sources":["../../src/tree/create-elements-tree.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AACtC,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAC;AACzC,OAAO,EAAE,KAAK,qBAAqB,EAAE,MAAM,qBAAqB,CAAC;
|
|
1
|
+
{"version":3,"file":"create-elements-tree.d.ts","sourceRoot":"","sources":["../../src/tree/create-elements-tree.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AACtC,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAC;AACzC,OAAO,EAAE,KAAK,qBAAqB,EAAE,MAAM,qBAAqB,CAAC;AAGjE,oBAAY,eAAe,GAAG,KAAK,CAC/B,MAAM,GAEN;IAAE,EAAE,EAAE,QAAQ,CAAC,IAAI,CAAC,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,GAEpC;IACE,EAAE,EAAE,QAAQ,CAAC,IAAI,CAAC,CAAC;IACnB,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,EAAE,QAAQ,CAAC,WAAW,CAAC,CAAC;IACjC,cAAc,EAAE,IAAI,CAAC;CACtB,CACJ,CAAC;AAEF,oBAAY,gBAAgB,GAAG,CAAC,MAAM,EAAE;IACtC,UAAU,EAAE,QAAQ,CAAC,IAAI,CAAC,CAAC;IAC3B,OAAO,EAAE,eAAe,CAAC;CAC1B,KAAK,IAAI,CAAC;AAEX,eAAO,MAAM,kBAAkB;cAMnB,QAAQ;iBACL,MAAM,UAAU,CAAC;uBACX,qBAAqB,KAAK,WAAW;;iBAsBzD,CAAC"}
|
|
@@ -2,20 +2,52 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.createElementsTree = void 0;
|
|
4
4
|
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
5
|
+
const react_1 = require("react");
|
|
5
6
|
const stitches_1 = require("../stitches");
|
|
7
|
+
const react_2 = require("@remix-run/react");
|
|
6
8
|
const createElementsTree = ({ instance, breakpoints, Component, onChangeChildren, }) => {
|
|
7
|
-
const children =
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
9
|
+
const children = createInstanceChildrenElements({
|
|
10
|
+
Component,
|
|
11
|
+
children: instance.children,
|
|
12
|
+
breakpoints,
|
|
13
|
+
onChangeChildren,
|
|
14
|
+
});
|
|
15
|
+
const body = createInstanceElement({
|
|
16
|
+
Component,
|
|
17
|
+
instance,
|
|
18
|
+
children: [
|
|
19
|
+
(0, jsx_runtime_1.jsxs)(react_1.Fragment, { children: [children, (0, jsx_runtime_1.jsx)(react_2.ScrollRestoration, {}), (0, jsx_runtime_1.jsx)(react_2.Scripts, {})] }, "children"),
|
|
20
|
+
],
|
|
21
|
+
breakpoints,
|
|
22
|
+
});
|
|
23
|
+
return body;
|
|
24
|
+
};
|
|
25
|
+
exports.createElementsTree = createElementsTree;
|
|
26
|
+
const createInstanceChildrenElements = ({ children, breakpoints, Component, onChangeChildren, }) => {
|
|
27
|
+
const elements = [];
|
|
28
|
+
for (const child of children) {
|
|
29
|
+
if (typeof child === "string") {
|
|
30
|
+
elements.push(child);
|
|
31
|
+
continue;
|
|
32
|
+
}
|
|
33
|
+
const children = createInstanceChildrenElements({
|
|
34
|
+
children: child.children,
|
|
35
|
+
breakpoints,
|
|
36
|
+
Component,
|
|
37
|
+
onChangeChildren,
|
|
38
|
+
});
|
|
39
|
+
const element = createInstanceElement({
|
|
40
|
+
instance: child,
|
|
41
|
+
breakpoints,
|
|
42
|
+
Component,
|
|
43
|
+
onChangeChildren,
|
|
44
|
+
children,
|
|
45
|
+
});
|
|
46
|
+
elements.push(element);
|
|
18
47
|
}
|
|
48
|
+
return elements;
|
|
49
|
+
};
|
|
50
|
+
const createInstanceElement = ({ Component, instance, children = [], breakpoints, onChangeChildren, }) => {
|
|
19
51
|
const props = {
|
|
20
52
|
instance,
|
|
21
53
|
children,
|
|
@@ -25,4 +57,3 @@ const createElementsTree = ({ instance, breakpoints, Component, onChangeChildren
|
|
|
25
57
|
};
|
|
26
58
|
return (0, jsx_runtime_1.jsx)(Component, { ...props });
|
|
27
59
|
};
|
|
28
|
-
exports.createElementsTree = createElementsTree;
|
package/lib/tree/root.d.ts
CHANGED
|
@@ -11,6 +11,6 @@ declare type RootProps = {
|
|
|
11
11
|
data: Data;
|
|
12
12
|
Component?: (props: WrapperComponentProps) => JSX.Element;
|
|
13
13
|
};
|
|
14
|
-
export declare const
|
|
14
|
+
export declare const InstanceRoot: ({ data, Component, }: RootProps) => JSX.Element | null;
|
|
15
15
|
export {};
|
|
16
16
|
//# sourceMappingURL=root.d.ts.map
|
package/lib/tree/root.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"root.d.ts","sourceRoot":"","sources":["../../src/tree/root.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,IAAI,EAAE,aAAa,EAAE,MAAM,OAAO,CAAC;AACjD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAC;AAGzC,OAAO,EAEL,KAAK,qBAAqB,EAC3B,MAAM,qBAAqB,CAAC;AAE7B,oBAAY,IAAI,GAAG;IACjB,IAAI,EAAE,IAAI,GAAG,IAAI,CAAC;IAClB,WAAW,EAAE,KAAK,CAAC,UAAU,CAAC,CAAC;IAC/B,KAAK,EAAE,KAAK,CAAC,aAAa,CAAC,CAAC;CAC7B,CAAC;AAEF,eAAO,MAAM,YAAY,cAIvB,CAAC;AAEH,aAAK,SAAS,GAAG;IACf,IAAI,EAAE,IAAI,CAAC;IACX,SAAS,CAAC,EAAE,CAAC,KAAK,EAAE,qBAAqB,KAAK,GAAG,CAAC,OAAO,CAAC;CAC3D,CAAC;AAEF,eAAO,MAAM,
|
|
1
|
+
{"version":3,"file":"root.d.ts","sourceRoot":"","sources":["../../src/tree/root.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,IAAI,EAAE,aAAa,EAAE,MAAM,OAAO,CAAC;AACjD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAC;AAGzC,OAAO,EAEL,KAAK,qBAAqB,EAC3B,MAAM,qBAAqB,CAAC;AAE7B,oBAAY,IAAI,GAAG;IACjB,IAAI,EAAE,IAAI,GAAG,IAAI,CAAC;IAClB,WAAW,EAAE,KAAK,CAAC,UAAU,CAAC,CAAC;IAC/B,KAAK,EAAE,KAAK,CAAC,aAAa,CAAC,CAAC;CAC7B,CAAC;AAEF,eAAO,MAAM,YAAY,cAIvB,CAAC;AAEH,aAAK,SAAS,GAAG;IACf,IAAI,EAAE,IAAI,CAAC;IACX,SAAS,CAAC,EAAE,CAAC,KAAK,EAAE,qBAAqB,KAAK,GAAG,CAAC,OAAO,CAAC;CAC3D,CAAC;AAEF,eAAO,MAAM,YAAY,yBAGtB,SAAS,KAAG,WAAW,GAAG,IAY5B,CAAC"}
|
package/lib/tree/root.js
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.InstanceRoot = exports.globalStyles = void 0;
|
|
4
4
|
const user_props_1 = require("../user-props/");
|
|
5
5
|
const stitches_1 = require("../stitches");
|
|
6
6
|
const create_elements_tree_1 = require("./create-elements-tree");
|
|
7
7
|
const wrapper_component_1 = require("./wrapper-component");
|
|
8
8
|
exports.globalStyles = (0, stitches_1.globalCss)({
|
|
9
|
-
|
|
10
|
-
|
|
9
|
+
html: {
|
|
10
|
+
height: "100%",
|
|
11
11
|
},
|
|
12
12
|
});
|
|
13
|
-
const
|
|
13
|
+
const InstanceRoot = ({ data, Component, }) => {
|
|
14
14
|
if (data.tree === null) {
|
|
15
15
|
throw new Error("Tree is null");
|
|
16
16
|
}
|
|
@@ -20,7 +20,7 @@ const Root = ({ data, Component }) => {
|
|
|
20
20
|
return (0, create_elements_tree_1.createElementsTree)({
|
|
21
21
|
instance: data.tree.root,
|
|
22
22
|
breakpoints: data.breakpoints,
|
|
23
|
-
Component: Component
|
|
23
|
+
Component: Component ?? wrapper_component_1.WrapperComponent,
|
|
24
24
|
});
|
|
25
25
|
};
|
|
26
|
-
exports.
|
|
26
|
+
exports.InstanceRoot = InstanceRoot;
|
|
@@ -43,10 +43,10 @@ const renderWrapperComponentChildren = (children) => {
|
|
|
43
43
|
});
|
|
44
44
|
};
|
|
45
45
|
exports.renderWrapperComponentChildren = renderWrapperComponentChildren;
|
|
46
|
-
const WrapperComponent = ({ instance, css, onChangeChildren, // prevent it from passing to
|
|
46
|
+
const WrapperComponent = ({ instance, css, onChangeChildren, // prevent it from passing to sdk component
|
|
47
47
|
children, ...rest }) => {
|
|
48
48
|
const className = (0, react_1.useMemo)(() => (0, stitches_1.css)(css)(), [css]);
|
|
49
|
-
const Component = components[instance.component];
|
|
49
|
+
const { Component } = components[instance.component];
|
|
50
50
|
const userProps = (0, use_user_props_1.useUserProps)(instance.id);
|
|
51
51
|
return ((0, jsx_runtime_1.jsx)(Component, { ...userProps, ...rest, id: instance.id, className: className, children: (0, exports.renderWrapperComponentChildren)(children) }));
|
|
52
52
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"all-user-props.d.ts","sourceRoot":"","sources":["../../src/user-props/all-user-props.ts"],"names":[],"mappings":";AAEA,OAAO,KAAK,EAAE,aAAa,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAErD,oBAAY,YAAY,GAAG;IAAE,CAAC,EAAE,EAAE,QAAQ,CAAC,IAAI,CAAC,GAAG,aAAa,CAAA;CAAE,CAAC;AAEnE,eAAO,MAAM,qBAAqB,yDAAyC,CAAC;AAE5E,eAAO,MAAM,eAAe,sBAAuB,MAAM,aAAa,CAAC,
|
|
1
|
+
{"version":3,"file":"all-user-props.d.ts","sourceRoot":"","sources":["../../src/user-props/all-user-props.ts"],"names":[],"mappings":";AAEA,OAAO,KAAK,EAAE,aAAa,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAErD,oBAAY,YAAY,GAAG;IAAE,CAAC,EAAE,EAAE,QAAQ,CAAC,IAAI,CAAC,GAAG,aAAa,CAAA;CAAE,CAAC;AAEnE,eAAO,MAAM,qBAAqB,yDAAyC,CAAC;AAE5E,eAAO,MAAM,eAAe,sBAAuB,MAAM,aAAa,CAAC,sEAatE,CAAC"}
|
|
@@ -5,16 +5,17 @@ const react_1 = require("react");
|
|
|
5
5
|
const react_nano_state_1 = require("react-nano-state");
|
|
6
6
|
exports.allUserPropsContainer = (0, react_nano_state_1.createValueContainer)({});
|
|
7
7
|
const useAllUserProps = (initialUserProps) => {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
8
|
+
// @todo ssr workaround for https://github.com/webstudio-is/webstudio-designer/issues/213
|
|
9
|
+
const ref = (0, react_1.useRef)(false);
|
|
10
|
+
if (ref.current === false && initialUserProps !== undefined) {
|
|
11
11
|
const propsMap = {};
|
|
12
12
|
for (const props of initialUserProps) {
|
|
13
13
|
propsMap[props.instanceId] = props;
|
|
14
14
|
}
|
|
15
15
|
//We don't need to trigger rerender when setting the initial value
|
|
16
16
|
exports.allUserPropsContainer.value = propsMap;
|
|
17
|
-
|
|
17
|
+
ref.current = true;
|
|
18
|
+
}
|
|
18
19
|
return (0, react_nano_state_1.useValue)(exports.allUserPropsContainer);
|
|
19
20
|
};
|
|
20
21
|
exports.useAllUserProps = useAllUserProps;
|
|
@@ -8,7 +8,7 @@ const all_user_props_1 = require("./all-user-props");
|
|
|
8
8
|
* up to date with props panel.
|
|
9
9
|
*/
|
|
10
10
|
const useUserProps = (instanceId) => {
|
|
11
|
-
const [allUserProps
|
|
11
|
+
const [allUserProps] = (0, all_user_props_1.useAllUserProps)();
|
|
12
12
|
const propsData = allUserProps[instanceId];
|
|
13
13
|
const initialUserProps = (0, react_1.useMemo)(() => {
|
|
14
14
|
if (propsData === undefined)
|
package/package.json
CHANGED
|
@@ -1,26 +1,26 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@webstudio-is/react-sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.1",
|
|
4
4
|
"description": "Webstudio JavaScript / TypeScript API",
|
|
5
5
|
"author": "Webstudio <github@webstudio.is>",
|
|
6
6
|
"homepage": "https://webstudio.is",
|
|
7
7
|
"scripts": {
|
|
8
8
|
"dev": "tsup src/index.ts --format esm,cjs --watch --out-dir=lib",
|
|
9
9
|
"build": "yarn build:mdn-data && yarn build:args && yarn build:lib",
|
|
10
|
-
"build:mdn-data": "
|
|
11
|
-
"build:args": "
|
|
12
|
-
"build:prisma": "prisma format && prisma generate",
|
|
10
|
+
"build:mdn-data": "tsx ./bin/mdn-data.ts ./src/css",
|
|
11
|
+
"build:args": "tsx ./bin/generate-arg-types.ts './src/components/*.tsx !./src/**/*.stories.tsx !./src/**/*.ws.tsx'",
|
|
13
12
|
"typecheck": "tsc --noEmit",
|
|
14
13
|
"build:lib": "rm -fr lib && tsc",
|
|
15
|
-
"postinstall": "prisma generate",
|
|
16
14
|
"test": "jest",
|
|
17
|
-
"
|
|
15
|
+
"lint": "eslint ./src --ext .ts,.tsx --max-warnings 0",
|
|
16
|
+
"checks": "yarn typecheck && yarn lint && yarn test",
|
|
18
17
|
"prepublishOnly": "yarn checks && yarn build:lib",
|
|
19
18
|
"storybook:run": "start-storybook -p 6006",
|
|
20
19
|
"storybook:build": "build-storybook"
|
|
21
20
|
},
|
|
22
21
|
"devDependencies": {
|
|
23
22
|
"@babel/core": "^7.17.12",
|
|
23
|
+
"@esbuild-kit/esm-loader": "^2.4.2",
|
|
24
24
|
"@remix-run/react": "^1.2.3",
|
|
25
25
|
"@remix-run/server-runtime": "^1.2.3",
|
|
26
26
|
"@storybook/addon-actions": "^6.5.6",
|
|
@@ -34,19 +34,20 @@
|
|
|
34
34
|
"@types/css-tree": "^1.0.7",
|
|
35
35
|
"@types/fs-extra": "^9.0.13",
|
|
36
36
|
"@types/node": "^17.0.21",
|
|
37
|
+
"@webstudio-is/jest-config": "*",
|
|
38
|
+
"@webstudio-is/prisma-client": "*",
|
|
37
39
|
"babel-loader": "^8.2.5",
|
|
38
40
|
"camelcase": "^6.3.0",
|
|
39
41
|
"css-tree": "^2.1.0",
|
|
40
42
|
"esbuild": "^0.14.25",
|
|
41
43
|
"esbuild-node-externals": "^1.4.1",
|
|
42
|
-
"esbuild-node-loader": "^0.8.0",
|
|
43
|
-
"@webstudio-is/jest-config": "*",
|
|
44
44
|
"mdn-data": "2.0.23",
|
|
45
45
|
"react": "^17.0.2",
|
|
46
46
|
"react-docgen-typescript": "^2.2.2",
|
|
47
47
|
"react-dom": "^17.0.2",
|
|
48
48
|
"tsup": "^6.1.3",
|
|
49
|
-
"
|
|
49
|
+
"tsx": "^3.9.0",
|
|
50
|
+
"typescript": "4.7.4"
|
|
50
51
|
},
|
|
51
52
|
"peerDependencies": {
|
|
52
53
|
"@remix-run/react": "^1.2.3",
|
|
@@ -56,13 +57,12 @@
|
|
|
56
57
|
"react-dom": "^17.0.2"
|
|
57
58
|
},
|
|
58
59
|
"dependencies": {
|
|
59
|
-
"@prisma/client": "^3.10.0",
|
|
60
60
|
"@stitches/core": "^1.2.7",
|
|
61
|
+
"@webstudio-is/icons": "*",
|
|
62
|
+
"@webstudio-is/jest-config": "*",
|
|
61
63
|
"immer": "^9.0.12",
|
|
62
64
|
"mitt": "^3.0.0",
|
|
63
|
-
"prisma": "^3.10.0",
|
|
64
65
|
"react-nano-state": "^0.4.0",
|
|
65
|
-
"@webstudio-is/jest-config": "*",
|
|
66
66
|
"zod": "^3.17.3"
|
|
67
67
|
},
|
|
68
68
|
"main": "lib/index.js",
|
|
@@ -70,8 +70,7 @@
|
|
|
70
70
|
"files": [
|
|
71
71
|
"lib/*",
|
|
72
72
|
"README.md",
|
|
73
|
-
"!*.test.*"
|
|
74
|
-
"prisma/*"
|
|
73
|
+
"!*.test.*"
|
|
75
74
|
],
|
|
76
75
|
"license": "MIT",
|
|
77
76
|
"private": false
|
package/lib/prisma.server.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"prisma.server.d.ts","sourceRoot":"","sources":["../src/prisma.server.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AACtD,OAAO,EAAE,6BAA6B,EAAE,MAAM,wBAAwB,CAAC"}
|
package/lib/prisma.server.js
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.PrismaClientKnownRequestError = exports.Prisma = exports.PrismaClient = void 0;
|
|
4
|
-
var client_1 = require("@prisma/client");
|
|
5
|
-
Object.defineProperty(exports, "PrismaClient", { enumerable: true, get: function () { return client_1.PrismaClient; } });
|
|
6
|
-
Object.defineProperty(exports, "Prisma", { enumerable: true, get: function () { return client_1.Prisma; } });
|
|
7
|
-
var runtime_1 = require("@prisma/client/runtime");
|
|
8
|
-
Object.defineProperty(exports, "PrismaClientKnownRequestError", { enumerable: true, get: function () { return runtime_1.PrismaClientKnownRequestError; } });
|
package/lib/pubsub/publish.d.ts
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { MutableRefObject } from "react";
|
|
2
|
-
declare type Action<Type, Payload> = {
|
|
3
|
-
type: Type;
|
|
4
|
-
payload?: Payload;
|
|
5
|
-
};
|
|
6
|
-
export declare type Publish = <Type, Payload = undefined>(action: Action<Type, Payload>) => void;
|
|
7
|
-
declare type UsePublish = [Publish, MutableRefObject<HTMLIFrameElement | null>];
|
|
8
|
-
/**
|
|
9
|
-
* To publish a postMessage event on the iframe and parent window from the parent window.
|
|
10
|
-
*/
|
|
11
|
-
export declare const usePublish: () => UsePublish;
|
|
12
|
-
/**
|
|
13
|
-
* To publish a postMessage event on the current window and parent window from the iframe.
|
|
14
|
-
*/
|
|
15
|
-
export declare const publish: <Type extends string, Payload = undefined>(action: Action<Type, Payload>) => void;
|
|
16
|
-
export {};
|
|
17
|
-
//# sourceMappingURL=publish.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"publish.d.ts","sourceRoot":"","sources":["../../src/pubsub/publish.ts"],"names":[],"mappings":"AAAA,OAAO,EAAuB,gBAAgB,EAAE,MAAM,OAAO,CAAC;AAE9D,aAAK,MAAM,CAAC,IAAI,EAAE,OAAO,IAAI;IAC3B,IAAI,EAAE,IAAI,CAAC;IACX,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB,CAAC;AAEF,oBAAY,OAAO,GAAG,CAAC,IAAI,EAAE,OAAO,GAAG,SAAS,EAC9C,MAAM,EAAE,MAAM,CAAC,IAAI,EAAE,OAAO,CAAC,KAC1B,IAAI,CAAC;AAEV,aAAK,UAAU,GAAG,CAAC,OAAO,EAAE,gBAAgB,CAAC,iBAAiB,GAAG,IAAI,CAAC,CAAC,CAAC;AAExE;;GAEG;AACH,eAAO,MAAM,UAAU,kBAYtB,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,OAAO,mFAKnB,CAAC"}
|
package/lib/pubsub/publish.js
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.publish = exports.usePublish = void 0;
|
|
4
|
-
const react_1 = require("react");
|
|
5
|
-
/**
|
|
6
|
-
* To publish a postMessage event on the iframe and parent window from the parent window.
|
|
7
|
-
*/
|
|
8
|
-
const usePublish = () => {
|
|
9
|
-
const iframeRef = (0, react_1.useRef)(null);
|
|
10
|
-
const publishCallback = (0, react_1.useCallback)((action) => {
|
|
11
|
-
const element = iframeRef.current;
|
|
12
|
-
if ((element === null || element === void 0 ? void 0 : element.contentWindow) == null)
|
|
13
|
-
return;
|
|
14
|
-
element.contentWindow.postMessage(action, "*");
|
|
15
|
-
window.postMessage(action, "*");
|
|
16
|
-
}, [iframeRef]);
|
|
17
|
-
return [publishCallback, iframeRef];
|
|
18
|
-
};
|
|
19
|
-
exports.usePublish = usePublish;
|
|
20
|
-
/**
|
|
21
|
-
* To publish a postMessage event on the current window and parent window from the iframe.
|
|
22
|
-
*/
|
|
23
|
-
const publish = (action) => {
|
|
24
|
-
window.parent.postMessage(action, "*");
|
|
25
|
-
window.postMessage(action, "*");
|
|
26
|
-
};
|
|
27
|
-
exports.publish = publish;
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
declare type Events = Record<string, any>;
|
|
2
|
-
export declare const emitter: import("mitt").Emitter<Events>;
|
|
3
|
-
/**
|
|
4
|
-
* To subscribe a message event on the current window.
|
|
5
|
-
*/
|
|
6
|
-
export declare const useSubscribe: <Type extends string, Payload = undefined>(type: Type, onAction: (payload: Payload) => void) => void;
|
|
7
|
-
export {};
|
|
8
|
-
//# sourceMappingURL=subscribe.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"subscribe.d.ts","sourceRoot":"","sources":["../../src/pubsub/subscribe.ts"],"names":[],"mappings":"AAOA,aAAK,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;AAElC,eAAO,MAAM,OAAO,gCAAiB,CAAC;AAgBtC;;GAEG;AACH,eAAO,MAAM,YAAY,yFAES,IAAI,SAQrC,CAAC"}
|
package/lib/pubsub/subscribe.js
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.useSubscribe = exports.emitter = void 0;
|
|
7
|
-
const mitt_1 = __importDefault(require("mitt"));
|
|
8
|
-
const react_1 = require("react");
|
|
9
|
-
exports.emitter = (0, mitt_1.default)();
|
|
10
|
-
if (typeof window === "object") {
|
|
11
|
-
window.addEventListener("message", (event) => {
|
|
12
|
-
var _a;
|
|
13
|
-
// @todo this has no type safety built in, could be anything from any source.
|
|
14
|
-
// we could potentially maintain a list of valid event types, but see prior contra points.
|
|
15
|
-
if (typeof ((_a = event.data) === null || _a === void 0 ? void 0 : _a.type) === "string") {
|
|
16
|
-
exports.emitter.emit(event.data.type, event.data.payload);
|
|
17
|
-
}
|
|
18
|
-
}, false);
|
|
19
|
-
}
|
|
20
|
-
/**
|
|
21
|
-
* To subscribe a message event on the current window.
|
|
22
|
-
*/
|
|
23
|
-
const useSubscribe = (type, onAction) => {
|
|
24
|
-
(0, react_1.useEffect)(() => {
|
|
25
|
-
exports.emitter.on(type, onAction);
|
|
26
|
-
return () => {
|
|
27
|
-
exports.emitter.off(type, onAction);
|
|
28
|
-
};
|
|
29
|
-
}, [type, onAction]);
|
|
30
|
-
};
|
|
31
|
-
exports.useSubscribe = useSubscribe;
|