@konfigure/sdk 0.0.0-stage → 0.2.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/LICENSE +41 -0
- package/README.md +325 -2
- package/THIRD_PARTY_NOTICES.md +283 -0
- package/dist/chunk-ARGXORCF.js +1 -0
- package/dist/chunk-OOVVLYAY.js +482 -0
- package/dist/chunk-XUSV3KOD.js +1 -0
- package/dist/configurator-6ISAZiAx.d.ts +468 -0
- package/dist/index.d.ts +97 -0
- package/dist/index.js +4 -0
- package/dist/src-GJ5RXX7G.js +3811 -0
- package/dist/view.d.ts +674 -0
- package/dist/view.js +801 -0
- package/package.json +46 -4
|
@@ -0,0 +1,468 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Structural mirrors of the configurator's public API rows.
|
|
3
|
+
*
|
|
4
|
+
* The configurator types its rows from its database schema. A package must
|
|
5
|
+
* never import that schema (it would drag the database along), so it declares
|
|
6
|
+
* only the fields it reads and the configurator's rows satisfy them
|
|
7
|
+
* structurally.
|
|
8
|
+
*/
|
|
9
|
+
type ApiVec3 = {
|
|
10
|
+
x: number;
|
|
11
|
+
y: number;
|
|
12
|
+
z: number;
|
|
13
|
+
};
|
|
14
|
+
type ApiPartialVec3 = Partial<ApiVec3>;
|
|
15
|
+
type ApiSlotPartCondition = {
|
|
16
|
+
basePartSlotName: string;
|
|
17
|
+
partId: number;
|
|
18
|
+
};
|
|
19
|
+
type ApiAutoConfigurePart = {
|
|
20
|
+
targetModuleId: number;
|
|
21
|
+
targetBasePartSlotName: string;
|
|
22
|
+
targetLinkedBasePartSlot?: boolean;
|
|
23
|
+
partId: number;
|
|
24
|
+
};
|
|
25
|
+
type ApiModuleSlot = {
|
|
26
|
+
id?: number;
|
|
27
|
+
name: string;
|
|
28
|
+
label?: string | null;
|
|
29
|
+
floatingPointPosition: ApiVec3;
|
|
30
|
+
moduleSlotPosition: ApiVec3;
|
|
31
|
+
direction?: ApiVec3 | null;
|
|
32
|
+
slotGroup?: string | null;
|
|
33
|
+
hasBuiltInConnector: boolean;
|
|
34
|
+
preferConnection?: boolean;
|
|
35
|
+
linkedPartSlotName?: string | null;
|
|
36
|
+
compatibleModuleIds?: number[];
|
|
37
|
+
compatibleModulesWithSlots?: {
|
|
38
|
+
moduleId: number;
|
|
39
|
+
allowedSlotNames?: string[];
|
|
40
|
+
}[];
|
|
41
|
+
disabledBySlotParts?: ApiSlotPartCondition[];
|
|
42
|
+
enabledBySlotParts?: ApiSlotPartCondition[];
|
|
43
|
+
disabledByNeighborSlots?: string[];
|
|
44
|
+
autoConfigureParts?: ApiAutoConfigurePart[];
|
|
45
|
+
accessoryPartIds?: number[];
|
|
46
|
+
accessoryAnchorPosition?: ApiVec3 | null;
|
|
47
|
+
};
|
|
48
|
+
type ApiCompatiblePartRef = {
|
|
49
|
+
partId: number;
|
|
50
|
+
addPosition?: ApiPartialVec3;
|
|
51
|
+
};
|
|
52
|
+
type ApiBasePartSlot = {
|
|
53
|
+
id?: number;
|
|
54
|
+
name: string;
|
|
55
|
+
label?: string | null;
|
|
56
|
+
pointPosition: ApiVec3;
|
|
57
|
+
addPosition: ApiVec3;
|
|
58
|
+
compatibleParts?: ApiCompatiblePartRef[];
|
|
59
|
+
defaultPartId?: number | null;
|
|
60
|
+
slotGroupId?: number | null;
|
|
61
|
+
column?: string | null;
|
|
62
|
+
row?: string | null;
|
|
63
|
+
invertible?: boolean;
|
|
64
|
+
canRotate?: boolean;
|
|
65
|
+
order?: number;
|
|
66
|
+
mandatory?: boolean;
|
|
67
|
+
showInPreview?: boolean;
|
|
68
|
+
requiredByPartIds?: number[];
|
|
69
|
+
disabledPartsByNeighborSlots?: unknown[];
|
|
70
|
+
enabledPartsByNeighborSlots?: unknown[];
|
|
71
|
+
disabledPartsByNeighborParts?: unknown[];
|
|
72
|
+
backrestBlocksTables?: unknown | null;
|
|
73
|
+
hiddenBySlotParts?: unknown[];
|
|
74
|
+
syncWithSlotName?: string | null;
|
|
75
|
+
defaultInverted?: boolean;
|
|
76
|
+
isVariantDiscriminator?: boolean;
|
|
77
|
+
};
|
|
78
|
+
type ApiSlotGroup = {
|
|
79
|
+
id: number;
|
|
80
|
+
label: string;
|
|
81
|
+
order: number;
|
|
82
|
+
};
|
|
83
|
+
type ApiModule = {
|
|
84
|
+
id: number;
|
|
85
|
+
name: string;
|
|
86
|
+
code?: string | null;
|
|
87
|
+
description?: string | null;
|
|
88
|
+
image?: string | null;
|
|
89
|
+
status?: string;
|
|
90
|
+
sizes?: {
|
|
91
|
+
x: number;
|
|
92
|
+
z: number;
|
|
93
|
+
} | null;
|
|
94
|
+
/** Made-to-measure sizes (mm) the module can be ordered in; null = its one size. */
|
|
95
|
+
sizing?: {
|
|
96
|
+
width: {
|
|
97
|
+
min: number;
|
|
98
|
+
max: number;
|
|
99
|
+
};
|
|
100
|
+
height: {
|
|
101
|
+
min: number;
|
|
102
|
+
max: number;
|
|
103
|
+
};
|
|
104
|
+
/** The size the module's price is for; a made-to-measure size scales it by area. */
|
|
105
|
+
base?: {
|
|
106
|
+
width: number;
|
|
107
|
+
height: number;
|
|
108
|
+
};
|
|
109
|
+
} | null;
|
|
110
|
+
configPointPosition: ApiVec3;
|
|
111
|
+
rotatableModule?: boolean;
|
|
112
|
+
allowAsInitialModule?: boolean;
|
|
113
|
+
sortOrder?: number | null;
|
|
114
|
+
slotGroups: ApiSlotGroup[];
|
|
115
|
+
remoteProductLineId?: number | null;
|
|
116
|
+
moduleSlots?: ApiModuleSlot[];
|
|
117
|
+
basePartSlots?: ApiBasePartSlot[];
|
|
118
|
+
};
|
|
119
|
+
type ApiModel3d = {
|
|
120
|
+
id: number;
|
|
121
|
+
name?: string;
|
|
122
|
+
filePath: string;
|
|
123
|
+
updatedAt?: string | null;
|
|
124
|
+
/** UV units per metre of this file (Nido 5, Pod 0.7); null = the default. */
|
|
125
|
+
uvPerMetre?: number | null;
|
|
126
|
+
};
|
|
127
|
+
type ApiPartModel = {
|
|
128
|
+
id?: number;
|
|
129
|
+
model3d?: ApiModel3d | null;
|
|
130
|
+
hasConfigurableSurface: boolean;
|
|
131
|
+
fixedSurfaceId?: number | null;
|
|
132
|
+
order?: number;
|
|
133
|
+
tag?: string | null;
|
|
134
|
+
};
|
|
135
|
+
type ApiPartSlot = {
|
|
136
|
+
name: string;
|
|
137
|
+
label?: string | null;
|
|
138
|
+
pointPosition: ApiVec3;
|
|
139
|
+
addPosition: ApiVec3;
|
|
140
|
+
compatibleParts?: ApiCompatiblePartRef[];
|
|
141
|
+
defaultPartId?: number | null;
|
|
142
|
+
slotGroupId?: number | null;
|
|
143
|
+
mandatory?: boolean;
|
|
144
|
+
showInPreview?: boolean;
|
|
145
|
+
requiredByPartIds?: number[];
|
|
146
|
+
};
|
|
147
|
+
type ApiPart = {
|
|
148
|
+
id: number;
|
|
149
|
+
name: string;
|
|
150
|
+
code?: string | null;
|
|
151
|
+
/**
|
|
152
|
+
* The catalogue's second line. Load-bearing for the config panel: a slot can
|
|
153
|
+
* offer several options under one name (the Nido socket slot is three
|
|
154
|
+
* "Zásuvka" rows) and this is the only thing that tells them apart.
|
|
155
|
+
*/
|
|
156
|
+
description?: string | null;
|
|
157
|
+
image?: string | null;
|
|
158
|
+
status?: string;
|
|
159
|
+
partTypeId?: number | null;
|
|
160
|
+
hasConfigurableSurface?: boolean;
|
|
161
|
+
allowedSurfaceGroupIds?: number[];
|
|
162
|
+
allowedSurfaceIds?: number[];
|
|
163
|
+
defaultSurfaceId?: number | null;
|
|
164
|
+
ignoreCollision?: boolean;
|
|
165
|
+
collisionGroup?: string | null;
|
|
166
|
+
mirror?: {
|
|
167
|
+
x?: boolean;
|
|
168
|
+
y?: boolean;
|
|
169
|
+
z?: boolean;
|
|
170
|
+
} | null;
|
|
171
|
+
rotation?: ApiVec3 | null;
|
|
172
|
+
scale?: number | null;
|
|
173
|
+
hideFromConfigurator?: boolean;
|
|
174
|
+
wallThickness?: number | null;
|
|
175
|
+
wallPositionOffset?: number | null;
|
|
176
|
+
priceMultiplier?: number | null;
|
|
177
|
+
remoteProductAccessoryId?: number | null;
|
|
178
|
+
models: ApiPartModel[];
|
|
179
|
+
partSlots?: ApiPartSlot[];
|
|
180
|
+
};
|
|
181
|
+
type ApiSurface = {
|
|
182
|
+
id: number;
|
|
183
|
+
name: string;
|
|
184
|
+
description?: string | null;
|
|
185
|
+
groupId?: number | null;
|
|
186
|
+
status?: string;
|
|
187
|
+
/** JSON string (or object) with { color?, metalness?, roughness?, … }. */
|
|
188
|
+
textureJson?: string | Record<string, unknown> | null;
|
|
189
|
+
/** Colour map of a textured finish (a path on the instance). */
|
|
190
|
+
texturePath?: string | null;
|
|
191
|
+
/** Swatch picture for a picker. */
|
|
192
|
+
thumbnailPath?: string | null;
|
|
193
|
+
/** Centimetres of material the texture image shows (texture_scales). */
|
|
194
|
+
imageSizeCm?: number | null;
|
|
195
|
+
/** Row revision, used to bust caches on its files. */
|
|
196
|
+
updatedAt?: string | null;
|
|
197
|
+
};
|
|
198
|
+
type ApiSurfaceGroup = {
|
|
199
|
+
id: number;
|
|
200
|
+
name: string;
|
|
201
|
+
status?: string;
|
|
202
|
+
};
|
|
203
|
+
|
|
204
|
+
/** A product line as the SDK presents it. */
|
|
205
|
+
type ProductLine = {
|
|
206
|
+
id: number;
|
|
207
|
+
name: string;
|
|
208
|
+
/** The catalogue's slug, or one derived from the name (`BL 70 slim` → `bl-70-slim`). */
|
|
209
|
+
slug: string;
|
|
210
|
+
description: string | null;
|
|
211
|
+
/** Absolute URL of the product line's picture. */
|
|
212
|
+
image: string | null;
|
|
213
|
+
/** The 3D scene the instance shows it in (`wall` for windows and doors). */
|
|
214
|
+
scenePreset: string | null;
|
|
215
|
+
};
|
|
216
|
+
/**
|
|
217
|
+
* A configuration rule as the instance publishes it. The configurator
|
|
218
|
+
* evaluates these; their conditions and actions are the instance's own format
|
|
219
|
+
* and not part of the SDK's contract, hence `unknown`.
|
|
220
|
+
*/
|
|
221
|
+
type CatalogRule = {
|
|
222
|
+
id: number;
|
|
223
|
+
name: string;
|
|
224
|
+
ruleType: string;
|
|
225
|
+
priority: number;
|
|
226
|
+
conditions: unknown[];
|
|
227
|
+
actions: unknown[];
|
|
228
|
+
partMappings?: unknown[] | null;
|
|
229
|
+
targetModuleIds?: number[] | null;
|
|
230
|
+
};
|
|
231
|
+
/**
|
|
232
|
+
* Everything one product line needs, fetched once: its modules, the parts they
|
|
233
|
+
* can hold (nested parts included), the finishes and their groups, and the
|
|
234
|
+
* line's published rules, highest priority first. Rows are the public API's
|
|
235
|
+
* own, with every asset path made absolute against the instance.
|
|
236
|
+
*/
|
|
237
|
+
type LineCatalog = {
|
|
238
|
+
productLine: ProductLine;
|
|
239
|
+
modules: ApiModule[];
|
|
240
|
+
parts: ApiPart[];
|
|
241
|
+
surfaces: ApiSurface[];
|
|
242
|
+
surfaceGroups: ApiSurfaceGroup[];
|
|
243
|
+
rules: CatalogRule[];
|
|
244
|
+
};
|
|
245
|
+
|
|
246
|
+
/** A part in a slot, with its finish and its own nested slots. */
|
|
247
|
+
type ConfigPartState = {
|
|
248
|
+
/** The part's id on the instance. */
|
|
249
|
+
apiPartId: number;
|
|
250
|
+
/** The finish it wears, when it can wear one. */
|
|
251
|
+
surfaceId?: number;
|
|
252
|
+
/** Absent from the product at save time (a brace hidden by a neighbour). */
|
|
253
|
+
hidden?: boolean;
|
|
254
|
+
/** Nested slots by name; null = empty. */
|
|
255
|
+
nestedSlots: Record<string, ConfigPartState | null>;
|
|
256
|
+
};
|
|
257
|
+
/** A module: its parts by base slot, and the modules connected to it. */
|
|
258
|
+
type ConfigModuleState = {
|
|
259
|
+
/** Content hash; recomputed by the SDK on every change. */
|
|
260
|
+
hash: string;
|
|
261
|
+
apiModuleId: number;
|
|
262
|
+
basePartSlots: Record<string, ConfigPartState>;
|
|
263
|
+
invertedSlots: Record<string, boolean>;
|
|
264
|
+
rotatedSlots: Record<string, boolean>;
|
|
265
|
+
children: Record<string, ConfigModuleState>;
|
|
266
|
+
childSlotNames: Record<string, string>;
|
|
267
|
+
position: {
|
|
268
|
+
x: number;
|
|
269
|
+
y: number;
|
|
270
|
+
z: number;
|
|
271
|
+
};
|
|
272
|
+
rotationY: number;
|
|
273
|
+
/** Made-to-measure frame size in mm (`setSize`); absent = the module's own size. */
|
|
274
|
+
size?: {
|
|
275
|
+
width: number;
|
|
276
|
+
height: number;
|
|
277
|
+
};
|
|
278
|
+
};
|
|
279
|
+
/** A whole configuration — what `save()` stores and an enquiry carries. */
|
|
280
|
+
type ConfigurationState = {
|
|
281
|
+
productLineId: number | null;
|
|
282
|
+
rootModule: ConfigModuleState | null;
|
|
283
|
+
modifiers: Record<string, {
|
|
284
|
+
optionId: number | null;
|
|
285
|
+
}>;
|
|
286
|
+
quantities: {
|
|
287
|
+
modules: number;
|
|
288
|
+
connectors: number;
|
|
289
|
+
braces?: number;
|
|
290
|
+
cycles?: number;
|
|
291
|
+
};
|
|
292
|
+
extraConnections: {
|
|
293
|
+
fromPath: string[];
|
|
294
|
+
fromSlot: string;
|
|
295
|
+
toPath: string[];
|
|
296
|
+
toSlot: string;
|
|
297
|
+
}[];
|
|
298
|
+
environment: 'space' | 'wall';
|
|
299
|
+
};
|
|
300
|
+
|
|
301
|
+
/** The made-to-measure sizes a module can be made in (mm), or null for one size only. */
|
|
302
|
+
type SizeLimits = {
|
|
303
|
+
width: {
|
|
304
|
+
min: number;
|
|
305
|
+
max: number;
|
|
306
|
+
};
|
|
307
|
+
height: {
|
|
308
|
+
min: number;
|
|
309
|
+
max: number;
|
|
310
|
+
};
|
|
311
|
+
};
|
|
312
|
+
|
|
313
|
+
type GroupKind = 'module' | 'part' | 'surface';
|
|
314
|
+
/**
|
|
315
|
+
* One choice the configuration offers:
|
|
316
|
+
*
|
|
317
|
+
* - `module` — the product's model and size (a window's layout and dimensions);
|
|
318
|
+
* - a base slot name (`glass`, `handle`) — which part stands in that slot;
|
|
319
|
+
* - `surface:<slot>` — the finish of the part in that slot;
|
|
320
|
+
* - `surface` — one finish for every slot that allows it ("stain inside and out").
|
|
321
|
+
*/
|
|
322
|
+
type Group = {
|
|
323
|
+
key: string;
|
|
324
|
+
kind: GroupKind;
|
|
325
|
+
/** The catalogue's label (slot labels), or a short default for `module` / `surface`. */
|
|
326
|
+
label: string;
|
|
327
|
+
/** The base slots a `surface` group paints. */
|
|
328
|
+
slots?: string[];
|
|
329
|
+
};
|
|
330
|
+
type Option = {
|
|
331
|
+
/** The instance's numeric id: stable, what the saved state stores. */
|
|
332
|
+
id: number;
|
|
333
|
+
/** The catalogue code where the row has one (modules, parts). */
|
|
334
|
+
code: string | null;
|
|
335
|
+
name: string;
|
|
336
|
+
description: string | null;
|
|
337
|
+
/** Absolute URL of a picture: the module or part image, or a finish's swatch. */
|
|
338
|
+
image: string | null;
|
|
339
|
+
selected: boolean;
|
|
340
|
+
disabled: boolean;
|
|
341
|
+
/** Why it is disabled — the rule's own message. */
|
|
342
|
+
reason: string | null;
|
|
343
|
+
};
|
|
344
|
+
type ModuleOption = Option & {
|
|
345
|
+
/** Footprint in metres (`x` wide, `z` deep) as the catalogue declares it. */
|
|
346
|
+
sizes: {
|
|
347
|
+
x: number;
|
|
348
|
+
z: number;
|
|
349
|
+
} | null;
|
|
350
|
+
/** The made-to-measure sizes (mm) it can be made in; null = its one size only. */
|
|
351
|
+
sizing: SizeLimits | null;
|
|
352
|
+
};
|
|
353
|
+
/** A made-to-measure frame size, in millimetres. */
|
|
354
|
+
type Size = {
|
|
355
|
+
width: number;
|
|
356
|
+
height: number;
|
|
357
|
+
};
|
|
358
|
+
|
|
359
|
+
type SurfaceOption = Option & {
|
|
360
|
+
/** A hex colour to draw a swatch with when there is no image. */
|
|
361
|
+
color: string | null;
|
|
362
|
+
groupId: number | null;
|
|
363
|
+
groupName: string | null;
|
|
364
|
+
/** For the `surface` group: which slots this finish can be put on. */
|
|
365
|
+
slots: string[];
|
|
366
|
+
};
|
|
367
|
+
type AnyOption = Option | ModuleOption | SurfaceOption;
|
|
368
|
+
type SummaryRow = {
|
|
369
|
+
group: string;
|
|
370
|
+
label: string;
|
|
371
|
+
value: string;
|
|
372
|
+
optionId: number;
|
|
373
|
+
};
|
|
374
|
+
type ValidationIssue = {
|
|
375
|
+
group: string;
|
|
376
|
+
code: 'missing_module' | 'incompatible_part' | 'surface_not_allowed' | 'rule_violation';
|
|
377
|
+
message: string;
|
|
378
|
+
};
|
|
379
|
+
type ChangeEvent = {
|
|
380
|
+
state: ConfigurationState;
|
|
381
|
+
/** Group keys whose selection changed. `['*']` after `load()`. */
|
|
382
|
+
changed: string[];
|
|
383
|
+
};
|
|
384
|
+
type Events = {
|
|
385
|
+
change: ChangeEvent;
|
|
386
|
+
};
|
|
387
|
+
type ConfiguratorOptions = {
|
|
388
|
+
catalog: LineCatalog;
|
|
389
|
+
locale: string;
|
|
390
|
+
/** The instance's origin, e.g. `https://example.konfigure.app` (the client sets it). */
|
|
391
|
+
instance?: string;
|
|
392
|
+
/** Start from this module (id, code or name); the line's first otherwise. */
|
|
393
|
+
module?: number | string;
|
|
394
|
+
/** Start from this state instead (a saved configuration, your own URL). */
|
|
395
|
+
state?: ConfigurationState;
|
|
396
|
+
/** Hooks the client provides: persisting and enquiring go through the instance. */
|
|
397
|
+
save: (state: ConfigurationState, name: string) => Promise<SavedConfiguration>;
|
|
398
|
+
submitInquiry: (state: ConfigurationState, inquiry: InquiryInput) => Promise<SubmittedInquiry>;
|
|
399
|
+
};
|
|
400
|
+
type SavedConfiguration = {
|
|
401
|
+
id: string;
|
|
402
|
+
displayId: string | null;
|
|
403
|
+
/** The instance's page for it — the configurator, opened on this configuration. */
|
|
404
|
+
shareUrl: string;
|
|
405
|
+
/** The read-only 3D view of it. */
|
|
406
|
+
viewUrl: string;
|
|
407
|
+
};
|
|
408
|
+
type InquiryInput = {
|
|
409
|
+
/** Full name; split into first and last name for the dashboard. */
|
|
410
|
+
name?: string;
|
|
411
|
+
email: string;
|
|
412
|
+
phone?: string;
|
|
413
|
+
company?: string;
|
|
414
|
+
message?: string;
|
|
415
|
+
/**
|
|
416
|
+
* Fields the instance doesn't model (for a window, say: the wood, a bottom
|
|
417
|
+
* profile, a count). They are written into the enquiry's note as `key: value`
|
|
418
|
+
* lines, after the message.
|
|
419
|
+
*/
|
|
420
|
+
extra?: Record<string, string | number | boolean | null | undefined>;
|
|
421
|
+
};
|
|
422
|
+
type SubmittedInquiry = {
|
|
423
|
+
id: string;
|
|
424
|
+
displayId: string | null;
|
|
425
|
+
};
|
|
426
|
+
/**
|
|
427
|
+
* A headless configurator for one product line: plain data in, plain data out.
|
|
428
|
+
* It never touches three.js — mount `@konfigure/sdk/view` to draw it.
|
|
429
|
+
*/
|
|
430
|
+
declare function createConfigurator(config: ConfiguratorOptions): {
|
|
431
|
+
/** The product line this configurator configures. */
|
|
432
|
+
productLine: ProductLine;
|
|
433
|
+
/** The catalogue rows it works from (absolute asset URLs) — what the view draws with. */
|
|
434
|
+
catalog: LineCatalog;
|
|
435
|
+
/** The instance it came from, when created through a client. */
|
|
436
|
+
instance: string | undefined;
|
|
437
|
+
groups: () => Group[];
|
|
438
|
+
options: {
|
|
439
|
+
(key: "module"): ModuleOption[];
|
|
440
|
+
(key: `surface${string}`): SurfaceOption[];
|
|
441
|
+
(key: string): AnyOption[];
|
|
442
|
+
};
|
|
443
|
+
selected: (key: string) => AnyOption | null;
|
|
444
|
+
select: (key: string, value: number | string) => boolean;
|
|
445
|
+
summary: () => SummaryRow[];
|
|
446
|
+
validate: () => {
|
|
447
|
+
valid: boolean;
|
|
448
|
+
issues: ValidationIssue[];
|
|
449
|
+
};
|
|
450
|
+
/** Prices aren't served to the SDK yet; always null. */
|
|
451
|
+
price: () => null;
|
|
452
|
+
/** The current module's catalogue row. */
|
|
453
|
+
module: () => ApiModule;
|
|
454
|
+
size: () => Size | null;
|
|
455
|
+
setSize: (next: Size | null) => boolean;
|
|
456
|
+
sizeLimits: () => SizeLimits | null;
|
|
457
|
+
toJSON: () => ConfigurationState;
|
|
458
|
+
load: (next: ConfigurationState) => void;
|
|
459
|
+
reset: (module?: number | string) => void;
|
|
460
|
+
on: <K extends keyof Events>(event: K, listener: (payload: Events[K]) => void) => () => void;
|
|
461
|
+
save: (saveOptions?: {
|
|
462
|
+
name?: string;
|
|
463
|
+
}) => Promise<SavedConfiguration>;
|
|
464
|
+
submitInquiry: (inquiry: InquiryInput) => Promise<SubmittedInquiry>;
|
|
465
|
+
};
|
|
466
|
+
type Configurator = ReturnType<typeof createConfigurator>;
|
|
467
|
+
|
|
468
|
+
export type { AnyOption as A, ConfigurationState as C, Group as G, InquiryInput as I, LineCatalog as L, ModuleOption as M, Option as O, ProductLine as P, SavedConfiguration as S, ValidationIssue as V, Configurator as a, SubmittedInquiry as b, CatalogRule as c, ChangeEvent as d, ConfigModuleState as e, ConfigPartState as f, GroupKind as g, Size as h, SizeLimits as i, SummaryRow as j, SurfaceOption as k };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { P as ProductLine, L as LineCatalog, C as ConfigurationState, a as Configurator, S as SavedConfiguration, I as InquiryInput, b as SubmittedInquiry } from './configurator-6ISAZiAx.js';
|
|
2
|
+
export { A as AnyOption, c as CatalogRule, d as ChangeEvent, e as ConfigModuleState, f as ConfigPartState, G as Group, g as GroupKind, M as ModuleOption, O as Option, h as Size, i as SizeLimits, j as SummaryRow, k as SurfaceOption, V as ValidationIssue } from './configurator-6ISAZiAx.js';
|
|
3
|
+
|
|
4
|
+
type KonfigureClientOptions = {
|
|
5
|
+
/** The instance's origin, e.g. `https://example.konfigure.app`. */
|
|
6
|
+
instance: string;
|
|
7
|
+
/** Catalogue language and the language of enquiry e-mails (cs, en, de, fr). Default `cs`. */
|
|
8
|
+
locale?: string;
|
|
9
|
+
/** A fetch to use instead of the global one (SSR, tests). */
|
|
10
|
+
fetch?: typeof fetch;
|
|
11
|
+
};
|
|
12
|
+
type SavedConfigurationRecord = {
|
|
13
|
+
id: string;
|
|
14
|
+
displayId: string | null;
|
|
15
|
+
name: string;
|
|
16
|
+
productLineId: number | null;
|
|
17
|
+
state: ConfigurationState;
|
|
18
|
+
shareUrl: string;
|
|
19
|
+
viewUrl: string;
|
|
20
|
+
};
|
|
21
|
+
type LeadInput = {
|
|
22
|
+
/** Field key → value, e.g. `{ name, email, phone, message }`. */
|
|
23
|
+
data: Record<string, string>;
|
|
24
|
+
/** Which gate or form captured it, for the dashboard. */
|
|
25
|
+
gateKey?: string;
|
|
26
|
+
/** A saved configuration it belongs to. */
|
|
27
|
+
configurationId?: string;
|
|
28
|
+
};
|
|
29
|
+
type ConfiguratorRequest = {
|
|
30
|
+
productLine: number | string;
|
|
31
|
+
module?: number | string;
|
|
32
|
+
state?: ConfigurationState;
|
|
33
|
+
} | {
|
|
34
|
+
configuration: string;
|
|
35
|
+
};
|
|
36
|
+
/**
|
|
37
|
+
* A client for one Konfigure instance. Everything goes over the instance's
|
|
38
|
+
* public API with plain `fetch` — no cookies (requests are anonymous), so the
|
|
39
|
+
* site's origin has to be on the instance's embed allow-list for the browser
|
|
40
|
+
* to let the responses through (see the README).
|
|
41
|
+
*/
|
|
42
|
+
declare function createKonfigureClient(options: KonfigureClientOptions): {
|
|
43
|
+
instance: string;
|
|
44
|
+
locale: string;
|
|
45
|
+
productLines: () => Promise<ProductLine[]>;
|
|
46
|
+
productLine: (ref: number | string) => Promise<ProductLine>;
|
|
47
|
+
catalog: (ref: number | string) => Promise<LineCatalog>;
|
|
48
|
+
configurator: (request: ConfiguratorRequest) => Promise<Configurator>;
|
|
49
|
+
getConfiguration: (id: string) => Promise<SavedConfigurationRecord>;
|
|
50
|
+
saveConfiguration: (state: ConfigurationState, name: string) => Promise<SavedConfiguration>;
|
|
51
|
+
submitInquiry: (state: ConfigurationState, inquiry: InquiryInput) => Promise<SubmittedInquiry>;
|
|
52
|
+
submitLead: (lead: LeadInput) => Promise<{
|
|
53
|
+
ok: boolean;
|
|
54
|
+
}>;
|
|
55
|
+
};
|
|
56
|
+
type KonfigureClient = ReturnType<typeof createKonfigureClient>;
|
|
57
|
+
|
|
58
|
+
type KonfigureErrorCode =
|
|
59
|
+
/** The instance answered with an error status (see `status`). */
|
|
60
|
+
'http'
|
|
61
|
+
/** The instance could not be reached (network, CORS: is the origin allowed?). */
|
|
62
|
+
| 'network'
|
|
63
|
+
/** No product line matches the id, slug or name given. */
|
|
64
|
+
| 'unknown_product_line'
|
|
65
|
+
/** No module of the product line matches. */
|
|
66
|
+
| 'unknown_module'
|
|
67
|
+
/** The group key isn't one `groups()` lists for the current module. */
|
|
68
|
+
| 'unknown_group'
|
|
69
|
+
/** No option of the group matches the id, code or name given. */
|
|
70
|
+
| 'unknown_option'
|
|
71
|
+
/** The option exists but a rule rules it out (see `message`). */
|
|
72
|
+
| 'option_disabled'
|
|
73
|
+
/** A configuration state that doesn't belong to this configurator. */
|
|
74
|
+
| 'invalid_state'
|
|
75
|
+
/** The view has nothing drawn yet (await `whenReady()`), or was disposed. */
|
|
76
|
+
| 'not_ready'
|
|
77
|
+
/** A photo studio is open on the view: one at a time, and the scene is the studio's until it is disposed. */
|
|
78
|
+
| 'studio_open'
|
|
79
|
+
/** The photo studio was disposed; open a new one. */
|
|
80
|
+
| 'studio_closed'
|
|
81
|
+
/** The module comes in its one size only (`sizeLimits()` is null). */
|
|
82
|
+
| 'size_not_available'
|
|
83
|
+
/** The size is outside what the module can be made in (`details` holds `sizeLimits()`). */
|
|
84
|
+
| 'size_out_of_range';
|
|
85
|
+
/** Every error the SDK throws on purpose. `code` is stable; `message` is for people. */
|
|
86
|
+
declare class KonfigureError extends Error {
|
|
87
|
+
readonly code: KonfigureErrorCode;
|
|
88
|
+
readonly status?: number;
|
|
89
|
+
readonly details?: unknown;
|
|
90
|
+
constructor(code: KonfigureErrorCode, message: string, extra?: {
|
|
91
|
+
status?: number;
|
|
92
|
+
details?: unknown;
|
|
93
|
+
cause?: unknown;
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
export { ConfigurationState, Configurator, InquiryInput, type KonfigureClient, type KonfigureClientOptions, KonfigureError, type KonfigureErrorCode, type LeadInput, LineCatalog, ProductLine, SavedConfiguration, type SavedConfigurationRecord, SubmittedInquiry, createKonfigureClient };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import {g,h,j as j$1,i,b,f,a as a$1}from'./chunk-ARGXORCF.js';export{a as KonfigureError}from'./chunk-ARGXORCF.js';import {a}from'./chunk-XUSV3KOD.js';function j(t,e){return e?/^(https?:|data:|blob:)/i.test(e)?e:new URL(e,`${t}/`).toString():null}a(j,"absoluteUrl");function W(t,e){if(!t||!e)return t;let o=Date.parse(e);return Number.isNaN(o)?t:`${t}${t.includes("?")?"&":"?"}v=${o}`}a(W,"versionedUrl");function G(t){return t.normalize("NFD").replace(/[̀-ͯ]/g,"").toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-+|-+$/g,"")}a(G,"slugify");function J(t){if(Array.isArray(t))return t;let e=t?.items;return Array.isArray(e)?e:[]}a(J,"listRows");function le(t){return t.status===void 0||t.status==="public"}a(le,"isPublished");function de(t,e){return {id:e.id,name:e.name,slug:e.slug||G(e.name),description:e.description??null,image:W(j(t,e.image),e.updatedAt),scenePreset:e.scenePreset??null}}a(de,"toProductLine");function Ae(t){let e=new Set;for(let o of t.basePartSlots??[]){o.defaultPartId&&e.add(o.defaultPartId);for(let a of o.compatibleParts??[])e.add(a.partId);}for(let o of t.moduleSlots??[])for(let a of o.accessoryPartIds??[])e.add(a);return e}a(Ae,"partIdsOfModule");function $e(t,e){let o=[...t];for(;o.length>0;){let a=e.get(o.pop());for(let m of a?.partSlots??[])for(let y of [m.defaultPartId,...(m.compatibleParts??[]).map(h=>h.partId)])y&&!t.has(y)&&(t.add(y),o.push(y));}return t}a($e,"closePartIds");var ke=["normalPath","roughnessPath","metalnessPath","aoPath","heightPath"];function Re(t,e){let o=a(m=>W(j(t,m),e.updatedAt),"asset"),a$1=null;try{a$1=typeof e.textureJson=="string"?JSON.parse(e.textureJson):e.textureJson??null;}catch{a$1=null;}if(a$1){a$1={...a$1};for(let m of ke){let y=a$1[m];typeof y=="string"&&(a$1[m]=o(y));}}return {...e,textureJson:a$1,texturePath:o(e.texturePath),thumbnailPath:o(e.thumbnailPath)}}a(Re,"absoluteSurface");function ze(t,e){return {...e,image:j(t,e.image),models:e.models.map(o=>o.model3d?{...o,model3d:{...o.model3d,filePath:W(j(t,o.model3d.filePath),o.model3d.updatedAt)??o.model3d.filePath}}:o)}}a(ze,"absolutePart");function ce(t,e,o){let a=J(o.modules).filter(le).map(p=>({...p,image:j(t,p.image)})).sort((p,C)=>(p.sortOrder??0)-(C.sortOrder??0)),m=J(o.parts),y=new Map(m.map(p=>[p.id,p])),h=new Set;for(let p of a)for(let C of Ae(p))h.add(C);$e(h,y);let b=J(o.rules).filter(p=>p.productLine?.id===e.id&&le(p)).sort((p,C)=>C.priority-p.priority);return {productLine:e,modules:a,parts:m.filter(p=>h.has(p.id)).map(p=>ze(t,p)),surfaces:J(o.surfaces).filter(p=>p.status!=="deleted").map(p=>Re(t,p)),surfaceGroups:J(o.surfaceGroups),rules:b}}a(ce,"buildLineCatalog");function fe(t){return {catalog:t,modules:new Map(t.modules.map(e=>[e.id,e])),parts:new Map(t.parts.map(e=>[e.id,e])),surfaces:new Map(t.surfaces.map(e=>[e.id,e])),surfaceGroups:new Map(t.surfaceGroups.map(e=>[e.id,e]))}}a(fe,"indexCatalog");function q(t,e,o){let a=t.surfaces.get(o);return a!==void 0&&g(e,o,a.groupId)}a(q,"isSurfaceAllowed");function U(t,e){return e.hasConfigurableSurface?t.catalog.surfaces.filter(o=>q(t,e,o.id)):[]}a(U,"surfacePalette");function B(t,e,o={}){let a=t.parts.get(e),m=a?h(a,{preferred:o.surfaceId,inherited:o.inheritedSurfaceId},b=>q(t,a,b)):void 0,y=a?.hasConfigurableSurface&&m!==void 0&&t.surfaces.has(m)?m:void 0,h$1={};for(let b of a?.partSlots??[]){let p=j$1(b);h$1[b.name]=p?B(t,p,{inheritedSurfaceId:m}):null;}return {apiPartId:e,...y!==void 0&&{surfaceId:y},nestedSlots:h$1}}a(B,"defaultPartState");function Ne(t,e){let o=(e.compatibleParts??[]).map(a=>a.partId).filter(a=>t.parts.has(a));return i(e,o)??null}a(Ne,"startingPartOf");function T(t){return [...t.basePartSlots??[]].sort((e,o)=>(e.order??0)-(o.order??0))}a(T,"sortedBaseSlots");function K(t){let e=Object.fromEntries(Object.entries(t.children).map(([o,a])=>[o,K(a)]));return {...t,children:e,hash:b({apiModuleId:t.apiModuleId,basePartSlots:t.basePartSlots,invertedSlots:t.invertedSlots,rotatedSlots:t.rotatedSlots,childrenHashes:Object.fromEntries(Object.entries(e).map(([o,a])=>[o,a.hash])),size:t.size})}}a(K,"withHash");function pe(t,e){let o={},a={};for(let m of T(e)){let y=Ne(t,m);y!=null&&(o[m.name]=B(t,y),m.defaultInverted&&(a[m.name]=true));}return K({apiModuleId:e.id,basePartSlots:o,invertedSlots:a,rotatedSlots:{},children:{},childSlotNames:{},position:{x:0,y:0,z:0},rotationY:0})}a(pe,"defaultModuleState");function _e(t,e){return !!t&&!!e&&t.trim().toLowerCase()===e.trim().toLowerCase()}a(_e,"sameName");function me(t,e,o){let a=pe(t,o);if(!e)return a;let m=t.modules.get(e.apiModuleId),y={...a.basePartSlots};for(let b of T(o)){let p=e.basePartSlots[b.name];if(!p)continue;let C=t.parts.get(p.apiPartId),x=(b.compatibleParts??[]).map(A=>A.partId),O=x.find(A=>_e(t.parts.get(A)?.name,C?.name));if(O===void 0){let k=(m?.basePartSlots?.find($=>$.name===b.name)?.compatibleParts??[]).findIndex($=>$.partId===p.apiPartId);k>=0&&k<x.length&&(O=x[k]);}O===void 0&&(O=y[b.name]?.apiPartId),O!==void 0&&(y[b.name]=B(t,O,{surfaceId:p.surfaceId}));}let h=e.size?je(o.sizing,e.size):null;return K({...a,basePartSlots:y,...h&&{size:h}})}a(me,"carryOverModuleState");function je(t,e){if(!t)return null;let o=a((a,m)=>Math.round(Math.min(m.max,Math.max(m.min,a))),"clamp");return {width:o(e.width,t.width),height:o(e.height,t.height)}}a(je,"fitSize");function Q(t,e){return {productLineId:t.catalog.productLine.id,rootModule:pe(t,e),modifiers:{},quantities:{modules:1,connectors:0},extraConnections:[],environment:"space"}}a(Q,"initialState");function Z(t){return t?1+Object.values(t.children).reduce((e,o)=>e+Z(o),0):0}a(Z,"countModules");function ge(t){return {apiPartId:t.apiPartId,partSlots:Object.fromEntries(Object.entries(t.nestedSlots).map(([e,o])=>[e,{part:o?ge(o):void 0}]))}}a(ge,"rulePart");function F(t,e,o="root"){let a=t.modules.get(e.apiModuleId),m={};for(let[h,b]of Object.entries(e.basePartSlots)){let p=a?.basePartSlots?.find(C=>C.name===h);m[h]={part:ge(b),compatibleParts:(p?.compatibleParts??[]).map(C=>({apiPartId:C.partId}))};}let y={};for(let h of a?.moduleSlots??[]){let b=e.children[h.name];y[h.name]={module:b?F(t,b,`${o}/${h.name}`):void 0,compatibleModules:(h.compatibleModuleIds??[]).map(p=>({id:p}))};}return {id:o,apiModuleId:e.apiModuleId,basePartSlots:m,moduleSlots:y}}a(F,"ruleModule");function H(t){let e=[t];for(let o of Object.values(t.moduleSlots))o.module&&e.push(...H(o.module));return e}a(H,"allRuleModules");var he={cs:{module:"Model",surface:"Povrch",size:"Rozm\u011Br"},en:{module:"Model",surface:"Finish",size:"Size"},de:{module:"Modell",surface:"Oberfl\xE4che",size:"Ma\xDF"},fr:{module:"Mod\xE8le",surface:"Finition",size:"Dimensions"}};function Se(t,e){if(typeof e=="number")return t.find(a=>a.id===e);let o=e.trim().toLowerCase();return t.find(a=>String(a.id)===o)??t.find(a=>a.code?.trim().toLowerCase()===o)??t.find(a=>a.name.trim().toLowerCase()===o)}a(Se,"findOption");function Te(t){let e=t.textureJson,o=e&&typeof e=="object"?e.color:void 0;return typeof o=="string"?o:null}a(Te,"colourOf");function be(t){let e=fe(t.catalog),{catalog:o}=t,a$2=he[t.locale]??he.en,m=f(o.rules),y=new Map;if(o.modules.length===0)throw new a$1("unknown_module",`Product line "${o.productLine.name}" has no published modules`);let h=t.state?p(t.state):Q(e,b(t.module));function b(n){if(n===void 0)return o.modules.find(s=>s.allowAsInitialModule!==false)??o.modules[0];let r=Se(o.modules,n);if(!r)throw new a$1("unknown_module",`No module "${n}" in product line "${o.productLine.name}"`);return r}a(b,"resolveModule");function p(n){if(n.productLineId!=null&&n.productLineId!==o.productLine.id)throw new a$1("invalid_state",`State is for product line ${n.productLineId}, this configurator is ${o.productLine.id}`);let r=n.rootModule?K(n.rootModule):null;if(r&&!e.modules.has(r.apiModuleId))throw new a$1("invalid_state",`Module ${r.apiModuleId} is not in this line`);return {productLineId:o.productLine.id,rootModule:r,modifiers:n.modifiers??{},quantities:{...n.quantities,modules:Z(r)},extraConnections:n.extraConnections??[],environment:n.environment??"space"}}a(p,"normalise");function C(){let n=h.rootModule;if(!n)throw new a$1("invalid_state","The configuration has no module");return n}a(C,"root");function x(){return e.modules.get(C().apiModuleId)}a(x,"currentModule");function O(n){return x().basePartSlots?.find(r=>r.name===n)}a(O,"slotOf");function A(){return T(x()).filter(n=>!n.syncWithSlotName)}a(A,"leaderSlots");function k(n){return T(x()).filter(r=>r.syncWithSlotName===n)}a(k,"followersOf");function $(n){return (n.compatibleParts??[]).map(r=>e.parts.get(r.partId)).filter(r=>!!r&&!r.hideFromConfigurator)}a($,"visibleParts");function N(n){let r=C().basePartSlots[n]?.apiPartId;return r===void 0?void 0:e.parts.get(r)}a(N,"partIn");function X(){return A().filter(n=>{let r=N(n.name);return r?U(e,r).length>0:false})}a(X,"surfaceSlots");function d(){let n=[];o.modules.length>1&&n.push({key:"module",kind:"module",label:a$2.module});for(let s of A())$(s).length>1&&n.push({key:s.name,kind:"part",label:s.label||s.name});let r=X();for(let s of r)U(e,N(s.name)).length>1&&n.push({key:`surface:${s.name}`,kind:"surface",label:s.label||s.name,slots:[s.name]});return r.length>0&&n.push({key:"surface",kind:"surface",label:a$2.surface,slots:r.map(s=>s.name)}),n}a(d,"groups");function l(n){let r=d().find(s=>s.key===n);if(!r){let s=d().map(f=>f.key).join(", ");throw new a$1("unknown_group",`No group "${n}" (this module has: ${s})`)}return r}a(l,"requireGroup");function I(){let n=C().apiModuleId;return o.modules.map(r=>({id:r.id,code:r.code??null,name:r.name,description:r.description??null,image:r.image??null,sizes:r.sizes??null,sizing:r.sizing??null,selected:r.id===n,disabled:false,reason:null}))}a(I,"moduleOptions");function w(n){let r=O(n),s=C(),f=s.basePartSlots[n]?.apiPartId,u=F(e,s),S=H(u);return $(r).map(c=>{let g=c.id===f?null:m.checkPart(c.id,n,u,S,n);return {id:c.id,code:c.code??null,name:c.name,description:c.description??null,image:c.image??null,selected:c.id===f,disabled:!!g,reason:g?.message??null}})}a(w,"partOptions");function P(n){let r=C(),s=new Map;for(let u of n){let S=N(u);if(S)for(let c of U(e,S)){let g=s.get(c.id)??{surface:c,slots:[]};g.slots.push(u),s.set(c.id,g);}}let f=n.map(u=>r.basePartSlots[u]?.surfaceId);return o.surfaces.filter(u=>s.has(u.id)).map(u=>{let{slots:S}=s.get(u.id),c=u.groupId!=null?e.surfaceGroups.get(u.groupId):void 0;return {id:u.id,code:null,name:u.name,description:u.description??null,image:u.thumbnailPath??u.texturePath??null,color:Te(u),groupId:u.groupId??null,groupName:c?.name??null,slots:S,selected:f.length>0&&f.every(g=>g===u.id),disabled:false,reason:null}})}a(P,"surfaceOptions");function L(n){let r=l(n);return r.kind==="module"?I():r.kind==="part"?w(r.key):P(r.slots??[])}a(L,"options");function R(n){return L(n).find(r=>r.selected)??null}a(R,"selected");function v(n,r){let s=K(n);h={...h,rootModule:s,quantities:{...h.quantities,modules:1}},Y("change",{state:_(),changed:r});}a(v,"commit");function V(n,r,s){let f={...n.basePartSlots};for(let u of [r,...k(r).map(S=>S.name)]){if(!O(u)?.compatibleParts?.some(g=>g.partId===s))continue;let c=f[u];c?.apiPartId!==s&&(f[u]=B(e,s,{surfaceId:c?.surfaceId}));}return {...n,basePartSlots:f}}a(V,"placePart");function ee(n,r,s){let f=e.parts.get(n.apiPartId),u=!!f?.hasConfigurableSurface&&q(e,f,r),S=Object.fromEntries(Object.entries(n.nestedSlots).map(([c,g])=>[c,g&&g.surfaceId===s?ee(g,r,s):g]));return {...n,...u&&{surfaceId:r},nestedSlots:S}}a(ee,"paint");function ye(n,r,s){let f={...n.basePartSlots};for(let u of r)for(let S of [u,...k(u).map(c=>c.name)]){let c=f[S];c&&(f[S]=ee(c,s,c.surfaceId));}return {...n,basePartSlots:f}}a(ye,"paintSlots");function Ie(n,r){let s=l(n),f=L(n),u=Se(f,r);if(!u){let g=f.map(z=>z.name).join(", ");throw new a$1("unknown_option",`No option "${r}" in "${n}" (${g})`)}if(u.disabled)throw new a$1("option_disabled",u.reason??`"${u.name}" is ruled out`);if(u.selected)return false;let S=C();if(s.kind==="module")return v(me(e,S,e.modules.get(u.id)),["*"]),true;if(s.kind==="part"){let g=V(S,n,u.id),z=[n],E=F(e,g);for(let D of m.partChangeSyncs(u.id,n,E,H(E)))D.moduleId===E.id&&(g=V(g,D.slotName,D.newPartId),z.push(D.slotName));return v(g,z),true}let c=u.slots;return v(ye(S,c,u.id),[n,...c.map(g=>`surface:${g}`)].filter((g,z,E)=>E.indexOf(g)===z)),true}a(Ie,"select");function te(){let n=x().sizing;return n?JSON.parse(JSON.stringify(n)):null}a(te,"sizeLimits");function Pe(){let n=C().size;return n?{...n}:null}a(Pe,"size");function Ce(n){let r=C();if(n===null){if(!r.size)return false;let{size:c,...g}=r;return v(g,["size"]),true}let s=te();if(!s)throw new a$1("size_not_available",`"${x().name}" comes in one size only`);let f=Math.round(n.width),u=Math.round(n.height),S=a((c,g)=>Number.isFinite(c)&&c>=g.min&&c<=g.max,"fits");if(!S(f,s.width)||!S(u,s.height))throw new a$1("size_out_of_range",`${f} \xD7 ${u} mm is outside ${s.width.min}\u2013${s.width.max} \xD7 ${s.height.min}\u2013${s.height.max} mm`,{details:s});return r.size?.width===f&&r.size?.height===u?false:(v({...r,size:{width:f,height:u}},["size"]),true)}a(Ce,"setSize");function we(){let n=C(),r=x(),s=[{group:"module",label:a$2.module,value:r.name,optionId:r.id}];n.size&&s.push({group:"size",label:a$2.size,value:`${n.size.width} \xD7 ${n.size.height} mm`,optionId:r.id});for(let f of A()){let u=N(f.name);if(!u)continue;$(f).length>1&&s.push({group:f.name,label:f.label||f.name,value:u.name,optionId:u.id});let S=n.basePartSlots[f.name]?.surfaceId,c=S!==void 0?e.surfaces.get(S):void 0;c&&U(e,u).length>0&&s.push({group:`surface:${f.name}`,label:f.label||f.name,value:c.name,optionId:c.id});}return s}a(we,"summary");function ne(){let n=[],r=h.rootModule;if(!r)return n.push({group:"module",code:"missing_module",message:"No module chosen"}),{valid:false,issues:n};let s=F(e,r),f=H(s);for(let u of T(x())){let S=r.basePartSlots[u.name];if(!S)continue;let c=e.parts.get(S.apiPartId);if(!c||!u.compatibleParts?.some(z=>z.partId===S.apiPartId)){n.push({group:u.name,code:"incompatible_part",message:`Part ${S.apiPartId} does not fit slot "${u.name}"`});continue}let g=m.checkPart(c.id,u.name,s,f,u.name);g&&n.push({group:u.name,code:"rule_violation",message:g.message}),S.surfaceId!==void 0&&!q(e,c,S.surfaceId)&&n.push({group:`surface:${u.name}`,code:"surface_not_allowed",message:`Finish ${S.surfaceId} is not offered for "${c.name}"`});}return {valid:n.length===0,issues:n}}a(ne,"validate");function _(){return JSON.parse(JSON.stringify(h))}a(_,"toJSON");function Me(n){h=p(n),Y("change",{state:_(),changed:["*"]});}a(Me,"load");function xe(n){h=Q(e,n===void 0?x():b(n)),Y("change",{state:_(),changed:["*"]});}a(xe,"reset");function Le(n,r){let s=y.get(n)??new Set;return s.add(r),y.set(n,s),()=>{s.delete(r);}}a(Le,"on");function Y(n,r){for(let s of y.get(n)??[])try{s(r);}catch(f){console.error("[konfigure] change listener failed",f);}}a(Y,"emit");function ve(n={}){let r=n.name??`${o.productLine.name} \xB7 ${x().name}`;return t.save(_(),r)}a(ve,"save");function Oe(n){let r=ne();if(!r.valid)throw new a$1("invalid_state",r.issues.map(s=>s.message).join("; "),{details:r.issues});return t.submitInquiry(_(),n)}return a(Oe,"submitInquiry"),{productLine:o.productLine,catalog:o,instance:t.instance,groups:d,options:L,selected:R,select:Ie,summary:we,validate:ne,price:a(()=>null,"price"),module:a(()=>x(),"module"),size:Pe,setSize:Ce,sizeLimits:te,toJSON:_,load:Me,reset:xe,on:Le,save:ve,submitInquiry:Oe}}a(be,"createConfigurator");function Ke(t){let e=t.instance.replace(/\/+$/,""),o=t.locale??"cs",a$2=t.fetch??globalThis.fetch.bind(globalThis),m=o==="cs"?"":`/${o}`,y=null,h=new Map;async function b(d,l){let I=`${e}${d}${d.includes("?")?"&":"?"}locale=${o}`,w;try{w=await a$2(I,{method:l?.method??"GET",headers:{Accept:"application/json",...l?.body!==void 0&&{"Content-Type":"application/json"}},body:l?.body!==void 0?JSON.stringify(l.body):void 0,credentials:"omit"});}catch(P){throw new a$1("network",`Could not reach ${e}${d} \u2014 is the instance running, and is this site's origin on its allowed origins?`,{cause:P})}if(!w.ok){let P;try{P=await w.json();}catch{P=void 0;}let L=P?.why??P?.message??w.statusText;throw new a$1("http",`${l?.method??"GET"} ${d}: ${L}`,{status:w.status,details:P})}return await w.json()}a(b,"request");function p(d){return {shareUrl:`${e}${m}/configuration/${d}`,viewUrl:`${e}${m}/configuration/${d}/view`}}a(p,"links");function C(){return y??=b("/api/product-lines/active").then(d=>d.map(l=>de(e,l))).catch(d=>{throw y=null,d}),y}a(C,"productLines");async function x(d){let l=await C(),I=typeof d=="string"?d.trim().toLowerCase():d,w=l.find(P=>P.id===I||String(P.id)===I)??l.find(P=>P.slug===I)??l.find(P=>typeof I=="string"&&G(P.name)===G(I));if(!w){let P=l.map(L=>L.slug).join(", ");throw new a$1("unknown_product_line",`No product line "${d}" (${P})`)}return w}a(x,"productLine");function O(d){return x(d).then(l=>{let I=h.get(l.id);return I||(I=Promise.all([b(`/api/product-lines/${l.id}/modules`),b("/api/parts"),b("/api/surfaces"),b("/api/surface-groups"),b("/api/rules").catch(()=>[])]).then(([w,P,L,R,v])=>ce(e,l,{modules:w,parts:P,surfaces:L,surfaceGroups:R,rules:v})),I.catch(()=>h.delete(l.id)),h.set(l.id,I)),I})}a(O,"catalog");async function A(d){let l=await b(`/api/saved-configurations/${encodeURIComponent(d)}`),I=[...l.versions??[]].sort((L,R)=>R.versionNumber-L.versionNumber),w=I.find(L=>L.versionNumber===l.currentVersionNumber)??I[0];if(!w)throw new a$1("invalid_state",`Configuration ${d} has no saved version`);let P=JSON.parse(w.configurationJson);return {id:l.id,displayId:l.displayId??null,name:l.name,productLineId:P.productLineId??l.productLineId??null,state:P,...p(l.id)}}a(A,"getConfiguration");async function k(d,l){let I=await b("/api/saved-configurations",{method:"POST",body:{name:l,status:"public",configurationJson:JSON.stringify(d),remoteProductLineId:d.productLineId}});return {id:I.id,displayId:I.displayId??null,...p(I.id)}}a(k,"saveConfiguration");async function $(d,l){let[I,...w]=(l.name??"").trim().split(/\s+/),P=Object.entries(l.extra??{}).filter(([,v])=>v!=null&&v!=="").map(([v,V])=>`${v}: ${V}`),L=[l.message?.trim(),P.join(`
|
|
2
|
+
`)].filter(Boolean).join(`
|
|
3
|
+
|
|
4
|
+
`),R=await b("/api/inquiries",{method:"POST",body:{projectJson:JSON.stringify(d),remoteProductLineId:d.productLineId,contactSnapshot:{email:l.email,...I&&{firstName:I},...w.length>0&&{lastName:w.join(" ")},...l.phone&&{phone:l.phone},...l.company&&{companyName:l.company}},note:L||void 0,state:"submitted"}});return {id:R.id,displayId:R.displayId??null}}a($,"submitInquiry");async function N(d){return b("/api/leads",{method:"POST",body:{data:d.data,gateKey:d.gateKey,configId:d.configurationId,locale:o}})}a(N,"submitLead");async function X(d){let l,I;if("configuration"in d){let w=await A(d.configuration);if(w.productLineId==null)throw new a$1("invalid_state",`Configuration ${w.id} has no product line`);l=w.state,I=w.productLineId;}else l=d.state,I=d.productLine;return be({catalog:await O(I),locale:o,instance:e,module:"module"in d?d.module:void 0,state:l,save:k,submitInquiry:$})}return a(X,"configurator"),{instance:e,locale:o,productLines:C,productLine:x,catalog:O,configurator:X,getConfiguration:A,saveConfiguration:k,submitInquiry:$,submitLead:N}}a(Ke,"createKonfigureClient");export{Ke as createKonfigureClient};
|