@weaverse/core 1.0.52 → 1.0.53

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.mts +350 -0
  2. package/package.json +1 -1
@@ -0,0 +1,350 @@
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 stitchesUtils: {
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
+
43
+ interface WeaverseProjectDataType {
44
+ items: ElementData[];
45
+ rootId: string;
46
+ script?: {
47
+ css: string;
48
+ js: string;
49
+ };
50
+ pageId?: string;
51
+ }
52
+ interface BreakPoints {
53
+ mobile: string;
54
+ desktop: string;
55
+ }
56
+ type PlatformTypeEnum = "shopify-section" | "shopify-hydrogen" | "nextjs";
57
+ interface WeaverseType {
58
+ mediaBreakPoints?: BreakPoints;
59
+ weaverseHost?: string;
60
+ weaverseVersion?: string;
61
+ projectId?: string;
62
+ pageId?: string;
63
+ data?: WeaverseProjectDataType;
64
+ isDesignMode?: boolean;
65
+ ssrMode?: boolean;
66
+ elementSchemas?: ElementSchema[];
67
+ platformType?: PlatformTypeEnum;
68
+ }
69
+ interface WeaverseElement {
70
+ Component: ForwardRefExoticComponent<any>;
71
+ type: string;
72
+ schema?: ElementSchema;
73
+ defaultCss?: ElementCSS;
74
+ permanentCss?: ElementCSS;
75
+ extraData?: ElementExtraData;
76
+ }
77
+ type CatalogGroup = "essential" | "composition" | "shopify";
78
+ interface ElementCatalog {
79
+ name: string;
80
+ icon?: string;
81
+ group?: CatalogGroup;
82
+ data?: ElementDataInCatalog[];
83
+ }
84
+ interface ElementDataInCatalog extends Omit<ElementData, "id"> {
85
+ id: string | number;
86
+ }
87
+ type FlagType = "draggable" | "resizable" | "sortable" | "ignoreShortcutKeys" | "hasContextMenu" | "isSortableContext" | "mustHaveChildren";
88
+ type ElementFlags = Partial<Record<FlagType, boolean>>;
89
+ type ChildElementSelector = string | string[];
90
+ interface ChildElement {
91
+ label: string;
92
+ selector: ChildElementSelector;
93
+ }
94
+ type ParentType = "container" | "layout" | "root" | "product-details" | "product-info" | "slideshow" | "slide";
95
+ type GridSize = {
96
+ rowSpan: number;
97
+ colSpan: number;
98
+ };
99
+ 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";
100
+ interface ElementSchema {
101
+ title: string;
102
+ type: string;
103
+ parentTypes: ParentType[];
104
+ gridSize?: GridSize;
105
+ inspector?: ElementInspector;
106
+ toolbar?: (ToolbarAction | ToolbarAction[])[];
107
+ childElements?: ChildElement[];
108
+ catalog?: ElementCatalog;
109
+ flags?: ElementFlags;
110
+ }
111
+ interface ElementData {
112
+ id: string;
113
+ type: string;
114
+ childIds?: (string | number)[];
115
+ css?: ElementCSS;
116
+ [key: string]: any;
117
+ }
118
+ interface ElementExtraData {
119
+ [key: string]: unknown;
120
+ }
121
+ type WeaverseCSSProperties = Stitches.CSS & Partial<Record<keyof typeof stitchesUtils, string | number>>;
122
+ type ChildElementCSS = Partial<{
123
+ [selector: string]: WeaverseCSSProperties & ChildElementCSS;
124
+ }>;
125
+ interface ElementCSS {
126
+ "@desktop"?: WeaverseCSSProperties | ChildElementCSS;
127
+ "@mobile"?: WeaverseCSSProperties | ChildElementCSS;
128
+ }
129
+ interface ElementInspector {
130
+ settings?: (AdvancedGroup | BasicGroup)[];
131
+ styles?: (AdvancedGroup | BasicGroup)[];
132
+ }
133
+ interface AdvancedGroup {
134
+ groupType: AdvancedGroupType;
135
+ useData?: boolean;
136
+ }
137
+ interface BasicGroup {
138
+ groupType: "basic";
139
+ groupHeader: string;
140
+ inputs: BasicInput[];
141
+ }
142
+ type AdvancedGroupType = "border" | "alignment" | "background" | "dimensions" | "spacing" | "typography" | "visibility" | "shadows-and-effects" | "layout-background";
143
+ interface BasicInput<ConfigsType = AdditionalInputConfigs> {
144
+ type: InputType;
145
+ label?: string;
146
+ binding?: "style" | "data";
147
+ /**
148
+ * The key of the value of the element data or styles
149
+ * @example
150
+ * // Bind to `element.data.title`
151
+ * name: "title"
152
+ * // Bind to `element.css["@desktop"].backgroundColor`
153
+ * name: "backgroundColor"
154
+ */
155
+ name?: string;
156
+ /**
157
+ * Additional options for inputs that require more configuration
158
+ */
159
+ configs?: ConfigsType;
160
+ /**
161
+ * Only display if condition matches.
162
+ *
163
+ * Format: `dataBindingKey.conditionalOperator.value`
164
+ *
165
+ * Supported operators: `eq`, `ne`, `gt`, `gte`, `lt`, `lte`
166
+ *
167
+ * @example
168
+ * `clickAction.eq.openLink`
169
+ * `clickAction.ne.openLink`
170
+ * `imagesPerRow.gt.1`
171
+ */
172
+ condition?: string;
173
+ defaultValue: string | number | boolean;
174
+ placeholder?: string;
175
+ helpText?: string;
176
+ }
177
+ type AdditionalInputConfigs = SelectInputConfigs | ToggleGroupConfigs | RangeInputConfigs | ChildrenSortInputConfigs | DataSortInputConfigs;
178
+ interface SelectInputConfigs {
179
+ options?: {
180
+ value: string;
181
+ label: string;
182
+ icon?: string;
183
+ weight?: string;
184
+ }[];
185
+ }
186
+ interface ToggleGroupConfigs {
187
+ options?: {
188
+ value: string;
189
+ label: string;
190
+ icon?: string;
191
+ weight?: string;
192
+ }[];
193
+ }
194
+ interface RangeInputConfigs {
195
+ min?: number;
196
+ max?: number;
197
+ step?: number;
198
+ unit?: string;
199
+ }
200
+ type SortableItemAction = "add" | "edit" | "duplicate" | "delete" | "toggle-visibility";
201
+ interface ChildrenSortInputConfigs {
202
+ actions: SortableItemAction[];
203
+ }
204
+ interface DataSortInputConfigs {
205
+ prop: string;
206
+ defaultData: object;
207
+ inspector: string;
208
+ }
209
+ 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";
210
+ declare global {
211
+ interface Window {
212
+ weaverseStudioInitialized: boolean;
213
+ Blinkloader: any;
214
+ __weaverse: any;
215
+ __weaverses: {
216
+ [key: string]: any;
217
+ };
218
+ createWeaverseStudioBridge: (weaverse: any) => Promise<any>;
219
+ }
220
+ }
221
+
222
+ declare class WeaverseItemStore {
223
+ weaverse: Weaverse;
224
+ listeners: Set<(_: ElementData) => void>;
225
+ ref: RefObject<HTMLElement>;
226
+ stitchesClass: string;
227
+ private _store;
228
+ constructor(itemData: ElementData, weaverse: Weaverse);
229
+ get _id(): string;
230
+ get _element(): HTMLElement | null;
231
+ get _flags(): Partial<Record<FlagType, boolean>>;
232
+ get Element(): WeaverseElement | undefined;
233
+ set data(update: Omit<ElementData, "id" | "type">);
234
+ get data(): ElementData;
235
+ setData: (update: Omit<ElementData, "id" | "type">) => ElementData;
236
+ subscribe: (fn: (_: ElementData) => void) => void;
237
+ unsubscribe: (fn: (_: ElementData) => void) => void;
238
+ triggerUpdate: () => void;
239
+ }
240
+ declare class Weaverse {
241
+ /**
242
+ * The `weaverse-content-root` element of Weaverse SDK
243
+ */
244
+ contentRootElement: HTMLElement | undefined;
245
+ /**
246
+ * For storing, registering element React component from Weaverse or created by user/developer
247
+ */
248
+ elementInstances: Map<string, WeaverseElement>;
249
+ /**
250
+ * list of element/items store to provide data, handle state update, state sharing, etc.
251
+ */
252
+ itemInstances: Map<string | number, WeaverseItemStore>;
253
+ /**
254
+ * Weaverse base URL that can provide by user/developer. for local development, use localhost:3000
255
+ */
256
+ weaverseHost: string;
257
+ /**
258
+ * Weaverse version, it can be used to load the correct version of Weaverse SDK
259
+ */
260
+ weaverseVersion: string;
261
+ /**
262
+ * Weaverse project key to access project data via API
263
+ */
264
+ projectId: string;
265
+ pageId: string;
266
+ internal: any;
267
+ /**
268
+ * Weaverse project data, by default, user can provide project data via React Component:
269
+ * <WeaverseRoot data={data} /> it will be used to server-side rendering
270
+ */
271
+ data: WeaverseProjectDataType;
272
+ /**
273
+ * Storing subscribe callback function for any component that want to listen to the change of WeaverseRoot
274
+ */
275
+ listeners: Set<() => void>;
276
+ /**
277
+ * Check whether the sdk is in editor or not.
278
+ * If isDesignMode is true, it means the sdk is isDesignMode mode, render the editor UI,
279
+ * else render the preview UI, plain HTML + CSS + React hydrate
280
+ */
281
+ isDesignMode: boolean;
282
+ /**
283
+ * Check the platform, shopify-section or react-ssr(hydrogen)
284
+ */
285
+ platformType: PlatformTypeEnum;
286
+ /**
287
+ * Check whether the sdk is in preview mode or not
288
+ */
289
+ isPreviewMode: boolean;
290
+ /**
291
+ * Use in element to optionally render special HTML for hydration
292
+ */
293
+ ssrMode: boolean;
294
+ /**
295
+ * Stitches instance for handling CSS stylesheet, media, theme for Weaverse project
296
+ */
297
+ stitchesInstance: Stitches$1 | any;
298
+ studioBridge?: any;
299
+ elementSchemas: ElementSchema[];
300
+ static WeaverseItemStore: typeof WeaverseItemStore;
301
+ mediaBreakPoints: BreakPoints;
302
+ /**
303
+ * constructor
304
+ * @param weaverseHost {string} Weaverse base URL that can provide by user/developer. for local development, use localhost:3000
305
+ * @param projectId {string} Weaverse project key to access project data via API
306
+ * @param data {WeaverseProjectDataType} Weaverse project data, by default, user can provide project data via React Component.
307
+ * @param mediaBreakPoints {object} Pass down custom media query breakpoints or just use the default.
308
+ * @param isDesignMode {boolean} check whether the sdk is isDesignMode or not
309
+ * @param ssrMode {boolean} Use in element to optionally render special HTML for hydration
310
+ * @param elementSchemas {Array<ElementSchema>} List of element schemas
311
+ * @param platformType {PlatformTypeEnum} Check the platform, shopify-section or react-ssr(hydrogen)
312
+ */
313
+ constructor(params?: WeaverseType);
314
+ /**
315
+ * Register the custom React Component to Weaverse, store it into Weaverse.elementInstances
316
+ * @param element {WeaverseElement} custom React Component
317
+ */
318
+ registerElement(element: WeaverseElement): void;
319
+ initStitches: (externalConfig?: {}) => void;
320
+ subscribe(fn: any): void;
321
+ unsubscribe(fn: any): void;
322
+ triggerUpdate(): void;
323
+ refreshAllItems(): void;
324
+ /**
325
+ * When applying new template,
326
+ * we need to reset the project data and re-initialize the project item data
327
+ * @param data {WeaverseProjectDataType}
328
+ */
329
+ setProjectData(data: WeaverseProjectDataType): void;
330
+ /**
331
+ * Create new WeaverseItemStore instance for each item in project data
332
+ */
333
+ initProject(): void;
334
+ }
335
+
336
+ declare let loadScript: (src: string) => Promise<unknown>;
337
+
338
+ declare let isReactNative: boolean;
339
+ declare let isBrowser: boolean;
340
+ declare let isIframe: boolean;
341
+ /**
342
+ * Deep merge two objects.
343
+ * @param target
344
+ * @param source
345
+ */
346
+ declare function merge(target: Record<string, any>, source: Record<string, any>): {
347
+ [x: string]: any;
348
+ };
349
+
350
+ 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, isBrowser, isIframe, isReactNative, loadScript, merge };
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "1.0.52",
2
+ "version": "1.0.53",
3
3
  "license": "MIT",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",