@weaverse/core 0.7.48 → 0.7.50

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.
Files changed (2) hide show
  1. package/dist/index.d.ts +349 -0
  2. package/package.json +1 -1
@@ -0,0 +1,349 @@
1
+ import * as Stitches from '@stitches/core';
2
+ import { ForwardRefExoticComponent, RefObject } from 'react';
3
+ import Stitches$1 from '@stitches/core/types/stitches';
4
+
5
+ declare let stichesUtils: {
6
+ m: (value: string) => {
7
+ margin: string;
8
+ };
9
+ mt: (value: string) => {
10
+ marginTop: string;
11
+ };
12
+ mr: (value: string) => {
13
+ marginRight: string;
14
+ };
15
+ mb: (value: string) => {
16
+ marginBottom: string;
17
+ };
18
+ ml: (value: string) => {
19
+ marginLeft: string;
20
+ };
21
+ mx: (value: string) => {
22
+ marginLeft: string;
23
+ marginRight: string;
24
+ };
25
+ my: (value: string) => {
26
+ marginTop: string;
27
+ marginBottom: string;
28
+ };
29
+ size: (value: string) => {
30
+ width: string;
31
+ height: string;
32
+ };
33
+ px: (value: string) => {
34
+ paddingLeft: string;
35
+ paddingRight: string;
36
+ };
37
+ py: (value: string) => {
38
+ paddingTop: string;
39
+ paddingBottom: string;
40
+ };
41
+ };
42
+ declare function createGlobalStyles(stitches: Stitches$1): void;
43
+
44
+ declare const isReactNative: boolean;
45
+ declare const isBrowser: boolean;
46
+ declare const isIframe: boolean;
47
+ /**
48
+ * Deep merge two objects.
49
+ * @param target
50
+ * @param source
51
+ */
52
+ declare function merge(target: Record<string, any>, source: Record<string, any>): {
53
+ [x: string]: any;
54
+ };
55
+
56
+ interface ProjectDataType {
57
+ items: ElementData[];
58
+ rootId: string;
59
+ script: {
60
+ css: string;
61
+ js: string;
62
+ };
63
+ pageId?: string;
64
+ }
65
+ interface InitializeData {
66
+ id: string;
67
+ handle: string;
68
+ data: ProjectDataType;
69
+ published: boolean;
70
+ projectKey?: string;
71
+ studioUrl?: string;
72
+ }
73
+ interface BreakPoints {
74
+ mobile: string;
75
+ desktop: string;
76
+ }
77
+ interface WeaverseType {
78
+ mediaBreakPoints?: BreakPoints;
79
+ appUrl?: string;
80
+ projectKey?: string;
81
+ projectData?: ProjectDataType;
82
+ isDesignMode?: boolean;
83
+ ssrMode?: boolean;
84
+ }
85
+ interface WeaverseElement {
86
+ Component: ForwardRefExoticComponent<any>;
87
+ type: string;
88
+ schema?: ElementSchema;
89
+ defaultCss?: ElementCSS;
90
+ permanentCss?: ElementCSS;
91
+ }
92
+ type CatalogGroup = "essential" | "composition" | "shopify";
93
+ interface ElementCatalog {
94
+ name: string;
95
+ icon?: string;
96
+ group?: CatalogGroup;
97
+ data?: ElementDataInCatalog[];
98
+ }
99
+ interface ElementDataInCatalog extends Omit<ElementData, "id"> {
100
+ id: string | number;
101
+ }
102
+ type FlagType = "draggable" | "resizable" | "sortable" | "ignoreShortcutKeys" | "hasContextMenu" | "isSortableContext";
103
+ type ElementFlags = Partial<Record<FlagType, boolean>>;
104
+ type ChildElementSelector = string | string[];
105
+ interface ChildElement {
106
+ label: string;
107
+ selector: ChildElementSelector;
108
+ }
109
+ type ParentType = "container" | "layout" | "root" | "product-details" | "product-info" | "collection.box" | "collection-box" | "article-box" | "article-list" | "slider" | "tab" | "accordion" | "accordion.wrapper";
110
+ type GridSize = {
111
+ rowSpan: number;
112
+ colSpan: number;
113
+ };
114
+ type ToolbarAction = "general-settings" | "edit-text" | "duplicate" | "delete" | "copy-styles" | "paste-styles" | "move-up" | "move-down" | "toggle-visibility";
115
+ interface ElementSchema {
116
+ title: string;
117
+ type: string;
118
+ parentTypes: ParentType[];
119
+ gridSize?: GridSize;
120
+ inspector?: ElementInspector;
121
+ toolbar?: (ToolbarAction | ToolbarAction[])[];
122
+ childElements?: ChildElement[];
123
+ catalog?: ElementCatalog;
124
+ flags?: ElementFlags;
125
+ }
126
+ interface ElementData {
127
+ id: string;
128
+ type: string;
129
+ childIds?: (string | number)[];
130
+ css?: ElementCSS;
131
+ [key: string]: any;
132
+ }
133
+ type WeaverseCSSProperties = Stitches.CSS & Partial<Record<keyof typeof stichesUtils, string | number>>;
134
+ type ChildElementCSS = Partial<{
135
+ [selector: string]: WeaverseCSSProperties & ChildElementCSS;
136
+ }>;
137
+ interface ElementCSS {
138
+ "@desktop"?: WeaverseCSSProperties | ChildElementCSS;
139
+ "@mobile"?: WeaverseCSSProperties | ChildElementCSS;
140
+ }
141
+ interface ElementInspector {
142
+ settings?: (AdvancedGroup | BasicGroup)[];
143
+ styles?: (AdvancedGroup | BasicGroup)[];
144
+ }
145
+ interface AdvancedGroup {
146
+ groupType: AdvancedGroupType;
147
+ useData?: boolean;
148
+ }
149
+ interface BasicGroup {
150
+ groupType: "basic";
151
+ groupHeader: string;
152
+ inputs: BasicInput[];
153
+ }
154
+ type AdvancedGroupType = "border" | "alignment" | "background" | "dimensions" | "spacing" | "typography" | "visibility" | "shadows-and-effects" | "layout-background";
155
+ interface BasicInput<ConfigsType = AdditionalInputConfigs> {
156
+ type: InputType;
157
+ label?: string;
158
+ binding?: "style" | "data";
159
+ /**
160
+ * The key of the value of the element data or styles
161
+ * @example
162
+ * // Bind to `element.data.title`
163
+ * name: "title"
164
+ * // Bind to `element.css["@desktop"].backgroundColor`
165
+ * name: "backgroundColor"
166
+ */
167
+ name?: string;
168
+ /**
169
+ * Additional options for inputs that require more configuration
170
+ */
171
+ configs?: ConfigsType;
172
+ /**
173
+ * Only display if condition matches.
174
+ *
175
+ * Format: `dataBindingKey.conditionalOperator.value`
176
+ *
177
+ * Supported operators: `eq`, `ne`, `gt`, `gte`, `lt`, `lte`
178
+ *
179
+ * @example
180
+ * `clickAction.eq.openLink`
181
+ * `clickAction.ne.openLink`
182
+ * `imagesPerRow.gt.1`
183
+ */
184
+ condition?: string;
185
+ defaultValue?: string | number | boolean;
186
+ placeholder?: string;
187
+ helpText?: string;
188
+ }
189
+ type AdditionalInputConfigs = SelectInputConfigs | ToggleGroupConfigs | RangeInputConfigs | SortableInputConfigs | PositionInputConfigs;
190
+ interface SelectInputConfigs {
191
+ options?: {
192
+ value: string;
193
+ label: string;
194
+ icon?: string;
195
+ weight?: string;
196
+ }[];
197
+ }
198
+ interface PositionInputConfigs {
199
+ positionValues: string[];
200
+ }
201
+ interface ToggleGroupConfigs {
202
+ options?: {
203
+ value: string;
204
+ label: string;
205
+ icon?: string;
206
+ weight?: string;
207
+ }[];
208
+ }
209
+ interface RangeInputConfigs {
210
+ min?: number;
211
+ max?: number;
212
+ step?: number;
213
+ }
214
+ type SortableItemAction = "add" | "edit" | "duplicate" | "delete" | "toggle-visibility";
215
+ interface SortableInputConfigs {
216
+ actions: SortableItemAction[];
217
+ }
218
+ type InputType = "color" | "datepicker" | "image" | "range" | "select" | "sortable" | "switch" | "text" | "textarea" | "toggle-group" | "position" | "form" | "product" | "product-list" | "product-swatches" | "text-editor" | "custom.html" | "instagram" | "collection-list" | "collection" | "article-list" | "map-autocomplete";
219
+ declare global {
220
+ interface Window {
221
+ WeaverseStudioBridge: any;
222
+ Blinkloader: any;
223
+ }
224
+ }
225
+
226
+ /**
227
+ * WeaverseItemStore is a store for Weaverse item, it can be used to subscribe/update the item data
228
+ * @param itemData {ElementData} Weaverse item data
229
+ * @param weaverse {Weaverse} Weaverse instance
230
+ * @example
231
+ * useEffect(() => {
232
+ * let handleUpdate = (update: any) => {
233
+ * setData({...update})
234
+ * }
235
+ * itemInstance.subscribe(handleUpdate)
236
+ * return () => {
237
+ * itemInstance.unsubscribe(handleUpdate)
238
+ * }
239
+ * }, [])
240
+ */
241
+ declare class WeaverseItemStore {
242
+ listeners: Set<any>;
243
+ ref: RefObject<HTMLElement>;
244
+ weaverse: Weaverse;
245
+ stitchesClass: string;
246
+ _data: ElementData;
247
+ _flags: ElementFlags;
248
+ constructor(itemData: ElementData, weaverse: Weaverse);
249
+ get _id(): string;
250
+ get _element(): HTMLElement | null;
251
+ get Element(): WeaverseElement | undefined;
252
+ set data(data: Omit<ElementData, "id" | "type">);
253
+ get data(): ElementData;
254
+ setData: (data: Omit<ElementData, "id" | "type">) => ElementData;
255
+ subscribe: (fn: any) => void;
256
+ unsubscribe: (fn: any) => void;
257
+ triggerUpdate: () => void;
258
+ }
259
+ declare class Weaverse {
260
+ /**
261
+ * The `weaverse-content-root` element of Weaverse SDK
262
+ */
263
+ contentRootElement: HTMLElement | undefined;
264
+ /**
265
+ * For storing, registering element React component from Weaverse or created by user/developer
266
+ */
267
+ elementInstances: Map<string, WeaverseElement>;
268
+ /**
269
+ * list of element/items store to provide data, handle state update, state sharing, etc.
270
+ */
271
+ itemInstances: Map<string | number, WeaverseItemStore>;
272
+ /**
273
+ * Weaverse base URL that can provide by user/developer. for local development, use localhost:3000
274
+ * @type {string}
275
+ */
276
+ appUrl: string;
277
+ /**
278
+ * Weaverse project key to access project data via API
279
+ * @type {string}
280
+ */
281
+ projectKey: string;
282
+ /**
283
+ * Weaverse project data, by default, user can provide project data via React Component:
284
+ * <WeaverseRoot defaultData={projectData} /> it will be used to server-side rendering
285
+ */
286
+ projectData: ProjectDataType;
287
+ /**
288
+ * storing subscribe callback function for any component that want to listen to the change of WeaverseRoot
289
+ * @type {Map<string, (data: any) => void>}
290
+ */
291
+ listeners: Set<any>;
292
+ /**
293
+ * check whether the sdk is isDesignMode or not
294
+ * if isDesignMode is true, it means the sdk is isDesignMode mode, render the editor UI
295
+ * else render the preview UI, plain HTML + CSS + React hydrate
296
+ * @type {boolean}
297
+ */
298
+ isDesignMode: boolean;
299
+ /**
300
+ * Use in element to optionally render special HTML for hydration
301
+ * @type {boolean}
302
+ */
303
+ ssrMode: boolean;
304
+ /**
305
+ * stitches instance for handling CSS stylesheet, media, theme for Weaverse project
306
+ */
307
+ stitchesInstance: Stitches$1 | any;
308
+ studioBridge?: any;
309
+ static WeaverseItemStore: typeof WeaverseItemStore;
310
+ mediaBreakPoints: BreakPoints;
311
+ /**
312
+ * constructor
313
+ * @param appUrl {string} Weaverse base URL that can provide by user/developer. for local development, use localhost:3000
314
+ * @param projectKey {string} Weaverse project key to access project data via API
315
+ * @param projectData {ProjectDataType} Weaverse project data, by default, user can provide project data via React Component.
316
+ * @param mediaBreakPoints {object} Pass down custom media query breakpoints or just use the default.
317
+ * @param isDesignMode {boolean} check whether the sdk is isDesignMode or not
318
+ * @param ssrMode {boolean} Use in element to optionally render special HTML for hydration
319
+ */
320
+ constructor({ appUrl, projectKey, projectData, mediaBreakPoints, isDesignMode, ssrMode }?: WeaverseType);
321
+ init({ appUrl, projectKey, projectData, mediaBreakPoints, isDesignMode, ssrMode }?: WeaverseType): void;
322
+ initialized: boolean;
323
+ initializeData: (data: InitializeData) => void;
324
+ loadStudio(): void;
325
+ /**
326
+ * register the custom React Component to Weaverse, store it into Weaverse.elementInstances
327
+ * @param element {WeaverseElement} custom React Component
328
+ */
329
+ registerElement(element: WeaverseElement): void;
330
+ initStitches: () => void;
331
+ subscribe(fn: any): void;
332
+ unsubscribe(fn: any): void;
333
+ triggerUpdate(): void;
334
+ /**
335
+ * fetch data from Weaverse API (https://weaverse.io/api/v1/project/:projectKey)
336
+ * @param fetch {fetch} custom fetch function, pass in custom fetch function if you want to use your own fetch function
337
+ * @param appUrl
338
+ * @param projectKey
339
+ */
340
+ static fetchProjectData({ fetch, appUrl, projectKey, }: {
341
+ fetch?: any;
342
+ appUrl?: string;
343
+ projectKey?: string;
344
+ }): any;
345
+ setProjectData(projectData: ProjectDataType): void;
346
+ initProjectItemData(): void;
347
+ }
348
+
349
+ export { AdditionalInputConfigs, AdvancedGroup, AdvancedGroupType, BasicGroup, BasicInput, BreakPoints, CatalogGroup, ChildElement, ChildElementCSS, ChildElementSelector, ElementCSS, ElementCatalog, ElementData, ElementDataInCatalog, ElementFlags, ElementInspector, ElementSchema, FlagType, GridSize, InitializeData, InputType, ParentType, PositionInputConfigs, ProjectDataType, RangeInputConfigs, SelectInputConfigs, SortableInputConfigs, SortableItemAction, ToggleGroupConfigs, ToolbarAction, Weaverse, WeaverseCSSProperties, WeaverseElement, WeaverseItemStore, WeaverseType, createGlobalStyles, isBrowser, isIframe, isReactNative, merge, stichesUtils };
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "0.7.48",
2
+ "version": "0.7.50",
3
3
  "license": "MIT",
4
4
  "main": "dist/index.js",
5
5
  "typings": "dist/index.d.ts",