@momentum-design/components 0.116.2 → 0.117.0

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 (44) hide show
  1. package/dist/browser/index.js +315 -307
  2. package/dist/browser/index.js.map +4 -4
  3. package/dist/components/icon/icon.utils.d.ts +1 -1
  4. package/dist/components/icon/icon.utils.js +2 -2
  5. package/dist/components/iconprovider/iconprovider.component.d.ts +3 -1
  6. package/dist/components/iconprovider/iconprovider.component.js +1 -1
  7. package/dist/components/iconprovider/iconprovider.constants.d.ts +0 -1
  8. package/dist/components/iconprovider/iconprovider.constants.js +0 -1
  9. package/dist/components/illustration/illustration.component.d.ts +91 -0
  10. package/dist/components/illustration/illustration.component.js +220 -0
  11. package/dist/components/illustration/illustration.constants.d.ts +5 -0
  12. package/dist/components/illustration/illustration.constants.js +6 -0
  13. package/dist/components/illustration/illustration.styles.d.ts +2 -0
  14. package/dist/components/illustration/illustration.styles.js +15 -0
  15. package/dist/components/illustration/illustration.types.d.ts +2 -0
  16. package/dist/components/illustration/illustration.types.js +1 -0
  17. package/dist/components/illustration/illustration.utils.d.ts +32 -0
  18. package/dist/components/illustration/illustration.utils.js +79 -0
  19. package/dist/components/illustration/index.d.ts +7 -0
  20. package/dist/components/illustration/index.js +4 -0
  21. package/dist/components/illustrationprovider/illustrationprovider.component.d.ts +97 -0
  22. package/dist/components/illustrationprovider/illustrationprovider.component.js +123 -0
  23. package/dist/components/illustrationprovider/illustrationprovider.constants.d.ts +7 -0
  24. package/dist/components/illustrationprovider/illustrationprovider.constants.js +8 -0
  25. package/dist/components/illustrationprovider/illustrationprovider.context.d.ts +12 -0
  26. package/dist/components/illustrationprovider/illustrationprovider.context.js +7 -0
  27. package/dist/components/illustrationprovider/illustrationprovider.types.d.ts +3 -0
  28. package/dist/components/illustrationprovider/illustrationprovider.types.js +1 -0
  29. package/dist/components/illustrationprovider/index.d.ts +7 -0
  30. package/dist/components/illustrationprovider/index.js +4 -0
  31. package/dist/custom-elements.json +2593 -2259
  32. package/dist/index.d.ts +5 -3
  33. package/dist/index.js +5 -3
  34. package/dist/react/iconprovider/index.d.ts +1 -1
  35. package/dist/react/iconprovider/index.js +1 -1
  36. package/dist/react/illustration/index.d.ts +40 -0
  37. package/dist/react/illustration/index.js +49 -0
  38. package/dist/react/illustrationprovider/index.d.ts +31 -0
  39. package/dist/react/illustrationprovider/index.js +40 -0
  40. package/dist/react/index.d.ts +4 -2
  41. package/dist/react/index.js +4 -2
  42. package/dist/utils/{icon-cache → assets-cache}/index.d.ts +2 -2
  43. package/dist/utils/{icon-cache → assets-cache}/index.js +3 -3
  44. package/package.json +1 -1
@@ -0,0 +1,123 @@
1
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
6
+ };
7
+ var __metadata = (this && this.__metadata) || function (k, v) {
8
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
9
+ };
10
+ import { property } from 'lit/decorators.js';
11
+ import { Provider } from '../../models';
12
+ import IllustrationProviderContext from './illustrationprovider.context';
13
+ import { ALLOWED_FILE_EXTENSIONS, DEFAULTS } from './illustrationprovider.constants';
14
+ /**
15
+ * IllustrationProvider component, which allows to be consumed from sub components
16
+ * (see `providerUtils.consume` for how to consume)
17
+ *
18
+ * Attribute `illustrationSet` can be set to either `momentum-illustrations` or `custom-illustrations`.
19
+ * If `momentum-illustrations` is selected, the illustrations will be fetched from the
20
+ * Momentum Design System illustration set per a dynamic JS Import (no need to provide a URL).
21
+ * This requires the consumer to have the `@momentum-design/illustrations` package installed and the
22
+ * build tooling needs to support dynamic imports.
23
+ *
24
+ * If `custom-illustrations` is selected, the illustrations will be fetched from the provided URL.
25
+ * This requires the consumer to provide a URL from which the illustrations will be fetched and
26
+ * the consumer needs to make sure to bundle the illustrations in the application.
27
+ *
28
+ * If `cacheStrategy` is provided (only works with illustrationSet = `custom-illustrations`), the
29
+ * IllustrationProvider will cache the illustrations in the selected cache (either web-api-cache or in-memory-cache),
30
+ * to avoid fetching the same illustration multiple times over the network.
31
+ * This is useful when the same illustration is used multiple times in the application.
32
+ * To consider:
33
+ * - The `in-memory-cache` is not persisted and will be lost when the
34
+ * IllustrationProvider is removed from the DOM.
35
+ * - The `web-api-cache` is persisted, but only works in https environments
36
+ * (https://developer.mozilla.org/en-US/docs/Web/API/Cache).
37
+ *
38
+ * @tagname mdc-illustrationprovider
39
+ *
40
+ * @slot - children
41
+ */
42
+ class IllustrationProvider extends Provider {
43
+ constructor() {
44
+ // initialise the context by running the Provider constructor:
45
+ super({
46
+ context: IllustrationProviderContext.context,
47
+ initialValue: new IllustrationProviderContext(),
48
+ });
49
+ /**
50
+ * Illustration set to be used
51
+ *
52
+ * If `momentum-illustrations` is selected, the illustrations will be fetched from the
53
+ * Momentum Design System illustration set per a dynamic JS Import (no need to provide a URL).
54
+ * This requires the consumer to have the `@momentum-designs` package installed and the
55
+ * build tooling needs to support dynamic imports.
56
+ *
57
+ * If `custom-illustrations` is selected, the illustrations will be fetched from the provided URL.
58
+ * This requires the consumer to provide a URL from which the illustrations will be fetched and
59
+ * the consumer needs to make sure to bundle the illustrations in the application.
60
+ *
61
+ * @default momentum-illustrations
62
+ */
63
+ this.illustrationSet = DEFAULTS.ILLUSTRATION_SET;
64
+ /**
65
+ * File extension of illustrations
66
+ * (if Illustration set is `custom-illustrations`, this will be the file extension for illustrations)
67
+ * @default svg
68
+ */
69
+ this.fileExtension = DEFAULTS.FILE_EXTENSION;
70
+ }
71
+ /**
72
+ * Context object of the IllustrationProviderContext, to be consumed by child components
73
+ */
74
+ static get Context() {
75
+ return IllustrationProviderContext.context;
76
+ }
77
+ updateValuesInContext() {
78
+ // only update fileExtension on context if its an allowed fileExtension
79
+ if (this.fileExtension && ALLOWED_FILE_EXTENSIONS.includes(this.fileExtension)) {
80
+ this.context.value.fileExtension = this.fileExtension;
81
+ }
82
+ else {
83
+ // Ensure both fileExtension and context are updated to the default if its not an allowed fileExtension
84
+ this.fileExtension = DEFAULTS.FILE_EXTENSION;
85
+ this.context.value.fileExtension = DEFAULTS.FILE_EXTENSION;
86
+ }
87
+ this.context.value.illustrationSet = this.illustrationSet;
88
+ this.context.value.url = this.url;
89
+ this.context.value.cacheName = this.cacheName;
90
+ this.context.value.cacheStrategy = this.cacheStrategy;
91
+ }
92
+ updateContext() {
93
+ if (this.context.value.fileExtension !== this.fileExtension ||
94
+ this.context.value.illustrationSet !== this.illustrationSet ||
95
+ this.context.value.url !== this.url ||
96
+ this.context.value.cacheName !== this.cacheName ||
97
+ this.context.value.cacheStrategy !== this.cacheStrategy) {
98
+ this.updateValuesInContext();
99
+ this.context.updateObservers();
100
+ }
101
+ }
102
+ }
103
+ __decorate([
104
+ property({ type: String, attribute: 'illustration-set', reflect: true }),
105
+ __metadata("design:type", String)
106
+ ], IllustrationProvider.prototype, "illustrationSet", void 0);
107
+ __decorate([
108
+ property({ type: String }),
109
+ __metadata("design:type", String)
110
+ ], IllustrationProvider.prototype, "url", void 0);
111
+ __decorate([
112
+ property({ type: String, attribute: 'file-extension', reflect: true }),
113
+ __metadata("design:type", String)
114
+ ], IllustrationProvider.prototype, "fileExtension", void 0);
115
+ __decorate([
116
+ property({ type: String, attribute: 'cache-strategy' }),
117
+ __metadata("design:type", String)
118
+ ], IllustrationProvider.prototype, "cacheStrategy", void 0);
119
+ __decorate([
120
+ property({ type: String, attribute: 'cache-name' }),
121
+ __metadata("design:type", String)
122
+ ], IllustrationProvider.prototype, "cacheName", void 0);
123
+ export default IllustrationProvider;
@@ -0,0 +1,7 @@
1
+ declare const TAG_NAME: "mdc-illustrationprovider";
2
+ declare const ALLOWED_FILE_EXTENSIONS: string[];
3
+ declare const DEFAULTS: {
4
+ readonly FILE_EXTENSION: "svg";
5
+ readonly ILLUSTRATION_SET: "momentum-illustrations";
6
+ };
7
+ export { TAG_NAME, DEFAULTS, ALLOWED_FILE_EXTENSIONS };
@@ -0,0 +1,8 @@
1
+ import utils from '../../utils/tag-name';
2
+ const TAG_NAME = utils.constructTagName('illustrationprovider');
3
+ const ALLOWED_FILE_EXTENSIONS = ['svg'];
4
+ const DEFAULTS = {
5
+ FILE_EXTENSION: 'svg',
6
+ ILLUSTRATION_SET: 'momentum-illustrations',
7
+ };
8
+ export { TAG_NAME, DEFAULTS, ALLOWED_FILE_EXTENSIONS };
@@ -0,0 +1,12 @@
1
+ import type { IllustrationSet, CacheStrategy } from './illustrationprovider.types';
2
+ declare class IllustrationProviderContext {
3
+ illustrationSet?: IllustrationSet;
4
+ fileExtension?: string;
5
+ url?: string;
6
+ cacheName?: string;
7
+ cacheStrategy?: CacheStrategy;
8
+ static readonly context: {
9
+ __context__: IllustrationProviderContext;
10
+ };
11
+ }
12
+ export default IllustrationProviderContext;
@@ -0,0 +1,7 @@
1
+ import { createContext } from '@lit/context';
2
+ import { TAG_NAME } from './illustrationprovider.constants';
3
+ class IllustrationProviderContext {
4
+ }
5
+ // create typed lit context as part of the IllustrationProviderContext
6
+ IllustrationProviderContext.context = createContext(TAG_NAME);
7
+ export default IllustrationProviderContext;
@@ -0,0 +1,3 @@
1
+ type IllustrationSet = 'momentum-illustrations' | 'custom-illustrations';
2
+ type CacheStrategy = 'in-memory-cache' | 'web-cache-api';
3
+ export type { IllustrationSet, CacheStrategy };
@@ -0,0 +1,7 @@
1
+ import IllustrationProvider from './illustrationprovider.component';
2
+ export default IllustrationProvider;
3
+ declare global {
4
+ interface HTMLElementTagNameMap {
5
+ ['mdc-illustrationprovider']: IllustrationProvider;
6
+ }
7
+ }
@@ -0,0 +1,4 @@
1
+ import IllustrationProvider from './illustrationprovider.component';
2
+ import { TAG_NAME } from './illustrationprovider.constants';
3
+ IllustrationProvider.register(TAG_NAME);
4
+ export default IllustrationProvider;