@statistikzh/leu 0.21.0 → 0.22.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 (83) hide show
  1. package/.release-please-manifest.json +1 -1
  2. package/CHANGELOG.md +14 -0
  3. package/dist/Accordion.js +1 -1
  4. package/dist/Button.js +1 -1
  5. package/dist/ButtonGroup.js +1 -1
  6. package/dist/ChartWrapper.js +1 -1
  7. package/dist/Checkbox.js +1 -1
  8. package/dist/CheckboxGroup.js +1 -1
  9. package/dist/Chip.js +1 -1
  10. package/dist/ChipGroup.js +1 -1
  11. package/dist/ChipLink.js +1 -1
  12. package/dist/ChipRemovable.js +1 -1
  13. package/dist/ChipSelectable.js +1 -1
  14. package/dist/Dialog.js +1 -1
  15. package/dist/Dropdown.d.ts +4 -0
  16. package/dist/Dropdown.js +4 -1
  17. package/dist/FileInput.js +2 -2
  18. package/dist/Icon.js +1 -1
  19. package/dist/Input.js +1 -1
  20. package/dist/{LeuElement-BFljD2fO.js → LeuElement-BooZrClI.js} +1 -1
  21. package/dist/Menu.js +1 -1
  22. package/dist/MenuItem.js +1 -1
  23. package/dist/Message.js +1 -1
  24. package/dist/Pagination.js +1 -1
  25. package/dist/Placeholder.js +1 -1
  26. package/dist/Popup.js +1 -1
  27. package/dist/ProgressBar.js +1 -1
  28. package/dist/Radio.js +1 -1
  29. package/dist/RadioGroup.js +1 -1
  30. package/dist/Range.js +1 -1
  31. package/dist/ScrollTop.js +1 -1
  32. package/dist/Select.js +1 -1
  33. package/dist/Spinner.js +1 -1
  34. package/dist/Table.js +97 -3
  35. package/dist/Tag.js +1 -1
  36. package/dist/VisuallyHidden.js +1 -1
  37. package/dist/components/dropdown/Dropdown.d.ts +4 -0
  38. package/dist/components/dropdown/Dropdown.d.ts.map +1 -1
  39. package/dist/components/dropdown/stories/dropdown.stories.d.ts.map +1 -1
  40. package/dist/components/table/Table.d.ts.map +1 -1
  41. package/dist/index.js +2 -2
  42. package/dist/leu-accordion.js +1 -1
  43. package/dist/leu-button-group.js +1 -1
  44. package/dist/leu-button.js +1 -1
  45. package/dist/leu-chart-wrapper.js +1 -1
  46. package/dist/leu-checkbox-group.js +1 -1
  47. package/dist/leu-checkbox.js +1 -1
  48. package/dist/leu-chip-group.js +1 -1
  49. package/dist/leu-chip-link.js +1 -1
  50. package/dist/leu-chip-removable.js +1 -1
  51. package/dist/leu-chip-selectable.js +1 -1
  52. package/dist/leu-dialog.js +1 -1
  53. package/dist/leu-dropdown.js +1 -1
  54. package/dist/leu-file-input.js +2 -2
  55. package/dist/leu-icon.js +1 -1
  56. package/dist/leu-input.js +1 -1
  57. package/dist/leu-menu-item.js +1 -1
  58. package/dist/leu-menu.js +1 -1
  59. package/dist/leu-message.js +1 -1
  60. package/dist/leu-pagination.js +1 -1
  61. package/dist/leu-placeholder.js +1 -1
  62. package/dist/leu-popup.js +1 -1
  63. package/dist/leu-progress-bar.js +1 -1
  64. package/dist/leu-radio-group.js +1 -1
  65. package/dist/leu-radio.js +1 -1
  66. package/dist/leu-range.js +1 -1
  67. package/dist/leu-scroll-top.js +1 -1
  68. package/dist/leu-select.js +1 -1
  69. package/dist/leu-spinner.js +1 -1
  70. package/dist/leu-table.js +2 -2
  71. package/dist/leu-tag.js +1 -1
  72. package/dist/leu-visually-hidden.js +1 -1
  73. package/dist/lib/styleMap.d.ts +61 -0
  74. package/dist/lib/styleMap.d.ts.map +1 -0
  75. package/dist/vscode.html-custom-data.json +13 -12
  76. package/dist/vue/index.d.ts +22 -20
  77. package/dist/web-types.json +33 -28
  78. package/package.json +1 -1
  79. package/src/components/dropdown/Dropdown.ts +3 -0
  80. package/src/components/dropdown/stories/dropdown.stories.ts +6 -2
  81. package/src/components/dropdown/test/dropdown.test.ts +14 -2
  82. package/src/components/table/Table.ts +1 -1
  83. package/src/lib/styleMap.ts +139 -0
@@ -0,0 +1,139 @@
1
+ /* eslint-disable prefer-template,no-param-reassign,no-restricted-syntax,guard-for-in */
2
+
3
+ /**
4
+ * The original lit styleMap directive is not compatible with a strict style-src content security policy.
5
+ * There is an an open issue about this in the lit repository:
6
+ * https://github.com/lit/lit/issues/4719
7
+ *
8
+ * This file contains a custom implementation of the styleMap directive that bypasses
9
+ * the render method and directly updates the styles using the .style.setProperty and
10
+ * .style.removeProperty methods.
11
+ *
12
+ * In the original implementation, the render method returns a string that is set as the
13
+ * value of the style attribute. This approach is blocked by strict CSPs that disallow
14
+ * inline styles.
15
+ *
16
+ * As we don't support SSR in this library, we can safely skip the render method.
17
+ */
18
+
19
+ import { AttributePart, noChange, nothing } from "lit"
20
+ import {
21
+ directive,
22
+ Directive,
23
+ DirectiveParameters,
24
+ PartInfo,
25
+ PartType,
26
+ } from "lit/directive.js"
27
+
28
+ /**
29
+ * A key-value set of CSS properties and values.
30
+ *
31
+ * The key should be either a valid CSS property name string, like
32
+ * `'background-color'`, or a valid JavaScript camel case property name
33
+ * for CSSStyleDeclaration like `backgroundColor`.
34
+ */
35
+ export interface StyleInfo {
36
+ [name: string]: string | number | undefined | null
37
+ }
38
+
39
+ const important = "important"
40
+ // The leading space is important
41
+ const importantFlag = " !" + important
42
+ // How many characters to remove from a value, as a negative number
43
+ const flagTrim = 0 - importantFlag.length
44
+
45
+ class StyleMapDirective extends Directive {
46
+ private _previousStyleProperties?: Set<string>
47
+
48
+ constructor(partInfo: PartInfo) {
49
+ super(partInfo)
50
+ if (
51
+ partInfo.type !== PartType.ATTRIBUTE ||
52
+ partInfo.name !== "style" ||
53
+ (partInfo.strings?.length as number) > 2
54
+ ) {
55
+ throw new Error(
56
+ "The `styleMap` directive must be used in the `style` attribute " +
57
+ "and must be the only part in the attribute.",
58
+ )
59
+ }
60
+ }
61
+
62
+ render(_styleInfo: Readonly<StyleInfo>) {
63
+ return nothing
64
+ }
65
+
66
+ override update(part: AttributePart, [styleInfo]: DirectiveParameters<this>) {
67
+ const { style } = part.element as HTMLElement
68
+
69
+ if (this._previousStyleProperties === undefined) {
70
+ this._previousStyleProperties = new Set(Object.keys(styleInfo))
71
+ }
72
+
73
+ // Remove old properties that no longer exist in styleInfo
74
+ for (const name of this._previousStyleProperties) {
75
+ // If the name isn't in styleInfo or it's null/undefined
76
+ if (styleInfo[name] == null) {
77
+ this._previousStyleProperties!.delete(name)
78
+ if (name.includes("-")) {
79
+ style.removeProperty(name)
80
+ } else {
81
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
82
+ ;(style as any)[name] = null
83
+ }
84
+ }
85
+ }
86
+
87
+ // Add or update properties
88
+ for (const name in styleInfo) {
89
+ const value = styleInfo[name]
90
+ if (value != null) {
91
+ this._previousStyleProperties.add(name)
92
+ const isImportant =
93
+ typeof value === "string" && value.endsWith(importantFlag)
94
+ if (name.includes("-") || isImportant) {
95
+ style.setProperty(
96
+ name,
97
+ isImportant
98
+ ? (value as string).slice(0, flagTrim)
99
+ : (value as string),
100
+ isImportant ? important : "",
101
+ )
102
+ } else {
103
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
104
+ ;(style as any)[name] = value
105
+ }
106
+ }
107
+ }
108
+ return noChange
109
+ }
110
+ }
111
+
112
+ /**
113
+ * !A custom implementation of lit's `styleMap` directive!
114
+ * A directive that applies CSS properties to an element.
115
+ *
116
+ * `styleMap` can only be used in the `style` attribute and must be the only
117
+ * expression in the attribute. It takes the property names in the
118
+ * {@link StyleInfo styleInfo} object and adds the properties to the inline
119
+ * style of the element.
120
+ *
121
+ * Property names with dashes (`-`) are assumed to be valid CSS
122
+ * property names and set on the element's style object using `setProperty()`.
123
+ * Names without dashes are assumed to be camelCased JavaScript property names
124
+ * and set on the element's style object using property assignment, allowing the
125
+ * style object to translate JavaScript-style names to CSS property names.
126
+ *
127
+ * For example `styleMap({backgroundColor: 'red', 'border-top': '5px', '--size':
128
+ * '0'})` sets the `background-color`, `border-top` and `--size` properties.
129
+ *
130
+ * @param styleInfo
131
+ * @see {@link https://lit.dev/docs/templates/directives/#stylemap styleMap code samples on Lit.dev}
132
+ */
133
+ export const styleMap = directive(StyleMapDirective)
134
+
135
+ /**
136
+ * The type of the class that powers this directive. Necessary for naming the
137
+ * directive's return type.
138
+ */
139
+ export type { StyleMapDirective }