@weaverse/core 1.3.2 → 1.4.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/dist/index.d.mts +74 -186
- package/dist/index.d.ts +74 -186
- package/dist/index.js +113 -181
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +113 -180
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
package/dist/index.d.mts
CHANGED
|
@@ -1,6 +1,67 @@
|
|
|
1
|
-
import * as
|
|
1
|
+
import * as stitches from '@stitches/core';
|
|
2
2
|
import { RefObject, ForwardRefExoticComponent } from 'react';
|
|
3
|
-
import Stitches
|
|
3
|
+
import Stitches from '@stitches/core/types/stitches';
|
|
4
|
+
|
|
5
|
+
type AnyFunction = (...args: any[]) => any;
|
|
6
|
+
declare class EventEmitter {
|
|
7
|
+
listeners: Set<AnyFunction>;
|
|
8
|
+
constructor();
|
|
9
|
+
subscribe(fn: AnyFunction): void;
|
|
10
|
+
unsubscribe(fn: AnyFunction): void;
|
|
11
|
+
emit(data?: any): void;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
declare class WeaverseItemStore extends EventEmitter {
|
|
15
|
+
weaverse: Weaverse;
|
|
16
|
+
ref: RefObject<HTMLElement>;
|
|
17
|
+
_store: ElementData;
|
|
18
|
+
stitchesClass: string;
|
|
19
|
+
constructor(intialData: ElementData, weaverse: Weaverse);
|
|
20
|
+
get _id(): string;
|
|
21
|
+
get _element(): HTMLElement | null;
|
|
22
|
+
get Element(): any;
|
|
23
|
+
get css(): ElementCSS;
|
|
24
|
+
get data(): ElementData;
|
|
25
|
+
set data(update: Omit<ElementData, "id" | "type">);
|
|
26
|
+
setData: (update: Omit<ElementData, "id" | "type">) => ElementData;
|
|
27
|
+
triggerUpdate: () => void;
|
|
28
|
+
}
|
|
29
|
+
declare class Weaverse extends EventEmitter {
|
|
30
|
+
contentRootElement: HTMLElement | null;
|
|
31
|
+
itemInstances: Map<any, any>;
|
|
32
|
+
weaverseHost: string;
|
|
33
|
+
weaverseVersion: string;
|
|
34
|
+
projectId: string;
|
|
35
|
+
isDesignMode: boolean;
|
|
36
|
+
isPreviewMode: boolean;
|
|
37
|
+
stitchesInstance: Stitches | any;
|
|
38
|
+
studioBridge?: any;
|
|
39
|
+
ItemConstructor: typeof WeaverseItemStore;
|
|
40
|
+
data: WeaverseProjectDataType;
|
|
41
|
+
platformType: PlatformTypeEnum;
|
|
42
|
+
readonly elementRegistry: Map<any, any>;
|
|
43
|
+
mediaBreakPoints: BreakPoints;
|
|
44
|
+
constructor(params: WeaverseCoreParams);
|
|
45
|
+
/**
|
|
46
|
+
* Create new `WeaverseItemStore` instance for each item in the project.
|
|
47
|
+
*/
|
|
48
|
+
initProject(): void;
|
|
49
|
+
initStitches: (externalConfig?: stitches.CreateStitches) => void;
|
|
50
|
+
/**
|
|
51
|
+
* Register the custom React Component to Weaverse, store it into Weaverse.elementRegistry
|
|
52
|
+
*/
|
|
53
|
+
registerElement(element: {
|
|
54
|
+
type: string;
|
|
55
|
+
}): void;
|
|
56
|
+
triggerUpdate(): void;
|
|
57
|
+
refreshAllItems(): void;
|
|
58
|
+
/**
|
|
59
|
+
* Reset the project data and re-initialize all items.
|
|
60
|
+
* Used when we need to re-render the project with new data (like applying new template)
|
|
61
|
+
* @param data {WeaverseProjectDataType}
|
|
62
|
+
*/
|
|
63
|
+
setProjectData(data: WeaverseProjectDataType): void;
|
|
64
|
+
}
|
|
4
65
|
|
|
5
66
|
declare let stitchesUtils: {
|
|
6
67
|
m: (value: string) => {
|
|
@@ -40,189 +101,40 @@ declare let stitchesUtils: {
|
|
|
40
101
|
};
|
|
41
102
|
};
|
|
42
103
|
|
|
43
|
-
declare class WeaverseItemStore {
|
|
44
|
-
weaverse: Weaverse;
|
|
45
|
-
listeners: Set<(_: ElementData) => void>;
|
|
46
|
-
ref: RefObject<HTMLElement>;
|
|
47
|
-
stitchesClass: string;
|
|
48
|
-
private _store;
|
|
49
|
-
constructor(itemData: ElementData, weaverse: Weaverse);
|
|
50
|
-
get _id(): string;
|
|
51
|
-
get _element(): HTMLElement | null;
|
|
52
|
-
get _flags(): Partial<Record<FlagType, boolean>>;
|
|
53
|
-
get Element(): WeaverseElement | undefined;
|
|
54
|
-
set data(update: Omit<ElementData, "id" | "type">);
|
|
55
|
-
get data(): ElementData;
|
|
56
|
-
setData: (update: Omit<ElementData, "id" | "type">) => ElementData;
|
|
57
|
-
subscribe: (fn: (_: ElementData) => void) => void;
|
|
58
|
-
unsubscribe: (fn: (_: ElementData) => void) => void;
|
|
59
|
-
triggerUpdate: () => void;
|
|
60
|
-
}
|
|
61
|
-
declare class Weaverse {
|
|
62
|
-
/**
|
|
63
|
-
* The `weaverse-content-root` element of Weaverse SDK
|
|
64
|
-
*/
|
|
65
|
-
contentRootElement: HTMLElement | undefined;
|
|
66
|
-
/**
|
|
67
|
-
* For storing, registering element React component from Weaverse or created by user/developer
|
|
68
|
-
*/
|
|
69
|
-
elementInstances: Map<string, WeaverseElement>;
|
|
70
|
-
/**
|
|
71
|
-
* list of element/items store to provide data, handle state update, state sharing, etc.
|
|
72
|
-
*/
|
|
73
|
-
itemInstances: Map<string | number, WeaverseItemStore>;
|
|
74
|
-
/**
|
|
75
|
-
* Weaverse base URL that can provide by user/developer. for local development, use localhost:3000
|
|
76
|
-
*/
|
|
77
|
-
weaverseHost: string;
|
|
78
|
-
/**
|
|
79
|
-
* Weaverse version, it can be used to load the correct version of Weaverse SDK
|
|
80
|
-
*/
|
|
81
|
-
weaverseVersion: string;
|
|
82
|
-
/**
|
|
83
|
-
* Weaverse project key to access project data via API
|
|
84
|
-
*/
|
|
85
|
-
projectId: string;
|
|
86
|
-
pageId: string;
|
|
87
|
-
internal: any;
|
|
88
|
-
requestInfo: any;
|
|
89
|
-
/**
|
|
90
|
-
* Weaverse project data, by default, user can provide project data via React Component:
|
|
91
|
-
* <WeaverseRoot data={data} /> it will be used to server-side rendering
|
|
92
|
-
*/
|
|
93
|
-
data: WeaverseProjectDataType;
|
|
94
|
-
/**
|
|
95
|
-
* Storing subscribe callback function for any component that want to listen to the change of WeaverseRoot
|
|
96
|
-
*/
|
|
97
|
-
listeners: Set<() => void>;
|
|
98
|
-
/**
|
|
99
|
-
* Check whether the sdk is in editor or not.
|
|
100
|
-
* If isDesignMode is true, it means the sdk is isDesignMode mode, render the editor UI,
|
|
101
|
-
* else render the preview UI, plain HTML + CSS + React hydrate
|
|
102
|
-
*/
|
|
103
|
-
isDesignMode: boolean;
|
|
104
|
-
/**
|
|
105
|
-
* Check the platform, shopify-section or react-ssr(hydrogen)
|
|
106
|
-
*/
|
|
107
|
-
platformType: PlatformTypeEnum;
|
|
108
|
-
/**
|
|
109
|
-
* Check whether the sdk is in preview mode or not
|
|
110
|
-
*/
|
|
111
|
-
isPreviewMode: boolean;
|
|
112
|
-
/**
|
|
113
|
-
* Use in element to optionally render special HTML for hydration
|
|
114
|
-
*/
|
|
115
|
-
ssrMode: boolean;
|
|
116
|
-
/**
|
|
117
|
-
* Stitches instance for handling CSS stylesheet, media, theme for Weaverse project
|
|
118
|
-
*/
|
|
119
|
-
stitchesInstance: Stitches$1 | any;
|
|
120
|
-
studioBridge?: any;
|
|
121
|
-
elementSchemas: ElementSchema[];
|
|
122
|
-
static WeaverseItemStore: typeof WeaverseItemStore;
|
|
123
|
-
mediaBreakPoints: BreakPoints;
|
|
124
|
-
constructor(params?: WeaverseType);
|
|
125
|
-
/**
|
|
126
|
-
* Register the custom React Component to Weaverse, store it into Weaverse.elementInstances
|
|
127
|
-
* @param element {WeaverseElement} custom React Component
|
|
128
|
-
*/
|
|
129
|
-
registerElement(element: WeaverseElement): void;
|
|
130
|
-
initStitches: (externalConfig?: {}) => void;
|
|
131
|
-
subscribe(fn: any): void;
|
|
132
|
-
unsubscribe(fn: any): void;
|
|
133
|
-
triggerUpdate(): void;
|
|
134
|
-
refreshAllItems(): void;
|
|
135
|
-
/**
|
|
136
|
-
* When applying new template,
|
|
137
|
-
* we need to reset the project data and re-initialize the project item data
|
|
138
|
-
* @param data {WeaverseProjectDataType}
|
|
139
|
-
*/
|
|
140
|
-
setProjectData(data: WeaverseProjectDataType): void;
|
|
141
|
-
/**
|
|
142
|
-
* Create new WeaverseItemStore instance for each item in project data
|
|
143
|
-
*/
|
|
144
|
-
initProject(): void;
|
|
145
|
-
}
|
|
146
|
-
|
|
147
104
|
interface WeaverseProjectDataType {
|
|
148
105
|
items: ElementData[];
|
|
149
106
|
rootId: string;
|
|
150
|
-
script?: {
|
|
151
|
-
css: string;
|
|
152
|
-
js: string;
|
|
153
|
-
};
|
|
154
|
-
pageId?: string;
|
|
155
107
|
}
|
|
156
108
|
interface BreakPoints {
|
|
157
109
|
mobile: string;
|
|
158
110
|
desktop: string;
|
|
159
111
|
}
|
|
160
112
|
type PlatformTypeEnum = "shopify-section" | "shopify-hydrogen" | "nextjs";
|
|
161
|
-
interface
|
|
113
|
+
interface WeaverseCoreParams {
|
|
162
114
|
mediaBreakPoints?: BreakPoints;
|
|
163
115
|
weaverseHost?: string;
|
|
164
116
|
weaverseVersion?: string;
|
|
165
|
-
projectId
|
|
166
|
-
|
|
167
|
-
data?: WeaverseProjectDataType;
|
|
117
|
+
projectId: string;
|
|
118
|
+
data: WeaverseProjectDataType;
|
|
168
119
|
isDesignMode?: boolean;
|
|
169
|
-
ssrMode?: boolean;
|
|
170
|
-
elementSchemas?: ElementSchema[];
|
|
171
120
|
platformType?: PlatformTypeEnum;
|
|
121
|
+
ItemConstructor: typeof WeaverseItemStore;
|
|
172
122
|
}
|
|
173
123
|
interface WeaverseElement {
|
|
174
124
|
Component: ForwardRefExoticComponent<any>;
|
|
175
125
|
type: string;
|
|
176
|
-
schema?: ElementSchema;
|
|
177
|
-
defaultCss?: ElementCSS;
|
|
178
|
-
permanentCss?: ElementCSS;
|
|
179
|
-
extraData?: ElementExtraData;
|
|
180
|
-
}
|
|
181
|
-
type CatalogGroup = "essential" | "composition" | "shopify";
|
|
182
|
-
interface ElementCatalog {
|
|
183
|
-
name: string;
|
|
184
|
-
icon?: string;
|
|
185
|
-
group?: CatalogGroup;
|
|
186
|
-
data?: ElementDataInCatalog[];
|
|
187
|
-
}
|
|
188
|
-
interface ElementDataInCatalog extends Omit<ElementData, "id"> {
|
|
189
|
-
id: string | number;
|
|
190
126
|
}
|
|
191
|
-
type
|
|
192
|
-
type ElementFlags = Partial<Record<FlagType, boolean>>;
|
|
193
|
-
type ChildElementSelector = string | string[];
|
|
194
|
-
interface ChildElement {
|
|
195
|
-
label: string;
|
|
196
|
-
selector: ChildElementSelector;
|
|
197
|
-
}
|
|
198
|
-
type ParentType = "container" | "layout" | "root" | "product-details" | "product-info" | "slideshow" | "slide";
|
|
199
|
-
type GridSize = {
|
|
200
|
-
rowSpan: number;
|
|
201
|
-
colSpan: number;
|
|
202
|
-
};
|
|
203
|
-
type ToolbarAction = "general-settings" | "settings-level-2" | "text-presets" | "ai-assistant" | "scale-text" | "duplicate" | "delete" | "copy-styles" | "paste-styles" | "move-up" | "move-down" | "next-slide" | "prev-slide" | "change-background" | "toggle-visibility" | "more-actions";
|
|
127
|
+
type ToolbarAction = "general-settings" | "settings-level-2" | "duplicate" | "delete";
|
|
204
128
|
interface ElementSchema {
|
|
205
129
|
title: string;
|
|
206
130
|
type: string;
|
|
207
|
-
parentTypes: ParentType[];
|
|
208
|
-
gridSize?: GridSize;
|
|
209
|
-
inspector?: ElementInspector;
|
|
210
|
-
toolbar?: (ToolbarAction | ToolbarAction[])[];
|
|
211
|
-
childElements?: ChildElement[];
|
|
212
|
-
catalog?: ElementCatalog;
|
|
213
|
-
flags?: ElementFlags;
|
|
214
131
|
}
|
|
215
132
|
interface ElementData {
|
|
216
133
|
id: string;
|
|
217
134
|
type: string;
|
|
218
|
-
childIds?: (string | number)[];
|
|
219
|
-
css?: ElementCSS;
|
|
220
135
|
[key: string]: any;
|
|
221
136
|
}
|
|
222
|
-
|
|
223
|
-
[key: string]: unknown;
|
|
224
|
-
}
|
|
225
|
-
type WeaverseCSSProperties = Stitches.CSS & Partial<Record<keyof typeof stitchesUtils, string | number>>;
|
|
137
|
+
type WeaverseCSSProperties = stitches.CSS & Partial<Record<keyof typeof stitchesUtils, string | number>>;
|
|
226
138
|
type ChildElementCSS = Partial<{
|
|
227
139
|
[selector: string]: WeaverseCSSProperties & ChildElementCSS;
|
|
228
140
|
}>;
|
|
@@ -230,24 +142,10 @@ interface ElementCSS {
|
|
|
230
142
|
"@desktop"?: WeaverseCSSProperties | ChildElementCSS;
|
|
231
143
|
"@mobile"?: WeaverseCSSProperties | ChildElementCSS;
|
|
232
144
|
}
|
|
233
|
-
interface ElementInspector {
|
|
234
|
-
settings?: (AdvancedGroup | BasicGroup)[];
|
|
235
|
-
styles?: (AdvancedGroup | BasicGroup)[];
|
|
236
|
-
}
|
|
237
|
-
interface AdvancedGroup {
|
|
238
|
-
groupType: AdvancedGroupType;
|
|
239
|
-
useData?: boolean;
|
|
240
|
-
}
|
|
241
|
-
interface BasicGroup {
|
|
242
|
-
groupType: "basic";
|
|
243
|
-
groupHeader: string;
|
|
244
|
-
inputs: BasicInput[];
|
|
245
|
-
}
|
|
246
145
|
type AdvancedGroupType = "border" | "alignment" | "background" | "dimensions" | "spacing" | "typography" | "visibility" | "shadows-and-effects" | "layout-background";
|
|
247
146
|
interface BasicInput<ConfigsType = AdditionalInputConfigs> {
|
|
248
147
|
type: InputType;
|
|
249
148
|
label?: string;
|
|
250
|
-
binding?: "style" | "data";
|
|
251
149
|
/**
|
|
252
150
|
* The key of the value of the element data or styles
|
|
253
151
|
* @example
|
|
@@ -274,12 +172,11 @@ interface BasicInput<ConfigsType = AdditionalInputConfigs> {
|
|
|
274
172
|
* `imagesPerRow.gt.1`
|
|
275
173
|
*/
|
|
276
174
|
condition?: string;
|
|
277
|
-
defaultValue?:
|
|
175
|
+
defaultValue?: any;
|
|
278
176
|
placeholder?: string;
|
|
279
177
|
helpText?: string;
|
|
280
|
-
shouldRevalidate?: boolean;
|
|
281
178
|
}
|
|
282
|
-
type AdditionalInputConfigs = SelectInputConfigs | ToggleGroupConfigs | RangeInputConfigs | ChildrenSortInputConfigs
|
|
179
|
+
type AdditionalInputConfigs = SelectInputConfigs | ToggleGroupConfigs | RangeInputConfigs | ChildrenSortInputConfigs;
|
|
283
180
|
interface SelectInputConfigs {
|
|
284
181
|
options?: {
|
|
285
182
|
value: string;
|
|
@@ -306,22 +203,14 @@ type SortableItemAction = "add" | "edit" | "duplicate" | "delete" | "toggle-visi
|
|
|
306
203
|
interface ChildrenSortInputConfigs {
|
|
307
204
|
actions: SortableItemAction[];
|
|
308
205
|
}
|
|
309
|
-
|
|
310
|
-
prop: string;
|
|
311
|
-
defaultData: object;
|
|
312
|
-
inspector: string;
|
|
313
|
-
}
|
|
314
|
-
type InputType = "color" | "datepicker" | "image" | "range" | "select" | "children-sort" | "data-sort" | "switch" | "text" | "textarea" | "toggle-group" | "position" | "information" | "product" | "product-list" | "product-swatches" | "text-editor" | "custom.html" | "instagram" | "collection-list" | "collection" | "article-list" | "map-autocomplete";
|
|
206
|
+
type InputType = "color" | "datepicker" | "image" | "range" | "select" | "children-sort" | "switch" | "text" | "textarea" | "toggle-group" | "position";
|
|
315
207
|
declare global {
|
|
316
208
|
interface Window {
|
|
317
209
|
Blinkloader: any;
|
|
318
210
|
weaverseStudio: any;
|
|
319
|
-
createWeaverseStudioBridge: (weaverse: Weaverse) => void;
|
|
320
211
|
}
|
|
321
212
|
}
|
|
322
213
|
|
|
323
|
-
declare let loadScript: (src: string) => Promise<unknown>;
|
|
324
|
-
|
|
325
214
|
declare let isReactNative: boolean;
|
|
326
215
|
declare let isBrowser: boolean;
|
|
327
216
|
declare let isIframe: boolean;
|
|
@@ -333,7 +222,6 @@ declare let isIframe: boolean;
|
|
|
333
222
|
declare function merge(target: Record<string, any>, source: Record<string, any>): {
|
|
334
223
|
[x: string]: any;
|
|
335
224
|
};
|
|
225
|
+
declare function loadScript(src: string): Promise<unknown>;
|
|
336
226
|
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
export { AdditionalInputConfigs, AdvancedGroup, AdvancedGroupType, BasicGroup, BasicInput, BreakPoints, CatalogGroup, ChildElement, ChildElementCSS, ChildElementSelector, ChildrenSortInputConfigs, DataSortInputConfigs, ElementCSS, ElementCatalog, ElementData, ElementDataInCatalog, ElementExtraData, ElementFlags, ElementInspector, ElementSchema, FlagType, GridSize, InputType, ParentType, PlatformTypeEnum, RangeInputConfigs, SelectInputConfigs, SortableItemAction, ToggleGroupConfigs, ToolbarAction, Weaverse, WeaverseCSSProperties, WeaverseElement, WeaverseItemStore, WeaverseProjectDataType, WeaverseType, getItemDefaultData, isBrowser, isIframe, isReactNative, loadScript, merge };
|
|
227
|
+
export { AdditionalInputConfigs, AdvancedGroupType, BasicInput, BreakPoints, ChildElementCSS, ChildrenSortInputConfigs, ElementCSS, ElementData, ElementSchema, InputType, PlatformTypeEnum, RangeInputConfigs, SelectInputConfigs, SortableItemAction, ToggleGroupConfigs, ToolbarAction, Weaverse, WeaverseCSSProperties, WeaverseCoreParams, WeaverseElement, WeaverseItemStore, WeaverseProjectDataType, isBrowser, isIframe, isReactNative, loadScript, merge };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,67 @@
|
|
|
1
|
-
import * as
|
|
1
|
+
import * as stitches from '@stitches/core';
|
|
2
2
|
import { RefObject, ForwardRefExoticComponent } from 'react';
|
|
3
|
-
import Stitches
|
|
3
|
+
import Stitches from '@stitches/core/types/stitches';
|
|
4
|
+
|
|
5
|
+
type AnyFunction = (...args: any[]) => any;
|
|
6
|
+
declare class EventEmitter {
|
|
7
|
+
listeners: Set<AnyFunction>;
|
|
8
|
+
constructor();
|
|
9
|
+
subscribe(fn: AnyFunction): void;
|
|
10
|
+
unsubscribe(fn: AnyFunction): void;
|
|
11
|
+
emit(data?: any): void;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
declare class WeaverseItemStore extends EventEmitter {
|
|
15
|
+
weaverse: Weaverse;
|
|
16
|
+
ref: RefObject<HTMLElement>;
|
|
17
|
+
_store: ElementData;
|
|
18
|
+
stitchesClass: string;
|
|
19
|
+
constructor(intialData: ElementData, weaverse: Weaverse);
|
|
20
|
+
get _id(): string;
|
|
21
|
+
get _element(): HTMLElement | null;
|
|
22
|
+
get Element(): any;
|
|
23
|
+
get css(): ElementCSS;
|
|
24
|
+
get data(): ElementData;
|
|
25
|
+
set data(update: Omit<ElementData, "id" | "type">);
|
|
26
|
+
setData: (update: Omit<ElementData, "id" | "type">) => ElementData;
|
|
27
|
+
triggerUpdate: () => void;
|
|
28
|
+
}
|
|
29
|
+
declare class Weaverse extends EventEmitter {
|
|
30
|
+
contentRootElement: HTMLElement | null;
|
|
31
|
+
itemInstances: Map<any, any>;
|
|
32
|
+
weaverseHost: string;
|
|
33
|
+
weaverseVersion: string;
|
|
34
|
+
projectId: string;
|
|
35
|
+
isDesignMode: boolean;
|
|
36
|
+
isPreviewMode: boolean;
|
|
37
|
+
stitchesInstance: Stitches | any;
|
|
38
|
+
studioBridge?: any;
|
|
39
|
+
ItemConstructor: typeof WeaverseItemStore;
|
|
40
|
+
data: WeaverseProjectDataType;
|
|
41
|
+
platformType: PlatformTypeEnum;
|
|
42
|
+
readonly elementRegistry: Map<any, any>;
|
|
43
|
+
mediaBreakPoints: BreakPoints;
|
|
44
|
+
constructor(params: WeaverseCoreParams);
|
|
45
|
+
/**
|
|
46
|
+
* Create new `WeaverseItemStore` instance for each item in the project.
|
|
47
|
+
*/
|
|
48
|
+
initProject(): void;
|
|
49
|
+
initStitches: (externalConfig?: stitches.CreateStitches) => void;
|
|
50
|
+
/**
|
|
51
|
+
* Register the custom React Component to Weaverse, store it into Weaverse.elementRegistry
|
|
52
|
+
*/
|
|
53
|
+
registerElement(element: {
|
|
54
|
+
type: string;
|
|
55
|
+
}): void;
|
|
56
|
+
triggerUpdate(): void;
|
|
57
|
+
refreshAllItems(): void;
|
|
58
|
+
/**
|
|
59
|
+
* Reset the project data and re-initialize all items.
|
|
60
|
+
* Used when we need to re-render the project with new data (like applying new template)
|
|
61
|
+
* @param data {WeaverseProjectDataType}
|
|
62
|
+
*/
|
|
63
|
+
setProjectData(data: WeaverseProjectDataType): void;
|
|
64
|
+
}
|
|
4
65
|
|
|
5
66
|
declare let stitchesUtils: {
|
|
6
67
|
m: (value: string) => {
|
|
@@ -40,189 +101,40 @@ declare let stitchesUtils: {
|
|
|
40
101
|
};
|
|
41
102
|
};
|
|
42
103
|
|
|
43
|
-
declare class WeaverseItemStore {
|
|
44
|
-
weaverse: Weaverse;
|
|
45
|
-
listeners: Set<(_: ElementData) => void>;
|
|
46
|
-
ref: RefObject<HTMLElement>;
|
|
47
|
-
stitchesClass: string;
|
|
48
|
-
private _store;
|
|
49
|
-
constructor(itemData: ElementData, weaverse: Weaverse);
|
|
50
|
-
get _id(): string;
|
|
51
|
-
get _element(): HTMLElement | null;
|
|
52
|
-
get _flags(): Partial<Record<FlagType, boolean>>;
|
|
53
|
-
get Element(): WeaverseElement | undefined;
|
|
54
|
-
set data(update: Omit<ElementData, "id" | "type">);
|
|
55
|
-
get data(): ElementData;
|
|
56
|
-
setData: (update: Omit<ElementData, "id" | "type">) => ElementData;
|
|
57
|
-
subscribe: (fn: (_: ElementData) => void) => void;
|
|
58
|
-
unsubscribe: (fn: (_: ElementData) => void) => void;
|
|
59
|
-
triggerUpdate: () => void;
|
|
60
|
-
}
|
|
61
|
-
declare class Weaverse {
|
|
62
|
-
/**
|
|
63
|
-
* The `weaverse-content-root` element of Weaverse SDK
|
|
64
|
-
*/
|
|
65
|
-
contentRootElement: HTMLElement | undefined;
|
|
66
|
-
/**
|
|
67
|
-
* For storing, registering element React component from Weaverse or created by user/developer
|
|
68
|
-
*/
|
|
69
|
-
elementInstances: Map<string, WeaverseElement>;
|
|
70
|
-
/**
|
|
71
|
-
* list of element/items store to provide data, handle state update, state sharing, etc.
|
|
72
|
-
*/
|
|
73
|
-
itemInstances: Map<string | number, WeaverseItemStore>;
|
|
74
|
-
/**
|
|
75
|
-
* Weaverse base URL that can provide by user/developer. for local development, use localhost:3000
|
|
76
|
-
*/
|
|
77
|
-
weaverseHost: string;
|
|
78
|
-
/**
|
|
79
|
-
* Weaverse version, it can be used to load the correct version of Weaverse SDK
|
|
80
|
-
*/
|
|
81
|
-
weaverseVersion: string;
|
|
82
|
-
/**
|
|
83
|
-
* Weaverse project key to access project data via API
|
|
84
|
-
*/
|
|
85
|
-
projectId: string;
|
|
86
|
-
pageId: string;
|
|
87
|
-
internal: any;
|
|
88
|
-
requestInfo: any;
|
|
89
|
-
/**
|
|
90
|
-
* Weaverse project data, by default, user can provide project data via React Component:
|
|
91
|
-
* <WeaverseRoot data={data} /> it will be used to server-side rendering
|
|
92
|
-
*/
|
|
93
|
-
data: WeaverseProjectDataType;
|
|
94
|
-
/**
|
|
95
|
-
* Storing subscribe callback function for any component that want to listen to the change of WeaverseRoot
|
|
96
|
-
*/
|
|
97
|
-
listeners: Set<() => void>;
|
|
98
|
-
/**
|
|
99
|
-
* Check whether the sdk is in editor or not.
|
|
100
|
-
* If isDesignMode is true, it means the sdk is isDesignMode mode, render the editor UI,
|
|
101
|
-
* else render the preview UI, plain HTML + CSS + React hydrate
|
|
102
|
-
*/
|
|
103
|
-
isDesignMode: boolean;
|
|
104
|
-
/**
|
|
105
|
-
* Check the platform, shopify-section or react-ssr(hydrogen)
|
|
106
|
-
*/
|
|
107
|
-
platformType: PlatformTypeEnum;
|
|
108
|
-
/**
|
|
109
|
-
* Check whether the sdk is in preview mode or not
|
|
110
|
-
*/
|
|
111
|
-
isPreviewMode: boolean;
|
|
112
|
-
/**
|
|
113
|
-
* Use in element to optionally render special HTML for hydration
|
|
114
|
-
*/
|
|
115
|
-
ssrMode: boolean;
|
|
116
|
-
/**
|
|
117
|
-
* Stitches instance for handling CSS stylesheet, media, theme for Weaverse project
|
|
118
|
-
*/
|
|
119
|
-
stitchesInstance: Stitches$1 | any;
|
|
120
|
-
studioBridge?: any;
|
|
121
|
-
elementSchemas: ElementSchema[];
|
|
122
|
-
static WeaverseItemStore: typeof WeaverseItemStore;
|
|
123
|
-
mediaBreakPoints: BreakPoints;
|
|
124
|
-
constructor(params?: WeaverseType);
|
|
125
|
-
/**
|
|
126
|
-
* Register the custom React Component to Weaverse, store it into Weaverse.elementInstances
|
|
127
|
-
* @param element {WeaverseElement} custom React Component
|
|
128
|
-
*/
|
|
129
|
-
registerElement(element: WeaverseElement): void;
|
|
130
|
-
initStitches: (externalConfig?: {}) => void;
|
|
131
|
-
subscribe(fn: any): void;
|
|
132
|
-
unsubscribe(fn: any): void;
|
|
133
|
-
triggerUpdate(): void;
|
|
134
|
-
refreshAllItems(): void;
|
|
135
|
-
/**
|
|
136
|
-
* When applying new template,
|
|
137
|
-
* we need to reset the project data and re-initialize the project item data
|
|
138
|
-
* @param data {WeaverseProjectDataType}
|
|
139
|
-
*/
|
|
140
|
-
setProjectData(data: WeaverseProjectDataType): void;
|
|
141
|
-
/**
|
|
142
|
-
* Create new WeaverseItemStore instance for each item in project data
|
|
143
|
-
*/
|
|
144
|
-
initProject(): void;
|
|
145
|
-
}
|
|
146
|
-
|
|
147
104
|
interface WeaverseProjectDataType {
|
|
148
105
|
items: ElementData[];
|
|
149
106
|
rootId: string;
|
|
150
|
-
script?: {
|
|
151
|
-
css: string;
|
|
152
|
-
js: string;
|
|
153
|
-
};
|
|
154
|
-
pageId?: string;
|
|
155
107
|
}
|
|
156
108
|
interface BreakPoints {
|
|
157
109
|
mobile: string;
|
|
158
110
|
desktop: string;
|
|
159
111
|
}
|
|
160
112
|
type PlatformTypeEnum = "shopify-section" | "shopify-hydrogen" | "nextjs";
|
|
161
|
-
interface
|
|
113
|
+
interface WeaverseCoreParams {
|
|
162
114
|
mediaBreakPoints?: BreakPoints;
|
|
163
115
|
weaverseHost?: string;
|
|
164
116
|
weaverseVersion?: string;
|
|
165
|
-
projectId
|
|
166
|
-
|
|
167
|
-
data?: WeaverseProjectDataType;
|
|
117
|
+
projectId: string;
|
|
118
|
+
data: WeaverseProjectDataType;
|
|
168
119
|
isDesignMode?: boolean;
|
|
169
|
-
ssrMode?: boolean;
|
|
170
|
-
elementSchemas?: ElementSchema[];
|
|
171
120
|
platformType?: PlatformTypeEnum;
|
|
121
|
+
ItemConstructor: typeof WeaverseItemStore;
|
|
172
122
|
}
|
|
173
123
|
interface WeaverseElement {
|
|
174
124
|
Component: ForwardRefExoticComponent<any>;
|
|
175
125
|
type: string;
|
|
176
|
-
schema?: ElementSchema;
|
|
177
|
-
defaultCss?: ElementCSS;
|
|
178
|
-
permanentCss?: ElementCSS;
|
|
179
|
-
extraData?: ElementExtraData;
|
|
180
|
-
}
|
|
181
|
-
type CatalogGroup = "essential" | "composition" | "shopify";
|
|
182
|
-
interface ElementCatalog {
|
|
183
|
-
name: string;
|
|
184
|
-
icon?: string;
|
|
185
|
-
group?: CatalogGroup;
|
|
186
|
-
data?: ElementDataInCatalog[];
|
|
187
|
-
}
|
|
188
|
-
interface ElementDataInCatalog extends Omit<ElementData, "id"> {
|
|
189
|
-
id: string | number;
|
|
190
126
|
}
|
|
191
|
-
type
|
|
192
|
-
type ElementFlags = Partial<Record<FlagType, boolean>>;
|
|
193
|
-
type ChildElementSelector = string | string[];
|
|
194
|
-
interface ChildElement {
|
|
195
|
-
label: string;
|
|
196
|
-
selector: ChildElementSelector;
|
|
197
|
-
}
|
|
198
|
-
type ParentType = "container" | "layout" | "root" | "product-details" | "product-info" | "slideshow" | "slide";
|
|
199
|
-
type GridSize = {
|
|
200
|
-
rowSpan: number;
|
|
201
|
-
colSpan: number;
|
|
202
|
-
};
|
|
203
|
-
type ToolbarAction = "general-settings" | "settings-level-2" | "text-presets" | "ai-assistant" | "scale-text" | "duplicate" | "delete" | "copy-styles" | "paste-styles" | "move-up" | "move-down" | "next-slide" | "prev-slide" | "change-background" | "toggle-visibility" | "more-actions";
|
|
127
|
+
type ToolbarAction = "general-settings" | "settings-level-2" | "duplicate" | "delete";
|
|
204
128
|
interface ElementSchema {
|
|
205
129
|
title: string;
|
|
206
130
|
type: string;
|
|
207
|
-
parentTypes: ParentType[];
|
|
208
|
-
gridSize?: GridSize;
|
|
209
|
-
inspector?: ElementInspector;
|
|
210
|
-
toolbar?: (ToolbarAction | ToolbarAction[])[];
|
|
211
|
-
childElements?: ChildElement[];
|
|
212
|
-
catalog?: ElementCatalog;
|
|
213
|
-
flags?: ElementFlags;
|
|
214
131
|
}
|
|
215
132
|
interface ElementData {
|
|
216
133
|
id: string;
|
|
217
134
|
type: string;
|
|
218
|
-
childIds?: (string | number)[];
|
|
219
|
-
css?: ElementCSS;
|
|
220
135
|
[key: string]: any;
|
|
221
136
|
}
|
|
222
|
-
|
|
223
|
-
[key: string]: unknown;
|
|
224
|
-
}
|
|
225
|
-
type WeaverseCSSProperties = Stitches.CSS & Partial<Record<keyof typeof stitchesUtils, string | number>>;
|
|
137
|
+
type WeaverseCSSProperties = stitches.CSS & Partial<Record<keyof typeof stitchesUtils, string | number>>;
|
|
226
138
|
type ChildElementCSS = Partial<{
|
|
227
139
|
[selector: string]: WeaverseCSSProperties & ChildElementCSS;
|
|
228
140
|
}>;
|
|
@@ -230,24 +142,10 @@ interface ElementCSS {
|
|
|
230
142
|
"@desktop"?: WeaverseCSSProperties | ChildElementCSS;
|
|
231
143
|
"@mobile"?: WeaverseCSSProperties | ChildElementCSS;
|
|
232
144
|
}
|
|
233
|
-
interface ElementInspector {
|
|
234
|
-
settings?: (AdvancedGroup | BasicGroup)[];
|
|
235
|
-
styles?: (AdvancedGroup | BasicGroup)[];
|
|
236
|
-
}
|
|
237
|
-
interface AdvancedGroup {
|
|
238
|
-
groupType: AdvancedGroupType;
|
|
239
|
-
useData?: boolean;
|
|
240
|
-
}
|
|
241
|
-
interface BasicGroup {
|
|
242
|
-
groupType: "basic";
|
|
243
|
-
groupHeader: string;
|
|
244
|
-
inputs: BasicInput[];
|
|
245
|
-
}
|
|
246
145
|
type AdvancedGroupType = "border" | "alignment" | "background" | "dimensions" | "spacing" | "typography" | "visibility" | "shadows-and-effects" | "layout-background";
|
|
247
146
|
interface BasicInput<ConfigsType = AdditionalInputConfigs> {
|
|
248
147
|
type: InputType;
|
|
249
148
|
label?: string;
|
|
250
|
-
binding?: "style" | "data";
|
|
251
149
|
/**
|
|
252
150
|
* The key of the value of the element data or styles
|
|
253
151
|
* @example
|
|
@@ -274,12 +172,11 @@ interface BasicInput<ConfigsType = AdditionalInputConfigs> {
|
|
|
274
172
|
* `imagesPerRow.gt.1`
|
|
275
173
|
*/
|
|
276
174
|
condition?: string;
|
|
277
|
-
defaultValue?:
|
|
175
|
+
defaultValue?: any;
|
|
278
176
|
placeholder?: string;
|
|
279
177
|
helpText?: string;
|
|
280
|
-
shouldRevalidate?: boolean;
|
|
281
178
|
}
|
|
282
|
-
type AdditionalInputConfigs = SelectInputConfigs | ToggleGroupConfigs | RangeInputConfigs | ChildrenSortInputConfigs
|
|
179
|
+
type AdditionalInputConfigs = SelectInputConfigs | ToggleGroupConfigs | RangeInputConfigs | ChildrenSortInputConfigs;
|
|
283
180
|
interface SelectInputConfigs {
|
|
284
181
|
options?: {
|
|
285
182
|
value: string;
|
|
@@ -306,22 +203,14 @@ type SortableItemAction = "add" | "edit" | "duplicate" | "delete" | "toggle-visi
|
|
|
306
203
|
interface ChildrenSortInputConfigs {
|
|
307
204
|
actions: SortableItemAction[];
|
|
308
205
|
}
|
|
309
|
-
|
|
310
|
-
prop: string;
|
|
311
|
-
defaultData: object;
|
|
312
|
-
inspector: string;
|
|
313
|
-
}
|
|
314
|
-
type InputType = "color" | "datepicker" | "image" | "range" | "select" | "children-sort" | "data-sort" | "switch" | "text" | "textarea" | "toggle-group" | "position" | "information" | "product" | "product-list" | "product-swatches" | "text-editor" | "custom.html" | "instagram" | "collection-list" | "collection" | "article-list" | "map-autocomplete";
|
|
206
|
+
type InputType = "color" | "datepicker" | "image" | "range" | "select" | "children-sort" | "switch" | "text" | "textarea" | "toggle-group" | "position";
|
|
315
207
|
declare global {
|
|
316
208
|
interface Window {
|
|
317
209
|
Blinkloader: any;
|
|
318
210
|
weaverseStudio: any;
|
|
319
|
-
createWeaverseStudioBridge: (weaverse: Weaverse) => void;
|
|
320
211
|
}
|
|
321
212
|
}
|
|
322
213
|
|
|
323
|
-
declare let loadScript: (src: string) => Promise<unknown>;
|
|
324
|
-
|
|
325
214
|
declare let isReactNative: boolean;
|
|
326
215
|
declare let isBrowser: boolean;
|
|
327
216
|
declare let isIframe: boolean;
|
|
@@ -333,7 +222,6 @@ declare let isIframe: boolean;
|
|
|
333
222
|
declare function merge(target: Record<string, any>, source: Record<string, any>): {
|
|
334
223
|
[x: string]: any;
|
|
335
224
|
};
|
|
225
|
+
declare function loadScript(src: string): Promise<unknown>;
|
|
336
226
|
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
export { AdditionalInputConfigs, AdvancedGroup, AdvancedGroupType, BasicGroup, BasicInput, BreakPoints, CatalogGroup, ChildElement, ChildElementCSS, ChildElementSelector, ChildrenSortInputConfigs, DataSortInputConfigs, ElementCSS, ElementCatalog, ElementData, ElementDataInCatalog, ElementExtraData, ElementFlags, ElementInspector, ElementSchema, FlagType, GridSize, InputType, ParentType, PlatformTypeEnum, RangeInputConfigs, SelectInputConfigs, SortableItemAction, ToggleGroupConfigs, ToolbarAction, Weaverse, WeaverseCSSProperties, WeaverseElement, WeaverseItemStore, WeaverseProjectDataType, WeaverseType, getItemDefaultData, isBrowser, isIframe, isReactNative, loadScript, merge };
|
|
227
|
+
export { AdditionalInputConfigs, AdvancedGroupType, BasicInput, BreakPoints, ChildElementCSS, ChildrenSortInputConfigs, ElementCSS, ElementData, ElementSchema, InputType, PlatformTypeEnum, RangeInputConfigs, SelectInputConfigs, SortableItemAction, ToggleGroupConfigs, ToolbarAction, Weaverse, WeaverseCSSProperties, WeaverseCoreParams, WeaverseElement, WeaverseItemStore, WeaverseProjectDataType, isBrowser, isIframe, isReactNative, loadScript, merge };
|