@weaverse/react 0.6.26 → 0.6.27
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/index.js +15 -16
- package/package.json +2 -2
- package/dist/index.d.ts +0 -98
- package/dist/index.mjs +0 -816
package/dist/index.js
CHANGED
|
@@ -588,14 +588,14 @@ Accordion.defaultProps = {
|
|
|
588
588
|
gap: 4,
|
|
589
589
|
".wv-accordion-header": {
|
|
590
590
|
borderRadius: 4,
|
|
591
|
-
padding:
|
|
591
|
+
padding: 12,
|
|
592
592
|
marginBottom: 4,
|
|
593
|
-
|
|
593
|
+
border: "1px solid #76A9FA",
|
|
594
594
|
"&.active": {
|
|
595
595
|
color: "blue"
|
|
596
596
|
},
|
|
597
597
|
'&.active + [data-wv-type="accordion.content"]': {
|
|
598
|
-
|
|
598
|
+
maxHeight: "var(--max-height, inherit)"
|
|
599
599
|
}
|
|
600
600
|
}
|
|
601
601
|
}
|
|
@@ -606,18 +606,17 @@ var accordion_default = Accordion;
|
|
|
606
606
|
// src/elements/accordion/AccordionWrapper.tsx
|
|
607
607
|
var import_react11 = __toESM(require("react"));
|
|
608
608
|
var AccordionWrapper = (0, import_react11.forwardRef)((props, ref) => {
|
|
609
|
-
const _a = props, {
|
|
609
|
+
const _a = props, { ["data-wv-id"]: wvId, headerText, children } = _a, rest = __objRest(_a, ["data-wv-id", "headerText", "children"]);
|
|
610
610
|
const { active, setActive } = (0, import_react11.useContext)(AccordionContext);
|
|
611
611
|
return /* @__PURE__ */ import_react11.default.createElement("div", __spreadValues({
|
|
612
612
|
ref
|
|
613
613
|
}, rest), /* @__PURE__ */ import_react11.default.createElement("div", {
|
|
614
|
-
onClick: () => setActive(
|
|
615
|
-
className: `wv-accordion-header ${active ===
|
|
616
|
-
}, headerText
|
|
614
|
+
onClick: () => setActive(wvId),
|
|
615
|
+
className: `wv-accordion-header ${active === wvId ? "active" : ""}`
|
|
616
|
+
}, headerText), children);
|
|
617
617
|
});
|
|
618
618
|
AccordionWrapper.defaultProps = {
|
|
619
|
-
|
|
620
|
-
headerText: "Header 1",
|
|
619
|
+
headerText: "Header text",
|
|
621
620
|
css: {
|
|
622
621
|
"@desktop": {
|
|
623
622
|
maxHeight: "100%"
|
|
@@ -635,7 +634,8 @@ var AccordionContent = (0, import_react12.forwardRef)((props, ref) => {
|
|
|
635
634
|
"--columns": columns,
|
|
636
635
|
"--gap": gap + "px",
|
|
637
636
|
"--row-size": rowSize + "px",
|
|
638
|
-
"--col-size": "calc((var(--grid-size) - calc(var(--columns) - 1) * var(--gap)) / var(--columns))"
|
|
637
|
+
"--col-size": "calc((var(--grid-size) - calc(var(--columns) - 1) * var(--gap)) / var(--columns))",
|
|
638
|
+
"--max-height": rows * rowSize + gap * (rowSize - 1) + "px"
|
|
639
639
|
};
|
|
640
640
|
return /* @__PURE__ */ import_react12.default.createElement("div", __spreadProps(__spreadValues({
|
|
641
641
|
ref
|
|
@@ -654,11 +654,13 @@ AccordionContent.defaultProps = {
|
|
|
654
654
|
"@desktop": {
|
|
655
655
|
width: "100%",
|
|
656
656
|
maxWidth: "var(--grid-size)",
|
|
657
|
-
|
|
658
|
-
display: "none",
|
|
657
|
+
display: "grid",
|
|
659
658
|
gridTemplateRows: "repeat(var(--rows), var(--row-size))",
|
|
660
659
|
gridTemplateColumns: "repeat(var(--columns), minmax(0, var(--col-size)))",
|
|
661
660
|
gap: "var(--gap)",
|
|
661
|
+
overflow: "hidden",
|
|
662
|
+
maxHeight: 0,
|
|
663
|
+
transition: "all 0.3s ease-in-out",
|
|
662
664
|
borderRadius: 4
|
|
663
665
|
}
|
|
664
666
|
}
|
|
@@ -762,12 +764,9 @@ var WeaverseRoot = ({ context }) => {
|
|
|
762
764
|
var _a, _b;
|
|
763
765
|
let [, setData] = (0, import_react14.useState)(context.projectData);
|
|
764
766
|
let rootRef = (0, import_react14.useRef)();
|
|
767
|
+
let update = () => setData({});
|
|
765
768
|
(0, import_react14.useEffect)(() => {
|
|
766
|
-
let update = () => setData({});
|
|
767
769
|
context.subscribe(update);
|
|
768
|
-
if (context.projectData) {
|
|
769
|
-
setTimeout(update, 110);
|
|
770
|
-
}
|
|
771
770
|
context.contentRootElement = rootRef.current;
|
|
772
771
|
return () => {
|
|
773
772
|
context.unsubscribe(update);
|
package/package.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "0.6.
|
|
2
|
+
"version": "0.6.27",
|
|
3
3
|
"license": "MIT",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"typings": "dist/index.d.ts",
|
|
@@ -31,6 +31,6 @@
|
|
|
31
31
|
"name": "@weaverse/react",
|
|
32
32
|
"author": "Weaverse Team",
|
|
33
33
|
"dependencies": {
|
|
34
|
-
"@weaverse/core": "0.6.
|
|
34
|
+
"@weaverse/core": "0.6.27"
|
|
35
35
|
}
|
|
36
36
|
}
|
package/dist/index.d.ts
DELETED
|
@@ -1,98 +0,0 @@
|
|
|
1
|
-
import * as react from 'react';
|
|
2
|
-
import { ReactElement, ReactNode } from 'react';
|
|
3
|
-
import { WeaverseType, Weaverse, ElementCSS, WeaverseItemStore } from '@weaverse/core';
|
|
4
|
-
export * from '@weaverse/core';
|
|
5
|
-
|
|
6
|
-
declare let createRootContext: (configs: WeaverseType) => Weaverse;
|
|
7
|
-
declare let WeaverseContext: react.Context<Weaverse>;
|
|
8
|
-
declare let WeaverseContextProvider: react.Provider<Weaverse>;
|
|
9
|
-
declare let WeaverseContextConsumer: react.Consumer<Weaverse>;
|
|
10
|
-
|
|
11
|
-
interface WeaverseElementProps extends ReactElement {
|
|
12
|
-
css?: ElementCSS;
|
|
13
|
-
children?: ReactElement | ReactElement[] | ReactNode | ReactNode[];
|
|
14
|
-
}
|
|
15
|
-
declare type WeaverseRootPropsType = {
|
|
16
|
-
context: Weaverse;
|
|
17
|
-
};
|
|
18
|
-
declare type ItemComponentProps = {
|
|
19
|
-
instance: InstanceType<typeof WeaverseItemStore>;
|
|
20
|
-
};
|
|
21
|
-
interface PlaceholderProps {
|
|
22
|
-
element: string;
|
|
23
|
-
children: ReactElement | ReactElement[] | ReactNode | ReactNode[];
|
|
24
|
-
}
|
|
25
|
-
interface ButtonElementProps extends WeaverseElementProps {
|
|
26
|
-
value: string;
|
|
27
|
-
openInNewTab: boolean;
|
|
28
|
-
target: string;
|
|
29
|
-
type: 'button' | 'submit' | 'reset';
|
|
30
|
-
}
|
|
31
|
-
interface ContainerElementProps extends WeaverseElementProps {
|
|
32
|
-
[key: string]: any;
|
|
33
|
-
}
|
|
34
|
-
interface ImageElementProps extends WeaverseElementProps {
|
|
35
|
-
src: string;
|
|
36
|
-
alt: string;
|
|
37
|
-
objectFit: 'contain' | 'cover';
|
|
38
|
-
objectPosition: 'left' | 'right' | 'top' | 'bottom' | 'center' | 'center left' | 'center right' | 'top left' | 'top right' | 'bottom left' | 'bottom right';
|
|
39
|
-
onClickAction: 'none' | 'open-lightbox' | 'open-link';
|
|
40
|
-
linkTo?: string;
|
|
41
|
-
openLinkInNewTab?: boolean;
|
|
42
|
-
}
|
|
43
|
-
interface LayoutElementProps extends WeaverseElementProps {
|
|
44
|
-
gridSize: number;
|
|
45
|
-
rows: number;
|
|
46
|
-
columns: number;
|
|
47
|
-
gap: number;
|
|
48
|
-
rowSize: number;
|
|
49
|
-
}
|
|
50
|
-
interface MapElementProps extends WeaverseElementProps {
|
|
51
|
-
place: string;
|
|
52
|
-
zoom: number;
|
|
53
|
-
}
|
|
54
|
-
interface TextElementProps extends WeaverseElementProps {
|
|
55
|
-
value: string;
|
|
56
|
-
}
|
|
57
|
-
interface VideoElementProps extends WeaverseElementProps {
|
|
58
|
-
src: string;
|
|
59
|
-
poster: string;
|
|
60
|
-
loop: boolean;
|
|
61
|
-
type: string;
|
|
62
|
-
controls: boolean;
|
|
63
|
-
autoPlay: boolean;
|
|
64
|
-
muted: boolean;
|
|
65
|
-
}
|
|
66
|
-
declare type CountdownTimeKey = 'days' | 'hours' | 'minutes' | 'seconds';
|
|
67
|
-
interface CountdownElementProps extends WeaverseElementProps {
|
|
68
|
-
timerType: 'fixed-time' | 'evergreen';
|
|
69
|
-
startTime: number;
|
|
70
|
-
endTime: number;
|
|
71
|
-
periods: number;
|
|
72
|
-
redirectUrl: string;
|
|
73
|
-
openInNewTab: boolean;
|
|
74
|
-
showLabel: boolean;
|
|
75
|
-
showColon: boolean;
|
|
76
|
-
}
|
|
77
|
-
declare type TimerBlockProps = {
|
|
78
|
-
label: string;
|
|
79
|
-
value: number;
|
|
80
|
-
};
|
|
81
|
-
interface InstagramElementProps extends WeaverseElementProps {
|
|
82
|
-
token: string;
|
|
83
|
-
username: string;
|
|
84
|
-
numberOfImages: number;
|
|
85
|
-
imagesPerRow: number;
|
|
86
|
-
gap: number;
|
|
87
|
-
}
|
|
88
|
-
declare type InstagramMedia = {
|
|
89
|
-
id: string;
|
|
90
|
-
media_type: 'IMAGE' | 'CAROUSEL_ALBUM';
|
|
91
|
-
media_url: string;
|
|
92
|
-
permalink: string;
|
|
93
|
-
caption: string;
|
|
94
|
-
};
|
|
95
|
-
|
|
96
|
-
declare let WeaverseRoot: ({ context }: WeaverseRootPropsType) => JSX.Element | null;
|
|
97
|
-
|
|
98
|
-
export { ButtonElementProps, ContainerElementProps, CountdownElementProps, CountdownTimeKey, ImageElementProps, InstagramElementProps, InstagramMedia, ItemComponentProps, LayoutElementProps, MapElementProps, PlaceholderProps, TextElementProps, TimerBlockProps, VideoElementProps, WeaverseContext, WeaverseContextConsumer, WeaverseContextProvider, WeaverseElementProps, WeaverseRoot, WeaverseRootPropsType, createRootContext };
|
package/dist/index.mjs
DELETED
|
@@ -1,816 +0,0 @@
|
|
|
1
|
-
var __defProp = Object.defineProperty;
|
|
2
|
-
var __defProps = Object.defineProperties;
|
|
3
|
-
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
4
|
-
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
7
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
8
|
-
var __spreadValues = (a, b) => {
|
|
9
|
-
for (var prop in b || (b = {}))
|
|
10
|
-
if (__hasOwnProp.call(b, prop))
|
|
11
|
-
__defNormalProp(a, prop, b[prop]);
|
|
12
|
-
if (__getOwnPropSymbols)
|
|
13
|
-
for (var prop of __getOwnPropSymbols(b)) {
|
|
14
|
-
if (__propIsEnum.call(b, prop))
|
|
15
|
-
__defNormalProp(a, prop, b[prop]);
|
|
16
|
-
}
|
|
17
|
-
return a;
|
|
18
|
-
};
|
|
19
|
-
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
20
|
-
var __objRest = (source, exclude) => {
|
|
21
|
-
var target = {};
|
|
22
|
-
for (var prop in source)
|
|
23
|
-
if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
|
|
24
|
-
target[prop] = source[prop];
|
|
25
|
-
if (source != null && __getOwnPropSymbols)
|
|
26
|
-
for (var prop of __getOwnPropSymbols(source)) {
|
|
27
|
-
if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
|
|
28
|
-
target[prop] = source[prop];
|
|
29
|
-
}
|
|
30
|
-
return target;
|
|
31
|
-
};
|
|
32
|
-
|
|
33
|
-
// src/context.ts
|
|
34
|
-
import { Weaverse } from "@weaverse/core";
|
|
35
|
-
import { createContext as createContext2 } from "react";
|
|
36
|
-
|
|
37
|
-
// src/elements/button.tsx
|
|
38
|
-
import * as React from "react";
|
|
39
|
-
var Button = React.forwardRef((props, ref) => {
|
|
40
|
-
let _a = props, { openInNewTab, target, value } = _a, rest = __objRest(_a, ["openInNewTab", "target", "value"]);
|
|
41
|
-
if (target) {
|
|
42
|
-
return /* @__PURE__ */ React.createElement("a", __spreadProps(__spreadValues({
|
|
43
|
-
href: target,
|
|
44
|
-
target: openInNewTab ? "_blank" : "_self",
|
|
45
|
-
rel: "noreferrer"
|
|
46
|
-
}, rest), {
|
|
47
|
-
ref
|
|
48
|
-
}), value);
|
|
49
|
-
}
|
|
50
|
-
return /* @__PURE__ */ React.createElement("button", __spreadValues({
|
|
51
|
-
ref
|
|
52
|
-
}, rest), value);
|
|
53
|
-
});
|
|
54
|
-
Button.defaultProps = {
|
|
55
|
-
value: "Shop now",
|
|
56
|
-
openInNewTab: false,
|
|
57
|
-
target: "",
|
|
58
|
-
type: "button",
|
|
59
|
-
css: {
|
|
60
|
-
"@desktop": {
|
|
61
|
-
borderRadius: "72px",
|
|
62
|
-
border: "none",
|
|
63
|
-
backgroundColor: "#0F71FF",
|
|
64
|
-
color: "#fff",
|
|
65
|
-
fontSize: "13px",
|
|
66
|
-
padding: "10px 20px"
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
};
|
|
70
|
-
var button_default = Button;
|
|
71
|
-
|
|
72
|
-
// src/elements/container.tsx
|
|
73
|
-
import React2, { forwardRef as forwardRef2 } from "react";
|
|
74
|
-
var Container = forwardRef2((props, ref) => {
|
|
75
|
-
let _a = props, { children } = _a, rest = __objRest(_a, ["children"]);
|
|
76
|
-
return /* @__PURE__ */ React2.createElement("div", __spreadValues({
|
|
77
|
-
ref
|
|
78
|
-
}, rest), children);
|
|
79
|
-
});
|
|
80
|
-
Container.defaultProps = {
|
|
81
|
-
css: {
|
|
82
|
-
"@desktop": {
|
|
83
|
-
alignItems: "flex-start",
|
|
84
|
-
backgroundColor: "rgba(248,203,203,0.38)",
|
|
85
|
-
display: "flex",
|
|
86
|
-
flexDirection: "column",
|
|
87
|
-
gridArea: "1 / 1 / 3 / 6",
|
|
88
|
-
height: "fit-content",
|
|
89
|
-
justifyContent: "flex-start",
|
|
90
|
-
overflow: "hidden",
|
|
91
|
-
textAlign: "left",
|
|
92
|
-
width: "100%"
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
};
|
|
96
|
-
var container_default = Container;
|
|
97
|
-
|
|
98
|
-
// src/elements/countdown/index.tsx
|
|
99
|
-
import React4, { forwardRef as forwardRef3, useContext, useEffect } from "react";
|
|
100
|
-
|
|
101
|
-
// src/elements/countdown/timer-block.tsx
|
|
102
|
-
import React3 from "react";
|
|
103
|
-
function TimerBlock({ value, label }) {
|
|
104
|
-
return /* @__PURE__ */ React3.createElement("div", null, /* @__PURE__ */ React3.createElement("div", {
|
|
105
|
-
className: "wv-countdown-number"
|
|
106
|
-
}, value.toString().padStart(2, "0")), label && /* @__PURE__ */ React3.createElement("div", {
|
|
107
|
-
className: "wv-countdown-label"
|
|
108
|
-
}, label));
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
// src/elements/countdown/utils.ts
|
|
112
|
-
var times = ["days", "hours", "minutes", "seconds"];
|
|
113
|
-
function getTime(_seconds) {
|
|
114
|
-
const ONE_MINUTE = 60 * 1e3;
|
|
115
|
-
const ONE_HOUR = 60 * ONE_MINUTE;
|
|
116
|
-
const ONE_DAY = 24 * ONE_HOUR;
|
|
117
|
-
const days = Math.floor(_seconds / ONE_DAY);
|
|
118
|
-
const hours = Math.floor((_seconds - days * ONE_DAY) / ONE_HOUR);
|
|
119
|
-
const minutes = Math.floor((_seconds - days * ONE_DAY - hours * ONE_HOUR) / ONE_MINUTE);
|
|
120
|
-
const seconds = Math.floor((_seconds - days * ONE_DAY - hours * ONE_HOUR - minutes * ONE_MINUTE) / 1e3);
|
|
121
|
-
return { days, hours, minutes, seconds };
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
// src/elements/countdown/index.tsx
|
|
125
|
-
var Countdown = forwardRef3((props, ref) => {
|
|
126
|
-
const { isDesignMode } = useContext(WeaverseContext);
|
|
127
|
-
let _a = props, {
|
|
128
|
-
timerType,
|
|
129
|
-
startTime,
|
|
130
|
-
endTime,
|
|
131
|
-
periods,
|
|
132
|
-
redirectUrl,
|
|
133
|
-
openInNewTab,
|
|
134
|
-
showColon,
|
|
135
|
-
showLabel
|
|
136
|
-
} = _a, rest = __objRest(_a, [
|
|
137
|
-
"timerType",
|
|
138
|
-
"startTime",
|
|
139
|
-
"endTime",
|
|
140
|
-
"periods",
|
|
141
|
-
"redirectUrl",
|
|
142
|
-
"openInNewTab",
|
|
143
|
-
"showColon",
|
|
144
|
-
"showLabel"
|
|
145
|
-
]);
|
|
146
|
-
const [remaining, setRemaining] = React4.useState(0);
|
|
147
|
-
if (typeof endTime !== "number") {
|
|
148
|
-
endTime = Number.parseInt(endTime);
|
|
149
|
-
}
|
|
150
|
-
useEffect(() => {
|
|
151
|
-
const flag = setInterval(() => {
|
|
152
|
-
const remainingTime = Math.max((timerType === "fixed-time" ? new Date(endTime).getTime() : new Date(startTime).getTime() + periods * 60 * 1e3) - Date.now(), 0);
|
|
153
|
-
if (!isDesignMode && redirectUrl && remainingTime > 0 && remainingTime < 1e3) {
|
|
154
|
-
window.open(redirectUrl, openInNewTab ? "_blank" : "_self");
|
|
155
|
-
}
|
|
156
|
-
setRemaining(remainingTime);
|
|
157
|
-
}, 1e3);
|
|
158
|
-
return () => {
|
|
159
|
-
clearInterval(flag);
|
|
160
|
-
};
|
|
161
|
-
}, [startTime, endTime, periods, timerType]);
|
|
162
|
-
const timer = getTime(remaining);
|
|
163
|
-
return /* @__PURE__ */ React4.createElement("div", __spreadValues({
|
|
164
|
-
ref
|
|
165
|
-
}, rest), times.map((time) => {
|
|
166
|
-
return /* @__PURE__ */ React4.createElement(React4.Fragment, {
|
|
167
|
-
key: time
|
|
168
|
-
}, /* @__PURE__ */ React4.createElement(TimerBlock, {
|
|
169
|
-
label: showLabel ? time : "",
|
|
170
|
-
value: timer[time]
|
|
171
|
-
}), time !== "seconds" && /* @__PURE__ */ React4.createElement("span", {
|
|
172
|
-
className: `wv-countdown-number ${showColon ? "" : "hidden"}`
|
|
173
|
-
}, ":"));
|
|
174
|
-
}));
|
|
175
|
-
});
|
|
176
|
-
Countdown.defaultProps = {
|
|
177
|
-
timerType: "fixed-time",
|
|
178
|
-
startTime: Date.now(),
|
|
179
|
-
endTime: 1661140528e3,
|
|
180
|
-
periods: 90,
|
|
181
|
-
redirectUrl: "https://myshop.com",
|
|
182
|
-
openInNewTab: false,
|
|
183
|
-
showLabel: true,
|
|
184
|
-
showColon: true,
|
|
185
|
-
css: {
|
|
186
|
-
"@desktop": {
|
|
187
|
-
fontFamily: "Inter",
|
|
188
|
-
fontSize: 36,
|
|
189
|
-
fontWeight: 500,
|
|
190
|
-
display: "grid",
|
|
191
|
-
gridAutoFlow: "column",
|
|
192
|
-
gap: 10,
|
|
193
|
-
"& > div": {
|
|
194
|
-
width: 48,
|
|
195
|
-
textAlign: "center"
|
|
196
|
-
},
|
|
197
|
-
".wv-countdown-label": {
|
|
198
|
-
fontSize: 10
|
|
199
|
-
},
|
|
200
|
-
"& > span": {
|
|
201
|
-
lineHeight: "100%"
|
|
202
|
-
},
|
|
203
|
-
"& .hidden": {
|
|
204
|
-
visibility: "hidden"
|
|
205
|
-
}
|
|
206
|
-
}
|
|
207
|
-
}
|
|
208
|
-
};
|
|
209
|
-
var countdown_default = Countdown;
|
|
210
|
-
|
|
211
|
-
// src/elements/image.tsx
|
|
212
|
-
import React5, { useContext as useContext2 } from "react";
|
|
213
|
-
var Image = React5.forwardRef((props, ref) => {
|
|
214
|
-
let { isDesignMode } = useContext2(WeaverseContext);
|
|
215
|
-
let _a = props, {
|
|
216
|
-
src,
|
|
217
|
-
alt,
|
|
218
|
-
objectFit,
|
|
219
|
-
objectPosition,
|
|
220
|
-
onClickAction,
|
|
221
|
-
openLinkInNewTab
|
|
222
|
-
} = _a, rest = __objRest(_a, [
|
|
223
|
-
"src",
|
|
224
|
-
"alt",
|
|
225
|
-
"objectFit",
|
|
226
|
-
"objectPosition",
|
|
227
|
-
"onClickAction",
|
|
228
|
-
"openLinkInNewTab"
|
|
229
|
-
]);
|
|
230
|
-
let style = {
|
|
231
|
-
"--wv-img-object-fit": objectFit,
|
|
232
|
-
"--wv-img-object-position": objectPosition
|
|
233
|
-
};
|
|
234
|
-
let handleClick = () => {
|
|
235
|
-
if (isDesignMode) {
|
|
236
|
-
return console.log("Click action:", onClickAction);
|
|
237
|
-
}
|
|
238
|
-
if (onClickAction) {
|
|
239
|
-
console.log("TODO: click action:", onClickAction);
|
|
240
|
-
}
|
|
241
|
-
};
|
|
242
|
-
return /* @__PURE__ */ React5.createElement("div", __spreadProps(__spreadValues({
|
|
243
|
-
ref
|
|
244
|
-
}, rest), {
|
|
245
|
-
style,
|
|
246
|
-
onClick: handleClick
|
|
247
|
-
}), /* @__PURE__ */ React5.createElement("img", {
|
|
248
|
-
alt,
|
|
249
|
-
src
|
|
250
|
-
}));
|
|
251
|
-
});
|
|
252
|
-
Image.defaultProps = {
|
|
253
|
-
src: "https://ucarecdn.com/1cdc9d39-ca62-492e-8ec7-f1a86b241a90/",
|
|
254
|
-
alt: "Image alt text",
|
|
255
|
-
objectFit: "cover",
|
|
256
|
-
objectPosition: "center",
|
|
257
|
-
onClickAction: "open-lightbox",
|
|
258
|
-
openLinkInNewTab: false,
|
|
259
|
-
css: {
|
|
260
|
-
"@desktop": {
|
|
261
|
-
img: {
|
|
262
|
-
width: "100%",
|
|
263
|
-
height: "100%",
|
|
264
|
-
objectFit: "var(--wv-img-object-fit, cover)",
|
|
265
|
-
objectPosition: "var(--wv-img-object-position, center)"
|
|
266
|
-
}
|
|
267
|
-
}
|
|
268
|
-
}
|
|
269
|
-
};
|
|
270
|
-
var image_default = Image;
|
|
271
|
-
|
|
272
|
-
// src/elements/layout.tsx
|
|
273
|
-
import React6, { forwardRef as forwardRef4 } from "react";
|
|
274
|
-
var Layout = forwardRef4((props, ref) => {
|
|
275
|
-
let _a = props, { children, rows, gap, rowSize, columns, gridSize } = _a, rest = __objRest(_a, ["children", "rows", "gap", "rowSize", "columns", "gridSize"]);
|
|
276
|
-
let style = {
|
|
277
|
-
"--grid-size": gridSize + "px",
|
|
278
|
-
"--rows": rows,
|
|
279
|
-
"--columns": columns,
|
|
280
|
-
"--gap": gap + "px",
|
|
281
|
-
"--row-size": rowSize + "px",
|
|
282
|
-
"--col-size": "calc((var(--grid-size) - calc(var(--columns) - 1) * var(--gap)) / var(--columns))"
|
|
283
|
-
};
|
|
284
|
-
return /* @__PURE__ */ React6.createElement("section", __spreadProps(__spreadValues({
|
|
285
|
-
ref
|
|
286
|
-
}, rest), {
|
|
287
|
-
style
|
|
288
|
-
}), /* @__PURE__ */ React6.createElement("div", {
|
|
289
|
-
"data-layout-content": true
|
|
290
|
-
}, children));
|
|
291
|
-
});
|
|
292
|
-
Layout.defaultProps = {
|
|
293
|
-
gridSize: 1224,
|
|
294
|
-
rows: 12,
|
|
295
|
-
columns: 12,
|
|
296
|
-
gap: 16,
|
|
297
|
-
rowSize: 48,
|
|
298
|
-
css: {
|
|
299
|
-
"@desktop": {
|
|
300
|
-
paddingTop: "16px",
|
|
301
|
-
paddingBottom: "16px",
|
|
302
|
-
paddingLeft: "var(--gap)",
|
|
303
|
-
paddingRight: "var(--gap)",
|
|
304
|
-
"> [data-layout-content]": {
|
|
305
|
-
margin: "0 auto",
|
|
306
|
-
display: "grid !important",
|
|
307
|
-
gridTemplateRows: "repeat(var(--rows), var(--row-size))",
|
|
308
|
-
gridTemplateColumns: "repeat(var(--columns), minmax(0, var(--col-size)))",
|
|
309
|
-
gap: "var(--gap)",
|
|
310
|
-
maxWidth: "var(--grid-size)"
|
|
311
|
-
}
|
|
312
|
-
},
|
|
313
|
-
"@mobile": {
|
|
314
|
-
padding: "0 16px",
|
|
315
|
-
"> [data-layout-content]": {
|
|
316
|
-
display: "flex !important",
|
|
317
|
-
flexDirection: "column"
|
|
318
|
-
}
|
|
319
|
-
}
|
|
320
|
-
}
|
|
321
|
-
};
|
|
322
|
-
var layout_default = Layout;
|
|
323
|
-
|
|
324
|
-
// src/elements/map.tsx
|
|
325
|
-
import React7, { forwardRef as forwardRef5 } from "react";
|
|
326
|
-
var Map = forwardRef5((props, ref) => {
|
|
327
|
-
let _a = props, { place, zoom } = _a, rest = __objRest(_a, ["place", "zoom"]);
|
|
328
|
-
return /* @__PURE__ */ React7.createElement("div", __spreadValues({
|
|
329
|
-
ref
|
|
330
|
-
}, rest), /* @__PURE__ */ React7.createElement("iframe", {
|
|
331
|
-
loading: "lazy",
|
|
332
|
-
scrolling: "no",
|
|
333
|
-
width: "100%",
|
|
334
|
-
height: "100%",
|
|
335
|
-
title: "map",
|
|
336
|
-
src: `https://maps.google.com/maps?z=${zoom}&t=m&q=${place}&ie=UTF8&&output=embed`,
|
|
337
|
-
style: { pointerEvents: "none" }
|
|
338
|
-
}));
|
|
339
|
-
});
|
|
340
|
-
Map.defaultProps = {
|
|
341
|
-
place: "Hanoi",
|
|
342
|
-
zoom: 14
|
|
343
|
-
};
|
|
344
|
-
var map_default = Map;
|
|
345
|
-
|
|
346
|
-
// src/elements/text.tsx
|
|
347
|
-
import * as React8 from "react";
|
|
348
|
-
var Text = React8.forwardRef((props, ref) => {
|
|
349
|
-
let _a = props, { children, value } = _a, rest = __objRest(_a, ["children", "value"]);
|
|
350
|
-
return /* @__PURE__ */ React8.createElement("div", __spreadProps(__spreadValues({
|
|
351
|
-
ref
|
|
352
|
-
}, rest), {
|
|
353
|
-
dangerouslySetInnerHTML: { __html: value }
|
|
354
|
-
}));
|
|
355
|
-
});
|
|
356
|
-
Text.defaultProps = {
|
|
357
|
-
value: "The quick brown fox jumps over the lazy dog",
|
|
358
|
-
css: {
|
|
359
|
-
"@desktop": {
|
|
360
|
-
width: "100%",
|
|
361
|
-
height: "fit-content",
|
|
362
|
-
padding: "20px",
|
|
363
|
-
outline: "none",
|
|
364
|
-
wordBreak: "break-word",
|
|
365
|
-
overflowWrap: "break-word",
|
|
366
|
-
whiteSpace: "break-spaces"
|
|
367
|
-
}
|
|
368
|
-
}
|
|
369
|
-
};
|
|
370
|
-
var text_default = Text;
|
|
371
|
-
|
|
372
|
-
// src/elements/video.tsx
|
|
373
|
-
import React9, { forwardRef as forwardRef7, useContext as useContext3 } from "react";
|
|
374
|
-
var Video = forwardRef7((props, ref) => {
|
|
375
|
-
let { isDesignMode } = useContext3(WeaverseContext);
|
|
376
|
-
let _a = props, { src, type, controls, poster, autoPlay, loop, muted } = _a, rest = __objRest(_a, ["src", "type", "controls", "poster", "autoPlay", "loop", "muted"]);
|
|
377
|
-
return /* @__PURE__ */ React9.createElement("div", __spreadValues({
|
|
378
|
-
ref
|
|
379
|
-
}, rest), /* @__PURE__ */ React9.createElement("video", {
|
|
380
|
-
controls: isDesignMode ? false : controls,
|
|
381
|
-
autoPlay: isDesignMode ? false : autoPlay,
|
|
382
|
-
loop,
|
|
383
|
-
muted: true,
|
|
384
|
-
controlsList: "nodownload",
|
|
385
|
-
disablePictureInPicture: true
|
|
386
|
-
}, /* @__PURE__ */ React9.createElement("source", {
|
|
387
|
-
src,
|
|
388
|
-
type: type || "video/mp4"
|
|
389
|
-
}), "Your browser does not support the video tag."));
|
|
390
|
-
});
|
|
391
|
-
Video.defaultProps = {
|
|
392
|
-
src: "https://youtu.be/wM-NT6hcw48",
|
|
393
|
-
poster: "https://ucarecdn.com/48d73272-3fe3-43f6-8b5b-22b68fc5a8c8/section.png",
|
|
394
|
-
loop: false,
|
|
395
|
-
type: "video/mp4",
|
|
396
|
-
controls: false,
|
|
397
|
-
autoPlay: true,
|
|
398
|
-
muted: true,
|
|
399
|
-
css: {
|
|
400
|
-
"@desktop": {
|
|
401
|
-
video: {
|
|
402
|
-
height: "100%",
|
|
403
|
-
width: "100%",
|
|
404
|
-
aspectRatio: "16 / 9"
|
|
405
|
-
}
|
|
406
|
-
}
|
|
407
|
-
}
|
|
408
|
-
};
|
|
409
|
-
var video_default = Video;
|
|
410
|
-
|
|
411
|
-
// src/elements/instagram.tsx
|
|
412
|
-
import React11, { forwardRef as forwardRef9, useEffect as useEffect2, useState } from "react";
|
|
413
|
-
|
|
414
|
-
// src/elements/shared/Placeholder.tsx
|
|
415
|
-
import React10, { forwardRef as forwardRef8 } from "react";
|
|
416
|
-
var Placeholder = forwardRef8((props, ref) => {
|
|
417
|
-
let _a = props, { element, children } = _a, rest = __objRest(_a, ["element", "children"]);
|
|
418
|
-
let style = {
|
|
419
|
-
position: "absolute",
|
|
420
|
-
height: "100%",
|
|
421
|
-
width: "100%",
|
|
422
|
-
display: "flex",
|
|
423
|
-
flexDirection: "column",
|
|
424
|
-
alignItems: "center",
|
|
425
|
-
justifyContent: "center",
|
|
426
|
-
color: "#374151",
|
|
427
|
-
pointerEvents: "none",
|
|
428
|
-
zIndex: 1
|
|
429
|
-
};
|
|
430
|
-
return /* @__PURE__ */ React10.createElement("div", __spreadValues({
|
|
431
|
-
style,
|
|
432
|
-
ref
|
|
433
|
-
}, rest), /* @__PURE__ */ React10.createElement("div", {
|
|
434
|
-
style: { fontWeight: 600, marginBottom: "10px" }
|
|
435
|
-
}, element), /* @__PURE__ */ React10.createElement("div", null, children));
|
|
436
|
-
});
|
|
437
|
-
var Placeholder_default = Placeholder;
|
|
438
|
-
|
|
439
|
-
// src/elements/instagram.tsx
|
|
440
|
-
var INSTAGRAM_API = "https://graph.instagram.com";
|
|
441
|
-
var Instagram = forwardRef9((props, ref) => {
|
|
442
|
-
let _a = props, { token, username, numberOfImages, imagesPerRow, gap } = _a, rest = __objRest(_a, ["token", "username", "numberOfImages", "imagesPerRow", "gap"]);
|
|
443
|
-
let [media, setMedia] = useState([]);
|
|
444
|
-
let [error, setError] = useState(null);
|
|
445
|
-
useEffect2(() => {
|
|
446
|
-
if (token) {
|
|
447
|
-
let params = new URLSearchParams({
|
|
448
|
-
access_token: token,
|
|
449
|
-
fields: "id,media_type,caption,media_url,permalink"
|
|
450
|
-
});
|
|
451
|
-
fetch(`${INSTAGRAM_API}/me/media?${params.toString()}`).then((res) => res.json()).then((res) => {
|
|
452
|
-
if (res.error) {
|
|
453
|
-
setError(res);
|
|
454
|
-
} else {
|
|
455
|
-
setError(null);
|
|
456
|
-
setMedia([...res.data]);
|
|
457
|
-
}
|
|
458
|
-
}).catch(setError);
|
|
459
|
-
}
|
|
460
|
-
}, [token]);
|
|
461
|
-
if (!token || error) {
|
|
462
|
-
return /* @__PURE__ */ React11.createElement("div", __spreadValues({
|
|
463
|
-
ref
|
|
464
|
-
}, rest), /* @__PURE__ */ React11.createElement(Placeholder_default, {
|
|
465
|
-
element: "Instagram"
|
|
466
|
-
}, !token ? "Connect your Instagram account to display photos on your site." : "Invalid or expired token!"));
|
|
467
|
-
}
|
|
468
|
-
let style = {
|
|
469
|
-
"--wv-ig-images-per-row": imagesPerRow,
|
|
470
|
-
"--wv-ig-images-gap": gap + "px"
|
|
471
|
-
};
|
|
472
|
-
return /* @__PURE__ */ React11.createElement("div", __spreadProps(__spreadValues({
|
|
473
|
-
ref
|
|
474
|
-
}, rest), {
|
|
475
|
-
style
|
|
476
|
-
}), /* @__PURE__ */ React11.createElement("div", {
|
|
477
|
-
className: "wv-ig-media-container"
|
|
478
|
-
}, media.slice(0, numberOfImages).map((item) => {
|
|
479
|
-
let { id, permalink, caption, media_url } = item;
|
|
480
|
-
return /* @__PURE__ */ React11.createElement("a", {
|
|
481
|
-
key: id,
|
|
482
|
-
href: permalink,
|
|
483
|
-
target: "_blank",
|
|
484
|
-
rel: "noreferrer"
|
|
485
|
-
}, /* @__PURE__ */ React11.createElement("img", {
|
|
486
|
-
alt: caption,
|
|
487
|
-
src: media_url
|
|
488
|
-
}));
|
|
489
|
-
})));
|
|
490
|
-
});
|
|
491
|
-
Instagram.defaultProps = {
|
|
492
|
-
token: "",
|
|
493
|
-
username: "",
|
|
494
|
-
numberOfImages: 8,
|
|
495
|
-
imagesPerRow: 4,
|
|
496
|
-
gap: 0,
|
|
497
|
-
css: {
|
|
498
|
-
"@desktop": {
|
|
499
|
-
".wv-ig-media-container": {
|
|
500
|
-
overflow: "hidden",
|
|
501
|
-
maxWidth: "100%",
|
|
502
|
-
maxHeight: "100%",
|
|
503
|
-
display: "grid",
|
|
504
|
-
gridTemplateColumns: "repeat(var(--wv-ig-images-per-row, 4), 1fr)",
|
|
505
|
-
gap: "var(--wv-ig-images-gap, 0px)",
|
|
506
|
-
img: {
|
|
507
|
-
aspectRatio: "1 / 1",
|
|
508
|
-
width: "100%",
|
|
509
|
-
height: "100%",
|
|
510
|
-
objectFit: "cover"
|
|
511
|
-
}
|
|
512
|
-
}
|
|
513
|
-
}
|
|
514
|
-
}
|
|
515
|
-
};
|
|
516
|
-
var instagram_default = Instagram;
|
|
517
|
-
|
|
518
|
-
// src/elements/accordion/index.tsx
|
|
519
|
-
import React12, { createContext, forwardRef as forwardRef10, useState as useState2 } from "react";
|
|
520
|
-
var AccordionContext = createContext({
|
|
521
|
-
active: null,
|
|
522
|
-
setActive: () => {
|
|
523
|
-
}
|
|
524
|
-
});
|
|
525
|
-
var Accordion = forwardRef10((props, ref) => {
|
|
526
|
-
const _a = props, { items, children } = _a, rest = __objRest(_a, ["items", "children"]);
|
|
527
|
-
const [active, setActive] = useState2(null);
|
|
528
|
-
const setOpenAccordion = (id) => {
|
|
529
|
-
if (id === active) {
|
|
530
|
-
setActive(null);
|
|
531
|
-
} else {
|
|
532
|
-
setActive(id);
|
|
533
|
-
}
|
|
534
|
-
};
|
|
535
|
-
console.info("9779 active", active);
|
|
536
|
-
return /* @__PURE__ */ React12.createElement("div", __spreadValues({
|
|
537
|
-
ref
|
|
538
|
-
}, rest), /* @__PURE__ */ React12.createElement(AccordionContext.Provider, {
|
|
539
|
-
value: { active, setActive: setOpenAccordion }
|
|
540
|
-
}, children));
|
|
541
|
-
});
|
|
542
|
-
Accordion.defaultProps = {
|
|
543
|
-
items: [
|
|
544
|
-
{
|
|
545
|
-
id: 1,
|
|
546
|
-
headerText: "Header 1",
|
|
547
|
-
childrenId: true
|
|
548
|
-
},
|
|
549
|
-
{
|
|
550
|
-
id: 2,
|
|
551
|
-
headerText: "Header 2"
|
|
552
|
-
}
|
|
553
|
-
],
|
|
554
|
-
css: {
|
|
555
|
-
"@desktop": {
|
|
556
|
-
display: "flex",
|
|
557
|
-
flexDirection: "column",
|
|
558
|
-
gap: 4,
|
|
559
|
-
".wv-accordion-header": {
|
|
560
|
-
borderRadius: 4,
|
|
561
|
-
padding: 4,
|
|
562
|
-
marginBottom: 4,
|
|
563
|
-
backgroundColor: "#aaa",
|
|
564
|
-
"&.active": {
|
|
565
|
-
color: "blue"
|
|
566
|
-
},
|
|
567
|
-
'&.active + [data-wv-type="accordion.content"]': {
|
|
568
|
-
display: "grid"
|
|
569
|
-
}
|
|
570
|
-
}
|
|
571
|
-
}
|
|
572
|
-
}
|
|
573
|
-
};
|
|
574
|
-
var accordion_default = Accordion;
|
|
575
|
-
|
|
576
|
-
// src/elements/accordion/AccordionWrapper.tsx
|
|
577
|
-
import React13, { forwardRef as forwardRef11, useContext as useContext4 } from "react";
|
|
578
|
-
var AccordionWrapper = forwardRef11((props, ref) => {
|
|
579
|
-
const _a = props, { wrapperId, headerText, children } = _a, rest = __objRest(_a, ["wrapperId", "headerText", "children"]);
|
|
580
|
-
const { active, setActive } = useContext4(AccordionContext);
|
|
581
|
-
return /* @__PURE__ */ React13.createElement("div", __spreadValues({
|
|
582
|
-
ref
|
|
583
|
-
}, rest), /* @__PURE__ */ React13.createElement("div", {
|
|
584
|
-
onClick: () => setActive(wrapperId),
|
|
585
|
-
className: `wv-accordion-header ${active === wrapperId ? "active" : ""}`
|
|
586
|
-
}, headerText, " #", wrapperId), children);
|
|
587
|
-
});
|
|
588
|
-
AccordionWrapper.defaultProps = {
|
|
589
|
-
wrapperId: 1,
|
|
590
|
-
headerText: "Header 1",
|
|
591
|
-
css: {
|
|
592
|
-
"@desktop": {
|
|
593
|
-
maxHeight: "100%"
|
|
594
|
-
}
|
|
595
|
-
}
|
|
596
|
-
};
|
|
597
|
-
var AccordionWrapper_default = AccordionWrapper;
|
|
598
|
-
|
|
599
|
-
// src/elements/accordion/AccordionContent.tsx
|
|
600
|
-
import React14, { forwardRef as forwardRef12 } from "react";
|
|
601
|
-
var AccordionContent = forwardRef12((props, ref) => {
|
|
602
|
-
const _a = props, { rows, columns, gap, rowSize, children } = _a, rest = __objRest(_a, ["rows", "columns", "gap", "rowSize", "children"]);
|
|
603
|
-
let style = {
|
|
604
|
-
"--rows": rows,
|
|
605
|
-
"--columns": columns,
|
|
606
|
-
"--gap": gap + "px",
|
|
607
|
-
"--row-size": rowSize + "px",
|
|
608
|
-
"--col-size": "calc((var(--grid-size) - calc(var(--columns) - 1) * var(--gap)) / var(--columns))"
|
|
609
|
-
};
|
|
610
|
-
return /* @__PURE__ */ React14.createElement("div", __spreadProps(__spreadValues({
|
|
611
|
-
ref
|
|
612
|
-
}, rest), {
|
|
613
|
-
style
|
|
614
|
-
}), React14.Children.count(children) > 0 ? children : /* @__PURE__ */ React14.createElement(Placeholder_default, {
|
|
615
|
-
element: "Accordion"
|
|
616
|
-
}, "Item Content"));
|
|
617
|
-
});
|
|
618
|
-
AccordionContent.defaultProps = {
|
|
619
|
-
rows: 2,
|
|
620
|
-
columns: 12,
|
|
621
|
-
gap: 4,
|
|
622
|
-
rowSize: 48,
|
|
623
|
-
css: {
|
|
624
|
-
"@desktop": {
|
|
625
|
-
width: "100%",
|
|
626
|
-
maxWidth: "var(--grid-size)",
|
|
627
|
-
backgroundColor: "#DDD",
|
|
628
|
-
display: "none",
|
|
629
|
-
gridTemplateRows: "repeat(var(--rows), var(--row-size))",
|
|
630
|
-
gridTemplateColumns: "repeat(var(--columns), minmax(0, var(--col-size)))",
|
|
631
|
-
gap: "var(--gap)",
|
|
632
|
-
borderRadius: 4
|
|
633
|
-
}
|
|
634
|
-
}
|
|
635
|
-
};
|
|
636
|
-
var AccordionContent_default = AccordionContent;
|
|
637
|
-
|
|
638
|
-
// src/elements/index.ts
|
|
639
|
-
var elements = {
|
|
640
|
-
Countdown: {
|
|
641
|
-
Component: countdown_default,
|
|
642
|
-
type: "countdown"
|
|
643
|
-
},
|
|
644
|
-
Button: {
|
|
645
|
-
Component: button_default,
|
|
646
|
-
type: "button"
|
|
647
|
-
},
|
|
648
|
-
Container: {
|
|
649
|
-
Component: container_default,
|
|
650
|
-
type: "container"
|
|
651
|
-
},
|
|
652
|
-
Image: {
|
|
653
|
-
Component: image_default,
|
|
654
|
-
type: "image"
|
|
655
|
-
},
|
|
656
|
-
Instagram: {
|
|
657
|
-
Component: instagram_default,
|
|
658
|
-
type: "instagram"
|
|
659
|
-
},
|
|
660
|
-
Layout: {
|
|
661
|
-
Component: layout_default,
|
|
662
|
-
type: "layout"
|
|
663
|
-
},
|
|
664
|
-
Map: {
|
|
665
|
-
Component: map_default,
|
|
666
|
-
type: "map"
|
|
667
|
-
},
|
|
668
|
-
Text: {
|
|
669
|
-
Component: text_default,
|
|
670
|
-
type: "text"
|
|
671
|
-
},
|
|
672
|
-
Video: {
|
|
673
|
-
Component: video_default,
|
|
674
|
-
type: "video"
|
|
675
|
-
},
|
|
676
|
-
Accordion: {
|
|
677
|
-
Component: accordion_default,
|
|
678
|
-
type: "accordion"
|
|
679
|
-
},
|
|
680
|
-
AccordionWrapper: {
|
|
681
|
-
Component: AccordionWrapper_default,
|
|
682
|
-
type: "accordion.wrapper"
|
|
683
|
-
},
|
|
684
|
-
AccordionContent: {
|
|
685
|
-
Component: AccordionContent_default,
|
|
686
|
-
type: "accordion.content"
|
|
687
|
-
}
|
|
688
|
-
};
|
|
689
|
-
var elements_default = elements;
|
|
690
|
-
|
|
691
|
-
// src/context.ts
|
|
692
|
-
var createRootContext = (configs) => {
|
|
693
|
-
let rootContext = new Weaverse(configs);
|
|
694
|
-
Object.keys(elements_default).forEach((key) => {
|
|
695
|
-
rootContext.registerElement(elements_default[key]);
|
|
696
|
-
});
|
|
697
|
-
return rootContext;
|
|
698
|
-
};
|
|
699
|
-
var WeaverseContext = createContext2({});
|
|
700
|
-
var WeaverseContextProvider = WeaverseContext.Provider;
|
|
701
|
-
var WeaverseContextConsumer = WeaverseContext.Consumer;
|
|
702
|
-
|
|
703
|
-
// src/renderer.tsx
|
|
704
|
-
import { isBrowser } from "@weaverse/core";
|
|
705
|
-
import React15, { useContext as useContext5, useEffect as useEffect3, useRef, useState as useState3 } from "react";
|
|
706
|
-
|
|
707
|
-
// src/utils/index.ts
|
|
708
|
-
var shortCssObject = (css) => {
|
|
709
|
-
return {
|
|
710
|
-
"@desktop": css["@desktop"],
|
|
711
|
-
"@mobile": css["@mobile"]
|
|
712
|
-
};
|
|
713
|
-
};
|
|
714
|
-
function generateItemClass(instance, stitchesInstance) {
|
|
715
|
-
var _a, _b, _c, _d;
|
|
716
|
-
let { css, className: cls = "" } = instance.data;
|
|
717
|
-
let defaultCss = ((_c = (_b = (_a = instance.Element) == null ? void 0 : _a.Component) == null ? void 0 : _b.defaultProps) == null ? void 0 : _c.css) || {};
|
|
718
|
-
let className = "";
|
|
719
|
-
if (css || defaultCss) {
|
|
720
|
-
let formattedCss = shortCssObject(css || defaultCss);
|
|
721
|
-
let { className: newClass = "" } = stitchesInstance.css(formattedCss)();
|
|
722
|
-
let { stitchesClass } = instance;
|
|
723
|
-
let otherClass = (((_d = instance.ref.current) == null ? void 0 : _d.className) || "").replace(stitchesClass, "").replace(cls, "").trim();
|
|
724
|
-
className = `${cls} ${newClass} ${otherClass}`.trim();
|
|
725
|
-
instance.stitchesClass = newClass;
|
|
726
|
-
}
|
|
727
|
-
return className;
|
|
728
|
-
}
|
|
729
|
-
|
|
730
|
-
// src/renderer.tsx
|
|
731
|
-
var WeaverseRoot = ({ context }) => {
|
|
732
|
-
var _a, _b;
|
|
733
|
-
let [, setData] = useState3(context.projectData);
|
|
734
|
-
let rootRef = useRef();
|
|
735
|
-
useEffect3(() => {
|
|
736
|
-
let update = () => setData({});
|
|
737
|
-
context.subscribe(update);
|
|
738
|
-
if (context.projectData) {
|
|
739
|
-
setTimeout(update, 110);
|
|
740
|
-
}
|
|
741
|
-
context.contentRootElement = rootRef.current;
|
|
742
|
-
return () => {
|
|
743
|
-
context.unsubscribe(update);
|
|
744
|
-
};
|
|
745
|
-
}, []);
|
|
746
|
-
let eventHandlers = ((_a = context == null ? void 0 : context.studioBridge) == null ? void 0 : _a.eventHandlers) || {};
|
|
747
|
-
let themeClass = context.stitchesInstance.theme.className;
|
|
748
|
-
return ((_b = context.projectData) == null ? void 0 : _b.rootId) ? /* @__PURE__ */ React15.createElement("div", __spreadProps(__spreadValues({
|
|
749
|
-
className: `weaverse-content-root ${themeClass}`
|
|
750
|
-
}, eventHandlers), {
|
|
751
|
-
ref: rootRef
|
|
752
|
-
}), /* @__PURE__ */ React15.createElement(WeaverseContextProvider, {
|
|
753
|
-
value: context
|
|
754
|
-
}, /* @__PURE__ */ React15.createElement(ItemInstance, {
|
|
755
|
-
id: context.projectData.rootId
|
|
756
|
-
}))) : null;
|
|
757
|
-
};
|
|
758
|
-
var ItemComponent = ({ instance }) => {
|
|
759
|
-
let { stitchesInstance, elementInstances } = useContext5(WeaverseContext);
|
|
760
|
-
let [data, setData] = useState3(instance.data);
|
|
761
|
-
let _a = data, { id, type, childIds = [], css, className } = _a, rest = __objRest(_a, ["id", "type", "childIds", "css", "className"]);
|
|
762
|
-
useEffect3(() => {
|
|
763
|
-
var _a2;
|
|
764
|
-
let update = (data2) => setData(__spreadValues({}, data2));
|
|
765
|
-
instance.subscribe(update);
|
|
766
|
-
if (isBrowser && !instance.ref.current) {
|
|
767
|
-
Object.assign(instance.ref, {
|
|
768
|
-
current: document.querySelector(`[data-wv-id="${id}"]`)
|
|
769
|
-
});
|
|
770
|
-
}
|
|
771
|
-
(_a2 = instance.ref.current) == null ? void 0 : _a2.removeAttribute("css");
|
|
772
|
-
return () => {
|
|
773
|
-
instance.unsubscribe(update);
|
|
774
|
-
};
|
|
775
|
-
}, []);
|
|
776
|
-
let Element = elementInstances.get(type);
|
|
777
|
-
if (Element == null ? void 0 : Element.Component) {
|
|
778
|
-
let Component = Element.Component;
|
|
779
|
-
if (Component.$$typeof === Symbol.for("react.forward_ref")) {
|
|
780
|
-
rest.ref = instance.ref;
|
|
781
|
-
}
|
|
782
|
-
return /* @__PURE__ */ React15.createElement(Component, __spreadValues({
|
|
783
|
-
key: id,
|
|
784
|
-
"data-wv-type": type,
|
|
785
|
-
"data-wv-id": id,
|
|
786
|
-
className: generateItemClass(instance, stitchesInstance)
|
|
787
|
-
}, rest), childIds.map((id2) => /* @__PURE__ */ React15.createElement(ItemInstance, {
|
|
788
|
-
key: id2,
|
|
789
|
-
id: id2
|
|
790
|
-
})));
|
|
791
|
-
}
|
|
792
|
-
return null;
|
|
793
|
-
};
|
|
794
|
-
var ItemInstance = ({ id }) => {
|
|
795
|
-
let context = useContext5(WeaverseContext);
|
|
796
|
-
let { itemInstances } = context;
|
|
797
|
-
let instance = itemInstances.get(id);
|
|
798
|
-
if (!instance) {
|
|
799
|
-
return /* @__PURE__ */ React15.createElement("div", {
|
|
800
|
-
style: { display: "none" }
|
|
801
|
-
}, "Item instance ", id, " not found");
|
|
802
|
-
}
|
|
803
|
-
return /* @__PURE__ */ React15.createElement(ItemComponent, {
|
|
804
|
-
instance
|
|
805
|
-
});
|
|
806
|
-
};
|
|
807
|
-
|
|
808
|
-
// src/index.ts
|
|
809
|
-
export * from "@weaverse/core";
|
|
810
|
-
export {
|
|
811
|
-
WeaverseContext,
|
|
812
|
-
WeaverseContextConsumer,
|
|
813
|
-
WeaverseContextProvider,
|
|
814
|
-
WeaverseRoot,
|
|
815
|
-
createRootContext
|
|
816
|
-
};
|