@shopware/helpers 0.0.0-canary-20250116171244

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 ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2022-2023 Shopware
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,45 @@
1
+ # shopware/frontends - helpers
2
+
3
+ Welcome to `@shopware/helpers` package.
4
+
5
+ For getting started documentation visit [https://frontends.shopware.com/](https://frontends.shopware.com/)
6
+
7
+ Documentation specific for this package: [helpers](https://frontends.shopware.com/packages/helpers.html)
8
+
9
+ ## Reusable classes
10
+
11
+ The `helpersCssClasses` variable, defined in the `cms/layoutClasses.ts` helper file, comprises an array of class names utilized within the CMS.
12
+
13
+ To enhance type support, a union type `HelpersCssClasses` is defined, which encompasses all class names present in the `helpersCssClasses` array.
14
+
15
+ ```ts
16
+ const visibilityMap: Record<CmsVisibility, HelpersCssClasses> = {
17
+ mobile: "max-md:hidden",
18
+ tablet: "md:max-lg:hidden",
19
+ desktop: "lg:hidden",
20
+ };
21
+ ```
22
+
23
+ These classes can be integrated into a custom template, thereby ensuring consistency across different packages. For example as a `safelist` classes in unocss configuration file
24
+
25
+ ```ts
26
+ import { helpersCssClasses } from "@shopware/helpers";
27
+
28
+ export default defineConfig({
29
+ safelist: helpersCssClasses,
30
+ });
31
+ ```
32
+
33
+ <!-- AUTO GENERATED CHANGELOG -->
34
+
35
+ ## Changelog
36
+
37
+ Full changelog for stable version is available [here](https://github.com/shopware/frontends/blob/main/packages/helpers/CHANGELOG.md)
38
+
39
+ ### Latest changes: 0.0.0-canary-20250116171244
40
+
41
+ ### Minor Changes
42
+
43
+ - [#1602](https://github.com/shopware/frontends/pull/1602) [`bb7d1cb`](https://github.com/shopware/frontends/commit/bb7d1cbc4204ff1d48f77416f94f550bc235e5ed) Thanks [@patzick](https://github.com/patzick)! - Switch from `@shopware-pwa/helpers-next` to `@shopware/helpers` package.
44
+
45
+ - [#1602](https://github.com/shopware/frontends/pull/1602) [`bb7d1cb`](https://github.com/shopware/frontends/commit/bb7d1cbc4204ff1d48f77416f94f550bc235e5ed) Thanks [@patzick](https://github.com/patzick)! - Switch from `@shopware-pwa/cms-base` to `@shopware/cms-base-layer` package.
@@ -0,0 +1,617 @@
1
+ /**
2
+ * Get product free shipping property
3
+ *
4
+ * @param {Product} product product entity
5
+ * @returns {boolean} product free shipping
6
+ *
7
+ * @public
8
+ *
9
+ * @category Product
10
+ */
11
+ declare function getProductFreeShipping<T extends {
12
+ shippingFree: boolean;
13
+ }>(product?: T): boolean;
14
+
15
+ /**
16
+ * gets the cover image
17
+ *
18
+ * @param {Product | LineItem | OrderLineItem} object Object containing media object
19
+ *
20
+ * @public
21
+ *
22
+ * @category Product
23
+ */
24
+ declare function getMainImageUrl<T extends {
25
+ cover?: {
26
+ media?: {
27
+ url: string;
28
+ };
29
+ };
30
+ } | {
31
+ media?: Array<{
32
+ media?: {
33
+ url?: string;
34
+ };
35
+ }>;
36
+ } | {
37
+ cover?: {
38
+ url: string;
39
+ };
40
+ }>(object: T): string;
41
+
42
+ /**
43
+ * @beta
44
+ *
45
+ * @param {Product} product product entity
46
+ *
47
+ * @category Product
48
+ */
49
+ declare function getProductName<T extends {
50
+ name: string;
51
+ }>({ product }?: {
52
+ product?: T;
53
+ }): string | null;
54
+
55
+ /**
56
+ * @public
57
+ */
58
+ type UiMediaGalleryItemUrl = {
59
+ url: string;
60
+ };
61
+ /**
62
+ * @public
63
+ */
64
+ type UiMediaGalleryItem = {
65
+ icon: UiMediaGalleryItemUrl;
66
+ mobile: UiMediaGalleryItemUrl;
67
+ desktop: UiMediaGalleryItemUrl;
68
+ };
69
+ /**
70
+ * @public
71
+ */
72
+ type UiProductOption = {
73
+ label: string;
74
+ value: string;
75
+ code: string;
76
+ color: string | null;
77
+ };
78
+ /**
79
+ * @public
80
+ */
81
+ type UiProductProperty = {
82
+ name: string;
83
+ value: string | null;
84
+ };
85
+ /**
86
+ * @public
87
+ */
88
+ type UiProductReview = {
89
+ id: string;
90
+ author?: string;
91
+ date: string;
92
+ message?: string;
93
+ rating?: number;
94
+ };
95
+
96
+ /**
97
+ * Format product reviews to ui-interfaces
98
+ *
99
+ * @param {Product} product product entity
100
+ *
101
+ * @public
102
+ *
103
+ * @category Product
104
+ */
105
+ declare function getProductReviews<T extends {
106
+ id: string;
107
+ productReviews?: Array<{
108
+ id: string;
109
+ externalUser?: string;
110
+ customerId?: string;
111
+ createdAt: string;
112
+ content: string;
113
+ points?: number;
114
+ }>;
115
+ }>({ product }?: {
116
+ product?: T;
117
+ }): UiProductReview[];
118
+
119
+ /**
120
+ * @beta
121
+ */
122
+ type TierPrice = {
123
+ label: string;
124
+ quantity: number;
125
+ unitPrice: number;
126
+ };
127
+ /**
128
+ * Get the prices depending on quantity added to cart.
129
+ * Tier prices can be set in `Advanced pricing` tab in `Product view` (admin panel)
130
+ *
131
+ * @param {Product} product product entity
132
+ *
133
+ * @returns TierPrice[]
134
+ * @beta
135
+ */
136
+ declare function getProductTierPrices<T extends {
137
+ calculatedPrices?: Array<{
138
+ unitPrice: number;
139
+ quantity: number;
140
+ }>;
141
+ }>(product?: T): TierPrice[];
142
+
143
+ /**
144
+ * Get product url. The priority is SEO url and then technical url.
145
+ *
146
+ * @param {Product} product product entity
147
+ *
148
+ * @public
149
+ *
150
+ * @category Product
151
+ */
152
+ declare function getProductUrl<T extends {
153
+ id: string;
154
+ seoUrls?: Array<{
155
+ seoPathInfo?: string;
156
+ }>;
157
+ }>(product?: T): string;
158
+
159
+ /**
160
+ * Get product rating average property
161
+ *
162
+ * @param product product entity
163
+ *
164
+ * @public
165
+ *
166
+ * @category Product
167
+ *
168
+ * @returns {number | null} product rating average
169
+ */
170
+ declare function getProductRatingAverage<T extends {
171
+ ratingAverage: number;
172
+ }>(product: T): number | null;
173
+
174
+ type CalculatedPrice$1 = {
175
+ unitPrice?: number;
176
+ listPrice?: {
177
+ price: number;
178
+ };
179
+ };
180
+ /**
181
+ * Get the calculated list price
182
+ *
183
+ * @param {ProductWithCalculatedPrice} product product entity
184
+ * @returns (number|undefined)
185
+ *
186
+ * @beta
187
+ */
188
+ declare function getProductCalculatedListingPrice<T extends {
189
+ calculatedPrice?: CalculatedPrice$1;
190
+ calculatedPrices?: CalculatedPrice$1[];
191
+ }>(product?: T): number | undefined;
192
+
193
+ type CalculatedPrice = {
194
+ unitPrice: number;
195
+ };
196
+ /**
197
+ *
198
+ * @param {ProductWithCalculatedPrice} product product entity
199
+ *
200
+ * @returns {number | undefined} product fromPrice
201
+ * @category Product
202
+ */
203
+ declare function getProductFromPrice<T extends {
204
+ calculatedPrice?: CalculatedPrice;
205
+ calculatedPrices?: CalculatedPrice[];
206
+ }>(product: T): number | undefined;
207
+
208
+ /**
209
+ * Get product route information for Vue router.
210
+ *
211
+ * Returns product URL and route informations for resolving SEO url.
212
+ * Use it with combination of `<RouterLink>` or `<NuxtLink>` in Vue.js or Nuxt.js projects.
213
+ *
214
+ * @public
215
+ * @category Product
216
+ * @category Routing
217
+ */
218
+ declare function getProductRoute<T extends {
219
+ id: string;
220
+ seoUrls?: Array<{
221
+ seoPathInfo?: string;
222
+ }>;
223
+ }>(product?: T): {
224
+ path: string;
225
+ state: {
226
+ routeName: string;
227
+ foreignKey: string | undefined;
228
+ };
229
+ };
230
+
231
+ /**
232
+ * Get URL for category.
233
+ * Some link {@link isLinkCategory}
234
+ *
235
+ * @param {Category} category category entity
236
+ *
237
+ * @public
238
+ */
239
+ declare function getCategoryUrl<T extends {
240
+ type: string;
241
+ externalLink?: string;
242
+ seoUrls?: {
243
+ seoPathInfo: string;
244
+ }[];
245
+ internalLink?: string;
246
+ id: string;
247
+ linkType?: string;
248
+ }>(category: T): string;
249
+
250
+ /**
251
+ * gets the cover image
252
+ *
253
+ * @param {Category} category category entity
254
+ *
255
+ * @public
256
+ */
257
+ declare function getCategoryImageUrl<T extends {
258
+ media?: {
259
+ url: string;
260
+ };
261
+ type: string;
262
+ }>(category: T): string;
263
+
264
+ /**
265
+ * Gather breadcrumbs from category
266
+ *
267
+ */
268
+ declare function getCategoryBreadcrumbs<T extends {
269
+ translated?: {
270
+ breadcrumb?: string[];
271
+ };
272
+ breadcrumb?: string[];
273
+ }>(category: T, options?: {
274
+ /**
275
+ * Start at specific index if your navigation
276
+ * contains root names which should not be visible.
277
+ */
278
+ startIndex?: number;
279
+ }): {
280
+ name: string;
281
+ }[];
282
+
283
+ /**
284
+ * Get category/navigation route information for Vue Router.
285
+ *
286
+ * Returns category or navigation URL and route informations for resolving SEO url.
287
+ * Use it with combination of `<RouterLink>` or `<NuxtLink>` in Vue.js or Nuxt.js projects.
288
+ *
289
+ * Example:
290
+ * ```html
291
+ * <RouterLink :to="getCategoryRoute(navigationElement)">
292
+ * ```
293
+ *
294
+ * @public
295
+ * @category Category
296
+ * @category Routing
297
+ */
298
+ declare function getCategoryRoute<T extends {
299
+ type: string;
300
+ externalLink?: string;
301
+ seoUrls?: {
302
+ seoPathInfo: string;
303
+ }[];
304
+ internalLink?: string;
305
+ id: string;
306
+ linkType?: string;
307
+ }>(category: T): string | {
308
+ path: string;
309
+ state: {
310
+ routeName: string;
311
+ foreignKey: string | undefined;
312
+ };
313
+ };
314
+
315
+ type GenericCms = {
316
+ visibility?: {
317
+ [key in CmsVisibility]?: boolean;
318
+ };
319
+ cssClass?: string | null;
320
+ backgroundColor?: string | null;
321
+ backgroundMedia?: {
322
+ url: string;
323
+ } | null;
324
+ backgroundMediaMode?: string | null;
325
+ sizingMode?: string | null;
326
+ marginBottom?: string | null;
327
+ marginLeft?: string | null;
328
+ marginRight?: string | null;
329
+ marginTop?: string | null;
330
+ };
331
+ type CmsBlock = GenericCms & {
332
+ apiAlias: "cms_block";
333
+ };
334
+ type CmsSection = GenericCms & {
335
+ apiAlias: "cms_section";
336
+ };
337
+ type CmsSlot = GenericCms & {
338
+ apiAlias: "cms_slot";
339
+ };
340
+ type CmsVisibility = "mobile" | "tablet" | "desktop" | string;
341
+ /**
342
+ * @beta
343
+ */
344
+ type LayoutConfiguration = {
345
+ layoutStyles: {
346
+ backgroundColor?: string | null;
347
+ backgroundImage?: string | null;
348
+ backgroundSize?: string | null;
349
+ sizingMode?: string | null;
350
+ marginBottom?: string | null | undefined;
351
+ marginLeft?: string | null | undefined;
352
+ marginRight?: string | null | undefined;
353
+ marginTop?: string | null | undefined;
354
+ };
355
+ cssClasses: {
356
+ [cssClass: string]: boolean;
357
+ } | null;
358
+ };
359
+ /**
360
+ * Get layout configuration for CMS content
361
+ *
362
+ * @param content CMS content
363
+ *
364
+ * @category CMS (Shopping Experiences)
365
+ */
366
+ declare function getCmsLayoutConfiguration<T extends CmsBlock | CmsSection | CmsSlot>(content: T): LayoutConfiguration;
367
+
368
+ declare function getBackgroundImageUrl<T extends {
369
+ backgroundMedia?: {
370
+ metaData?: {
371
+ width?: number;
372
+ height?: number;
373
+ };
374
+ };
375
+ }>(url: string, element: T): string;
376
+
377
+ type UrlRoute = {
378
+ path?: string;
379
+ state?: {
380
+ routeName?: string;
381
+ foreignKey?: string;
382
+ };
383
+ };
384
+ type UrlRouteOutput = Omit<UrlRoute, "path"> & {
385
+ path: string;
386
+ };
387
+ declare function buildUrlPrefix(url: string | UrlRoute, prefix: string): UrlRouteOutput;
388
+
389
+ declare const helpersCssClasses: string[];
390
+ type HelpersCssClasses = (typeof helpersCssClasses)[number];
391
+
392
+ declare function isMaintenanceMode<T extends {
393
+ code?: string;
394
+ }>(errors: [T]): boolean;
395
+
396
+ /**
397
+ * Replace text placeholder with param value
398
+ *
399
+ * @param {string} key
400
+ * @param {} params
401
+ * @returns {string}
402
+ */
403
+ declare function getCmsTranslate(key: string, params?: {
404
+ [key: string]: string | number | null | undefined;
405
+ } | null): string;
406
+
407
+ /**
408
+ * Build the breadcrumbs for the CMS page
409
+ *
410
+ * @param page
411
+ * @returns
412
+ */
413
+ declare function getCmsBreadcrumbs<T extends {
414
+ translated: {
415
+ name: string;
416
+ };
417
+ }>(page: T): {
418
+ name: string;
419
+ }[];
420
+
421
+ type Category = {
422
+ apiAlias: "category";
423
+ };
424
+ type LandingPage = {
425
+ apiAlias: "landing_page";
426
+ };
427
+ type Product = {
428
+ apiAlias: "product";
429
+ media?: {
430
+ thumbnails?: Array<{
431
+ width: number;
432
+ url: string;
433
+ }>;
434
+ };
435
+ };
436
+ type CmsPageResponse = {
437
+ resourceType: "frontend.navigation.page" | "frontend.detail.page" | "frontend.landing.page";
438
+ product: Product;
439
+ category: Category;
440
+ landingPage: LandingPage;
441
+ };
442
+
443
+ /**
444
+ * Returns the main page object depending of the type of the CMS page.
445
+ *
446
+ * @category CMS (Shopping Experiences)
447
+ */
448
+ declare function getCmsEntityObject(response: CmsPageResponse): Product | Category | LandingPage;
449
+ /**
450
+ * Predicate function to check if the entity is a product.
451
+ *
452
+ * @category CMS (Shopping Experiences)
453
+ */
454
+ declare function isProduct<T extends {
455
+ apiAlias: string;
456
+ }>(entity: T | Product): entity is Product;
457
+ declare function isCategory<T extends {
458
+ apiAlias: string;
459
+ }>(entity: T | Category): entity is Category;
460
+ declare function isLandingPage<T extends {
461
+ apiAlias: string;
462
+ }>(entity: T | LandingPage): entity is LandingPage;
463
+
464
+ /**
465
+ * Get translated property from the given object.
466
+ *
467
+ * @param {T} element object with translated property
468
+ *
469
+ * @public
470
+ */
471
+ declare function getTranslatedProperty<T>(element: T | undefined | null | never, property: keyof T): string;
472
+
473
+ type ListingFilter = {
474
+ label: string;
475
+ code: string;
476
+ id: string;
477
+ name: string;
478
+ };
479
+ /**
480
+ * @beta
481
+ */
482
+ declare function getListingFilters<T extends Record<string, any>>(aggregations: T | undefined | null): ListingFilter[];
483
+
484
+ type Options = {
485
+ direction?: "ltr" | "rtl";
486
+ removeDecimals?: boolean;
487
+ removeCurrency?: boolean;
488
+ };
489
+ /**
490
+ * Get formatted price
491
+ *
492
+ * @param value price value
493
+ * @param currency currency symbol
494
+ * @param options formatting options (direction, removeDecimals, removeCurrency)
495
+ *
496
+ * @public
497
+ */
498
+ declare function getFormattedPrice(value: string | number, currency: string, options?: Options): string;
499
+
500
+ /**
501
+ * Download file
502
+ *
503
+ */
504
+ declare function downloadFile<T>(file: T, name: string): void;
505
+
506
+ /**
507
+ * Returns the biggest thumbnail url from the media object
508
+ *
509
+ * @param media image object
510
+ *
511
+ * @public
512
+ * @category Media
513
+ */
514
+ declare function getBiggestThumbnailUrl<T extends {
515
+ thumbnails?: Array<{
516
+ width: number;
517
+ url: string;
518
+ }>;
519
+ }>(media?: T): string | undefined;
520
+
521
+ type ProductMedia = {
522
+ id: string;
523
+ fileName: string;
524
+ accessGranted: boolean;
525
+ };
526
+ /**
527
+ * Prepare media object
528
+ *
529
+ * @param {OrderLineItem} lineItem order item
530
+ *
531
+ * @public
532
+ * @category Media
533
+ */
534
+ declare function getMedia<T extends {
535
+ downloads?: Array<{
536
+ id: string;
537
+ accessGranted: boolean;
538
+ media: {
539
+ fileName: string;
540
+ fileExtension: string;
541
+ };
542
+ }>;
543
+ }>(lineItem: T): ProductMedia[];
544
+
545
+ /**
546
+ * Returns the smallest thumbnail url from the media object
547
+ *
548
+ * @param media image object
549
+ *
550
+ * @public
551
+ * @category Media
552
+ */
553
+ declare function getSmallestThumbnailUrl<T extends {
554
+ thumbnails?: Array<{
555
+ width: number;
556
+ url: string;
557
+ }>;
558
+ }>(media?: T): string | undefined;
559
+
560
+ /**
561
+ * Returns the srcset attribute for the image, for available breakpoints
562
+ *
563
+ * @param media image object
564
+ *
565
+ * @public
566
+ * @category Media
567
+ */
568
+ declare function getSrcSetForMedia<T extends {
569
+ thumbnails?: Array<{
570
+ width: number;
571
+ url: string;
572
+ }>;
573
+ }>(media?: T): string | undefined;
574
+
575
+ /**
576
+ * Get shipping delivery time
577
+ *
578
+ */
579
+ declare function getShippingMethodDeliveryTime<T extends {
580
+ deliveryTime?: {
581
+ translated: {
582
+ name: string;
583
+ };
584
+ };
585
+ }>(shippingMethod: T): string | undefined;
586
+
587
+ /**
588
+ * Get translated language name
589
+ *
590
+ * @param {Language} language
591
+ * @returns {string}
592
+ */
593
+ declare function getLanguageName<T extends {
594
+ translationCode?: {
595
+ translated: {
596
+ name: string;
597
+ };
598
+ };
599
+ }>(language: T): string;
600
+
601
+ /**
602
+ * Add/remove slash from the relative path
603
+ *
604
+ * @param {string} relativeUrl
605
+ * @param {boolean} slash
606
+ */
607
+ declare function relativeUrlSlash(relativeUrl: string, slash?: boolean): string;
608
+
609
+ declare function urlIsAbsolute(url: string): boolean;
610
+
611
+ declare function canUseQuoteActions<T extends {
612
+ stateMachineState?: {
613
+ technicalName: string;
614
+ };
615
+ }>(quote: T): boolean;
616
+
617
+ export { type HelpersCssClasses, type LayoutConfiguration, type TierPrice, type UiMediaGalleryItem, type UiMediaGalleryItemUrl, type UiProductOption, type UiProductProperty, type UiProductReview, buildUrlPrefix, canUseQuoteActions, downloadFile, getBackgroundImageUrl, getBiggestThumbnailUrl, getCategoryBreadcrumbs, getCategoryImageUrl, getCategoryRoute, getCategoryUrl, getCmsBreadcrumbs, getCmsEntityObject, getCmsLayoutConfiguration, getCmsTranslate, getFormattedPrice, getLanguageName, getListingFilters, getMainImageUrl, getMedia, getProductCalculatedListingPrice, getProductFreeShipping, getProductFromPrice, getProductName, getProductRatingAverage, getProductReviews, getProductRoute, getProductTierPrices, getProductUrl, getShippingMethodDeliveryTime, getSmallestThumbnailUrl, getSrcSetForMedia, getTranslatedProperty, helpersCssClasses, isCategory, isLandingPage, isMaintenanceMode, isProduct, relativeUrlSlash, urlIsAbsolute };