@weaverse/core 0.7.67 → 0.7.68

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.d.ts CHANGED
@@ -90,7 +90,7 @@ type GridSize = {
90
90
  rowSpan: number;
91
91
  colSpan: number;
92
92
  };
93
- type ToolbarAction = "general-settings" | "settings-level-2" | "duplicate" | "delete" | "copy-styles" | "paste-styles" | "move-up" | "move-down" | "next-slide" | "prev-slide" | "change-background" | "toggle-visibility" | "more-actions";
93
+ type ToolbarAction = "general-settings" | "settings-level-2" | "text-presets" | "duplicate" | "delete" | "copy-styles" | "paste-styles" | "move-up" | "move-down" | "next-slide" | "prev-slide" | "change-background" | "toggle-visibility" | "more-actions";
94
94
  interface ElementSchema {
95
95
  title: string;
96
96
  type: string;
package/dist/index.js CHANGED
@@ -18,6 +18,10 @@ var __copyProps = (to, from, except, desc) => {
18
18
  return to;
19
19
  };
20
20
  var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
21
25
  isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
22
26
  mod
23
27
  ));
@@ -55,6 +59,7 @@ function merge(target, source) {
55
59
 
56
60
  // src/utils/styles.ts
57
61
  var stichesUtils = {
62
+ // Abbreviated margin properties
58
63
  m: (value) => ({
59
64
  margin: value
60
65
  }),
@@ -78,10 +83,12 @@ var stichesUtils = {
78
83
  marginTop: value,
79
84
  marginBottom: value
80
85
  }),
86
+ // A property for applying width/height together
81
87
  size: (value) => ({
82
88
  width: value,
83
89
  height: value
84
90
  }),
91
+ // Abbreviated padding properties
85
92
  px: (value) => ({
86
93
  paddingLeft: value,
87
94
  paddingRight: value
@@ -146,22 +153,69 @@ var WeaverseItemStore = class {
146
153
  }
147
154
  };
148
155
  var Weaverse = class {
156
+ /**
157
+ * constructor
158
+ * @param appUrl {string} Weaverse base URL that can provide by user/developer. for local development, use localhost:3000
159
+ * @param projectKey {string} Weaverse project key to access project data via API
160
+ * @param projectData {ProjectDataType} Weaverse project data, by default, user can provide project data via React Component.
161
+ * @param mediaBreakPoints {object} Pass down custom media query breakpoints or just use the default.
162
+ * @param isDesignMode {boolean} check whether the sdk is isDesignMode or not
163
+ * @param ssrMode {boolean} Use in element to optionally render special HTML for hydration
164
+ */
149
165
  constructor({ appUrl, projectKey, projectData, mediaBreakPoints, isDesignMode, ssrMode } = {}) {
166
+ /**
167
+ * For storing, registering element React component from Weaverse or created by user/developer
168
+ */
150
169
  this.elementInstances = /* @__PURE__ */ new Map();
170
+ /**
171
+ * list of element/items store to provide data, handle state update, state sharing, etc.
172
+ */
151
173
  this.itemInstances = /* @__PURE__ */ new Map();
174
+ /**
175
+ * Weaverse base URL that can provide by user/developer. for local development, use localhost:3000
176
+ * @type {string}
177
+ */
152
178
  this.appUrl = process.env.NODE_ENV === "development" ? "http://localhost:3000" : "https://studio.weaverse.io";
179
+ /**
180
+ * Weaverse project key to access project data via API
181
+ * @type {string}
182
+ */
153
183
  this.projectKey = "";
184
+ /**
185
+ * Weaverse project data, by default, user can provide project data via React Component:
186
+ * <WeaverseRoot defaultData={projectData} /> it will be used to server-side rendering
187
+ */
154
188
  this.projectData = {
155
189
  rootId: "",
156
190
  items: [],
157
191
  script: { css: "", js: "" }
158
192
  };
193
+ /**
194
+ * Storing subscribe callback function for any component that want to listen to the change of WeaverseRoot
195
+ * @type {Map<string, (data: any) => void>}
196
+ */
159
197
  this.listeners = /* @__PURE__ */ new Set();
198
+ /**
199
+ * Check whether the sdk is in editor or not.
200
+ * If isDesignMode is true, it means the sdk is isDesignMode mode, render the editor UI,
201
+ * else render the preview UI, plain HTML + CSS + React hydrate
202
+ * @type {boolean}
203
+ */
160
204
  this.isDesignMode = false;
205
+ /**
206
+ * Check whether the sdk is in preview mode or not
207
+ * @type {boolean}
208
+ */
161
209
  this.isPreviewMode = false;
210
+ /**
211
+ * Use in element to optionally render special HTML for hydration
212
+ * @type {boolean}
213
+ */
162
214
  this.ssrMode = false;
163
215
  this.mediaBreakPoints = {
164
216
  desktop: "all",
217
+ // max-width need to subtract 0.02px to prevent bug https://getbootstrap.com/docs/5.1/layout/breakpoints/#max-width
218
+ // tablet: "(max-width: 1023.98px)", // to set css for tablet, {'@tablet' : { // css }},
165
219
  mobile: "(max-width: 767.98px)"
166
220
  };
167
221
  this.initStitches = () => {
@@ -183,6 +237,22 @@ var Weaverse = class {
183
237
  this.initStitches();
184
238
  this.initProjectItemData();
185
239
  }
240
+ // initialized = false
241
+ // initializeData = (data: InitializeData) => {
242
+ // if (!this.initialized) {
243
+ // let { data: pageData, published, id, projectKey, studioUrl } = data
244
+ // this.projectKey = projectKey || this.projectKey
245
+ // this.appUrl = studioUrl || this.appUrl
246
+ // this.projectData = { ...pageData, pageId: id }
247
+ // this.isDesignMode = !published
248
+ // this.initProjectItemData()
249
+ // if (this.isDesignMode) {
250
+ // this.triggerUpdate()
251
+ // this.loadStudio()
252
+ // }
253
+ // }
254
+ // this.initialized = true
255
+ // }
186
256
  loadStudio(version) {
187
257
  setTimeout(() => {
188
258
  if (isIframe && this.isDesignMode && !this.studioBridge) {
@@ -202,6 +272,10 @@ var Weaverse = class {
202
272
  }
203
273
  }, 2e3);
204
274
  }
275
+ /**
276
+ * Register the custom React Component to Weaverse, store it into Weaverse.elementInstances
277
+ * @param element {WeaverseElement} custom React Component
278
+ */
205
279
  registerElement(element) {
206
280
  if (element?.type) {
207
281
  if (this.elementInstances.has(element.type)) {
@@ -221,6 +295,12 @@ var Weaverse = class {
221
295
  triggerUpdate() {
222
296
  this.listeners.forEach((fn) => fn());
223
297
  }
298
+ /**
299
+ * Fetch data from Weaverse API (https://weaverse.io/api/v1/project/:projectKey)
300
+ * @param fetch {fetch} custom fetch function, pass in custom fetch function if you want to use your own fetch function
301
+ * @param appUrl
302
+ * @param projectKey
303
+ */
224
304
  static fetchProjectData({
225
305
  fetch = globalThis.fetch,
226
306
  appUrl,
package/dist/index.mjs CHANGED
@@ -18,6 +18,7 @@ function merge(target, source) {
18
18
 
19
19
  // src/utils/styles.ts
20
20
  var stichesUtils = {
21
+ // Abbreviated margin properties
21
22
  m: (value) => ({
22
23
  margin: value
23
24
  }),
@@ -41,10 +42,12 @@ var stichesUtils = {
41
42
  marginTop: value,
42
43
  marginBottom: value
43
44
  }),
45
+ // A property for applying width/height together
44
46
  size: (value) => ({
45
47
  width: value,
46
48
  height: value
47
49
  }),
50
+ // Abbreviated padding properties
48
51
  px: (value) => ({
49
52
  paddingLeft: value,
50
53
  paddingRight: value
@@ -109,22 +112,69 @@ var WeaverseItemStore = class {
109
112
  }
110
113
  };
111
114
  var Weaverse = class {
115
+ /**
116
+ * constructor
117
+ * @param appUrl {string} Weaverse base URL that can provide by user/developer. for local development, use localhost:3000
118
+ * @param projectKey {string} Weaverse project key to access project data via API
119
+ * @param projectData {ProjectDataType} Weaverse project data, by default, user can provide project data via React Component.
120
+ * @param mediaBreakPoints {object} Pass down custom media query breakpoints or just use the default.
121
+ * @param isDesignMode {boolean} check whether the sdk is isDesignMode or not
122
+ * @param ssrMode {boolean} Use in element to optionally render special HTML for hydration
123
+ */
112
124
  constructor({ appUrl, projectKey, projectData, mediaBreakPoints, isDesignMode, ssrMode } = {}) {
125
+ /**
126
+ * For storing, registering element React component from Weaverse or created by user/developer
127
+ */
113
128
  this.elementInstances = /* @__PURE__ */ new Map();
129
+ /**
130
+ * list of element/items store to provide data, handle state update, state sharing, etc.
131
+ */
114
132
  this.itemInstances = /* @__PURE__ */ new Map();
133
+ /**
134
+ * Weaverse base URL that can provide by user/developer. for local development, use localhost:3000
135
+ * @type {string}
136
+ */
115
137
  this.appUrl = process.env.NODE_ENV === "development" ? "http://localhost:3000" : "https://studio.weaverse.io";
138
+ /**
139
+ * Weaverse project key to access project data via API
140
+ * @type {string}
141
+ */
116
142
  this.projectKey = "";
143
+ /**
144
+ * Weaverse project data, by default, user can provide project data via React Component:
145
+ * <WeaverseRoot defaultData={projectData} /> it will be used to server-side rendering
146
+ */
117
147
  this.projectData = {
118
148
  rootId: "",
119
149
  items: [],
120
150
  script: { css: "", js: "" }
121
151
  };
152
+ /**
153
+ * Storing subscribe callback function for any component that want to listen to the change of WeaverseRoot
154
+ * @type {Map<string, (data: any) => void>}
155
+ */
122
156
  this.listeners = /* @__PURE__ */ new Set();
157
+ /**
158
+ * Check whether the sdk is in editor or not.
159
+ * If isDesignMode is true, it means the sdk is isDesignMode mode, render the editor UI,
160
+ * else render the preview UI, plain HTML + CSS + React hydrate
161
+ * @type {boolean}
162
+ */
123
163
  this.isDesignMode = false;
164
+ /**
165
+ * Check whether the sdk is in preview mode or not
166
+ * @type {boolean}
167
+ */
124
168
  this.isPreviewMode = false;
169
+ /**
170
+ * Use in element to optionally render special HTML for hydration
171
+ * @type {boolean}
172
+ */
125
173
  this.ssrMode = false;
126
174
  this.mediaBreakPoints = {
127
175
  desktop: "all",
176
+ // max-width need to subtract 0.02px to prevent bug https://getbootstrap.com/docs/5.1/layout/breakpoints/#max-width
177
+ // tablet: "(max-width: 1023.98px)", // to set css for tablet, {'@tablet' : { // css }},
128
178
  mobile: "(max-width: 767.98px)"
129
179
  };
130
180
  this.initStitches = () => {
@@ -146,6 +196,22 @@ var Weaverse = class {
146
196
  this.initStitches();
147
197
  this.initProjectItemData();
148
198
  }
199
+ // initialized = false
200
+ // initializeData = (data: InitializeData) => {
201
+ // if (!this.initialized) {
202
+ // let { data: pageData, published, id, projectKey, studioUrl } = data
203
+ // this.projectKey = projectKey || this.projectKey
204
+ // this.appUrl = studioUrl || this.appUrl
205
+ // this.projectData = { ...pageData, pageId: id }
206
+ // this.isDesignMode = !published
207
+ // this.initProjectItemData()
208
+ // if (this.isDesignMode) {
209
+ // this.triggerUpdate()
210
+ // this.loadStudio()
211
+ // }
212
+ // }
213
+ // this.initialized = true
214
+ // }
149
215
  loadStudio(version) {
150
216
  setTimeout(() => {
151
217
  if (isIframe && this.isDesignMode && !this.studioBridge) {
@@ -165,6 +231,10 @@ var Weaverse = class {
165
231
  }
166
232
  }, 2e3);
167
233
  }
234
+ /**
235
+ * Register the custom React Component to Weaverse, store it into Weaverse.elementInstances
236
+ * @param element {WeaverseElement} custom React Component
237
+ */
168
238
  registerElement(element) {
169
239
  if (element?.type) {
170
240
  if (this.elementInstances.has(element.type)) {
@@ -184,6 +254,12 @@ var Weaverse = class {
184
254
  triggerUpdate() {
185
255
  this.listeners.forEach((fn) => fn());
186
256
  }
257
+ /**
258
+ * Fetch data from Weaverse API (https://weaverse.io/api/v1/project/:projectKey)
259
+ * @param fetch {fetch} custom fetch function, pass in custom fetch function if you want to use your own fetch function
260
+ * @param appUrl
261
+ * @param projectKey
262
+ */
187
263
  static fetchProjectData({
188
264
  fetch = globalThis.fetch,
189
265
  appUrl,
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "0.7.67",
2
+ "version": "0.7.68",
3
3
  "license": "MIT",
4
4
  "main": "dist/index.js",
5
5
  "typings": "dist/index.d.ts",