@likable-hair/svelte 4.2.5 → 4.3.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 (117) hide show
  1. package/dist/components/composed/buttons/ActivableButton.svelte +25 -7
  2. package/dist/components/composed/common/HeadersDrawer.svelte +66 -28
  3. package/dist/components/composed/common/HeadersDrawer.svelte.d.ts +22 -12
  4. package/dist/components/composed/common/MenuOrDrawer.svelte +40 -12
  5. package/dist/components/composed/common/MenuOrDrawerOptions.svelte +51 -27
  6. package/dist/components/composed/common/MenuOrDrawerOptions.svelte.d.ts +15 -10
  7. package/dist/components/composed/common/QuickActions.svelte +59 -23
  8. package/dist/components/composed/common/ToolTip.svelte +51 -32
  9. package/dist/components/composed/dashboard/DashboardShaper.svelte +280 -147
  10. package/dist/components/composed/dashboard/DashboardShaper.svelte.d.ts +54 -45
  11. package/dist/components/composed/forms/AsyncAutocomplete.svelte +81 -30
  12. package/dist/components/composed/forms/AsyncAutocomplete.svelte.d.ts +12 -5
  13. package/dist/components/composed/forms/AvatarDropdown.svelte +146 -70
  14. package/dist/components/composed/forms/AvatarDropdown.svelte.d.ts +27 -22
  15. package/dist/components/composed/forms/ConfirmOrCancelButtons.svelte +65 -19
  16. package/dist/components/composed/forms/CountriesAutocomplete.svelte +33 -4
  17. package/dist/components/composed/forms/DatePickerTextField.svelte +266 -161
  18. package/dist/components/composed/forms/Dropdown.svelte +88 -21
  19. package/dist/components/composed/forms/Dropdown.svelte.d.ts +18 -13
  20. package/dist/components/composed/forms/IconsDropdown.svelte +85 -40
  21. package/dist/components/composed/forms/IconsDropdown.svelte.d.ts +15 -8
  22. package/dist/components/composed/forms/LabelAndSelect.svelte +46 -5
  23. package/dist/components/composed/forms/LabelAndTextField.svelte +56 -3
  24. package/dist/components/composed/forms/PeriodPicker.svelte +38 -18
  25. package/dist/components/composed/forms/PeriodPicker.svelte.d.ts +32 -7
  26. package/dist/components/composed/forms/PeriodSelector.svelte +427 -312
  27. package/dist/components/composed/forms/PeriodSelector.svelte.d.ts +20 -13
  28. package/dist/components/composed/forms/ToggleList.svelte +71 -37
  29. package/dist/components/composed/forms/ToggleList.svelte.d.ts +14 -7
  30. package/dist/components/composed/forms/YearPickerTextField.svelte +154 -82
  31. package/dist/components/composed/list/DynamicTable.svelte +1372 -809
  32. package/dist/components/composed/list/DynamicTable.svelte.d.ts +85 -70
  33. package/dist/components/composed/list/EnhancedPaginatedTable.svelte +75 -32
  34. package/dist/components/composed/list/EnhancedPaginatedTable.svelte.d.ts +16 -6
  35. package/dist/components/composed/list/PaginatedTable.svelte +324 -116
  36. package/dist/components/composed/list/PaginatedTable.svelte.d.ts +26 -22
  37. package/dist/components/composed/progress/HorizontalStackedProgress.svelte +67 -29
  38. package/dist/components/composed/search/DynamicFilters.svelte +126 -91
  39. package/dist/components/composed/search/FilterEditor.svelte +169 -109
  40. package/dist/components/composed/search/Filters.svelte +385 -275
  41. package/dist/components/composed/search/GlobalSearchTextField.svelte +102 -42
  42. package/dist/components/composed/search/GlobalSearchTextField.svelte.d.ts +23 -20
  43. package/dist/components/composed/search/MobileFilterEditor.svelte +174 -120
  44. package/dist/components/composed/search/QuickFilters.svelte +124 -75
  45. package/dist/components/composed/search/SearchBar.svelte +42 -3
  46. package/dist/components/composed/search/SearchResults.svelte +48 -5
  47. package/dist/components/composed/search/SearchResults.svelte.d.ts +17 -17
  48. package/dist/components/layouts/CollapsibleSideBarLayout.svelte +100 -24
  49. package/dist/components/layouts/StableDividedSideBarLayout.svelte +74 -24
  50. package/dist/components/layouts/UnstableDividedSideBarLayout.svelte +140 -57
  51. package/dist/components/simple/buttons/Button.svelte +86 -36
  52. package/dist/components/simple/buttons/LinkButton.svelte +81 -25
  53. package/dist/components/simple/charts/BarChart.svelte +137 -105
  54. package/dist/components/simple/charts/LineChart.svelte +124 -92
  55. package/dist/components/simple/charts/PieChart.svelte +51 -23
  56. package/dist/components/simple/common/CollapsibleDivider.svelte +58 -26
  57. package/dist/components/simple/common/Divider.svelte +2 -1
  58. package/dist/components/simple/common/InfiniteScroll.svelte +60 -34
  59. package/dist/components/simple/common/MediaQuery.svelte +28 -3
  60. package/dist/components/simple/common/Menu.svelte +516 -371
  61. package/dist/components/simple/common/NoData.svelte +18 -4
  62. package/dist/components/simple/common/VerticalDraggableList.svelte +52 -26
  63. package/dist/components/simple/common/VerticalDraggableList.svelte.d.ts +20 -9
  64. package/dist/components/simple/dashboards/DashboardGridShaper.svelte +28 -22
  65. package/dist/components/simple/dates/Calendar.svelte +142 -72
  66. package/dist/components/simple/dates/DatePicker.svelte +138 -71
  67. package/dist/components/simple/dates/MonthSelector.svelte +49 -13
  68. package/dist/components/simple/dates/YearSelector.svelte +73 -30
  69. package/dist/components/simple/dialogs/Dialog.svelte +109 -59
  70. package/dist/components/simple/forms/Autocomplete.svelte +341 -164
  71. package/dist/components/simple/forms/Autocomplete.svelte.d.ts +27 -20
  72. package/dist/components/simple/forms/Checkbox.svelte +57 -29
  73. package/dist/components/simple/forms/FileInput.svelte +103 -58
  74. package/dist/components/simple/forms/FileInputList.svelte +115 -51
  75. package/dist/components/simple/forms/RadioButton.svelte +36 -3
  76. package/dist/components/simple/forms/Select.svelte +30 -3
  77. package/dist/components/simple/forms/SimpleTextField.svelte +94 -4
  78. package/dist/components/simple/forms/Switch.svelte +33 -11
  79. package/dist/components/simple/forms/Textarea.svelte +22 -5
  80. package/dist/components/simple/forms/VerticalSwitch.svelte +19 -2
  81. package/dist/components/simple/forms/VerticalTextSwitch.svelte +35 -3
  82. package/dist/components/simple/lists/BoxList.svelte +42 -11
  83. package/dist/components/simple/lists/ColorInvertedSelector.svelte +83 -25
  84. package/dist/components/simple/lists/HierarchyMenu.svelte +55 -20
  85. package/dist/components/simple/lists/Paginator.svelte +53 -34
  86. package/dist/components/simple/lists/SelectableMenuList.svelte +52 -16
  87. package/dist/components/simple/lists/SelectableVerticalList.svelte +169 -85
  88. package/dist/components/simple/lists/SelectableVerticalList.svelte.d.ts +21 -14
  89. package/dist/components/simple/lists/SidebarMenuList.svelte +127 -79
  90. package/dist/components/simple/lists/SimpleTable.svelte +442 -245
  91. package/dist/components/simple/lists/SimpleTable.svelte.d.ts +31 -22
  92. package/dist/components/simple/loaders/CircularLoader.css +1 -1
  93. package/dist/components/simple/loaders/CircularLoader.svelte +11 -3
  94. package/dist/components/simple/loaders/Skeleton.svelte +3 -2
  95. package/dist/components/simple/media/Avatar.svelte +35 -15
  96. package/dist/components/simple/media/DescriptiveAvatar.svelte +30 -4
  97. package/dist/components/simple/media/FlagIcon.svelte +13 -3
  98. package/dist/components/simple/media/Icon.svelte +21 -6
  99. package/dist/components/simple/navigation/Breadcrumb.svelte +41 -9
  100. package/dist/components/simple/navigation/Chip.svelte +65 -29
  101. package/dist/components/simple/navigation/Drawer.svelte +132 -71
  102. package/dist/components/simple/navigation/HeaderMenu.svelte +69 -25
  103. package/dist/components/simple/navigation/Navigator.svelte +45 -11
  104. package/dist/components/simple/navigation/TabSwitcher.svelte +60 -19
  105. package/dist/components/simple/notifiers/AlertBanner.svelte +59 -11
  106. package/dist/components/simple/progress/ProgressBar.svelte +26 -10
  107. package/dist/components/simple/timeline/SimpleTimeLine.svelte +52 -5
  108. package/dist/components/simple/timeline/SimpleTimeLine.svelte.d.ts +16 -9
  109. package/dist/components/simple/typography/Code.svelte +41 -12
  110. package/dist/stores/layouts/unstableSidebarOpened.d.ts +1 -1
  111. package/dist/stores/layouts/unstableSidebarOpened.js +1 -1
  112. package/dist/stores/theme.js +2 -2
  113. package/dist/utils/filters/builder.d.ts +2 -2
  114. package/dist/utils/filters/builder.js +7 -7
  115. package/dist/utils/filters/modifiers/where.d.ts +1 -1
  116. package/dist/utils/teleporter.js +4 -4
  117. package/package.json +39 -33
@@ -1,129 +1,161 @@
1
- <script lang="ts">import { Chart, Tooltip, } from 'chart.js';
2
- import 'chart.js/auto';
3
- import 'chartjs-adapter-date-fns';
4
- import lodash from 'lodash';
5
- let { data, options: userOptions, resetZoom = $bindable(), ...rest } = $props();
6
- const defaultOptions = {
1
+ <script lang="ts">
2
+ import {
3
+ Chart,
4
+ Tooltip,
5
+ type ChartData,
6
+ type ChartOptions,
7
+ } from 'chart.js';
8
+ import type { HTMLCanvasAttributes } from 'svelte/elements';
9
+ import 'chart.js/auto';
10
+ import 'chartjs-adapter-date-fns';
11
+ import lodash from 'lodash'
12
+
13
+ interface Props extends HTMLCanvasAttributes {
14
+ data: ChartData<'bar', number[], string>
15
+ options?: ChartOptions<'bar'>
16
+ resetZoom?: boolean
17
+ }
18
+
19
+ let {
20
+ data,
21
+ options: userOptions,
22
+ resetZoom = $bindable(),
23
+ ...rest
24
+ }: Props = $props();
25
+
26
+ const defaultOptions: ChartOptions<'bar'> = {
7
27
  bar: {
8
- datasets: {
9
- barPercentage: 0.9,
10
- borderRadius: 2,
11
- categoryPercentage: 0.3
12
- }
28
+ datasets: {
29
+ barPercentage: 0.9,
30
+ borderRadius: 2,
31
+ categoryPercentage: 0.3
32
+ }
13
33
  },
14
34
  indexAxis: 'x', //horizontal ? 'y' : 'x'
15
35
  responsive: true, //responsive
16
- maintainAspectRatio: true, //maintainAspectRatio
36
+ maintainAspectRatio: true, //maintainAspectRatio
17
37
  plugins: {
18
- tooltip: {
19
- displayColors: false,
20
- titleColor: undefined, //`rgb(${rgbTooltipColor})`
21
- backgroundColor: undefined, //`rgb(${rgbTooltipBackgroundColor})`
22
- titleFont: {
23
- size: 14
24
- },
25
- bodyFont: {
26
- size: 14,
27
- weight: "bold"
28
- },
29
- callbacks: {
30
- label: undefined //tooltipLabel
31
- }
38
+ tooltip: {
39
+ displayColors: false,
40
+ titleColor: undefined, //`rgb(${rgbTooltipColor})`
41
+ backgroundColor: undefined, //`rgb(${rgbTooltipBackgroundColor})`
42
+ titleFont: {
43
+ size: 14
32
44
  },
33
- legend: {
34
- display: true //showLegend
45
+ bodyFont: {
46
+ size: 14,
47
+ weight: "bold"
35
48
  },
36
- zoom: {
37
- pan: {
38
- enabled: true, //enableZoom
39
- mode: 'x',
40
- modifierKey: 'ctrl',
41
- },
42
- zoom: {
43
- drag: {
44
- enabled: true //enableZoom
45
- },
46
- mode: 'x',
47
- },
49
+ callbacks: {
50
+ label: undefined //tooltipLabel
48
51
  }
52
+ },
53
+ legend: {
54
+ display: true //showLegend
55
+ },
56
+ zoom: {
57
+ pan: {
58
+ enabled: true, //enableZoom
59
+ mode: 'x',
60
+ modifierKey: 'ctrl',
61
+ },
62
+ zoom: {
63
+ drag: {
64
+ enabled: true //enableZoom
65
+ },
66
+ mode: 'x',
67
+ },
68
+ }
49
69
  },
50
70
  interaction: {
51
- intersect: false,
71
+ intersect: false,
52
72
  },
53
73
  scales: {
54
- x: {
55
- max: undefined, //xMax
56
- display: true,
57
- title: {
58
- display: true
59
- },
60
- grid: {
61
- display: false
62
- },
63
- border: {
64
- display: false
65
- },
66
- ticks: {
67
- display: false, //showXTicks
68
- callback: undefined, //xTickLabel
69
- stepSize: undefined //xTickStepSize
70
- }
74
+ x: {
75
+ max: undefined, //xMax
76
+ display: true,
77
+ title: {
78
+ display: true
79
+ },
80
+ grid: {
81
+ display: false
82
+ },
83
+ border: {
84
+ display: false
85
+ },
86
+ ticks: {
87
+ display: false, //showXTicks
88
+ callback: undefined, //xTickLabel
89
+ stepSize: undefined //xTickStepSize
90
+ }
91
+ },
92
+ y: {
93
+ max: undefined, //yMax
94
+ display: true, //displayYGrid
95
+ title: {
96
+ },
97
+ grid: {
98
+ lineWidth: 1, //lineWidth
99
+ color: undefined, //`rgb(${rgbBackgroundColor}, .3)`
100
+ },
101
+ border: {
102
+ dash: [10,10],
103
+ display: false
71
104
  },
72
- y: {
73
- max: undefined, //yMax
74
- display: true, //displayYGrid
75
- title: {},
76
- grid: {
77
- lineWidth: 1, //lineWidth
78
- color: undefined, //`rgb(${rgbBackgroundColor}, .3)`
79
- },
80
- border: {
81
- dash: [10, 10],
82
- display: false
83
- },
84
- ticks: {
85
- display: false, //showYTicks
86
- callback: undefined, //yTickLabel
87
- stepSize: undefined //yTickStepSize
88
- }
105
+ ticks: {
106
+ display: false, //showYTicks
107
+ callback: undefined, //yTickLabel
108
+ stepSize: undefined //yTickStepSize
89
109
  }
110
+ }
90
111
  }
91
- };
92
- let options = $derived(lodash.clone(lodash.merge(defaultOptions, userOptions)));
93
- Chart.register(Tooltip);
94
- let canvasElem, chart;
95
- $effect(() => {
96
- import("chartjs-plugin-zoom").then(({ default: zoomPlugin }) => {
97
- Chart.register(zoomPlugin);
98
- setTimeout(() => {
99
- if (!!chart.resetZoom)
100
- chart.resetZoom();
101
- }, 40);
102
- });
112
+ }
113
+
114
+ let options: ChartOptions<'bar'> = $derived(
115
+ lodash.clone(lodash.merge(defaultOptions, userOptions))
116
+ )
117
+
118
+ Chart.register(Tooltip);
119
+
120
+ let canvasElem: HTMLCanvasElement,
121
+ chart: Chart;
122
+
123
+ $effect(() => {
124
+ import("chartjs-plugin-zoom").then(({ default: zoomPlugin}) => {
125
+ Chart.register(zoomPlugin)
126
+ setTimeout(() => {
127
+ if(!!chart.resetZoom)
128
+ chart.resetZoom()
129
+ }, 40);
130
+ })
131
+
103
132
  chart = new Chart(canvasElem, {
104
- type: 'bar',
105
- data,
106
- options,
107
- });
133
+ type: 'bar',
134
+ data,
135
+ options,
136
+ })
137
+
108
138
  return () => {
109
- chart.destroy();
139
+ chart.destroy();
110
140
  };
111
- });
112
- $effect(() => {
141
+ });
142
+
143
+ $effect(() => {
113
144
  if (chart) {
114
- chart.data = data;
115
- chart.update();
145
+ chart.data = data;
146
+ chart.update();
116
147
  }
117
- });
118
- $effect(() => {
119
- if (!!chart && !!resetZoom && !!chart.resetZoom) {
120
- setTimeout(() => {
121
- if (!!chart.resetZoom)
122
- chart.resetZoom();
123
- resetZoom = false;
124
- }, 40);
148
+ });
149
+
150
+ $effect(() => {
151
+ if(!!chart && !!resetZoom && !!chart.resetZoom) {
152
+ setTimeout(() => {
153
+ if(!!chart.resetZoom)
154
+ chart.resetZoom()
155
+ resetZoom = false
156
+ }, 40);
125
157
  }
126
- });
158
+ });
127
159
  </script>
128
160
 
129
161
  <canvas bind:this={canvasElem} {...rest}></canvas>
@@ -1,117 +1,149 @@
1
- <script lang="ts">import { Chart, Tooltip, } from 'chart.js';
2
- import lodash from 'lodash';
3
- import 'chart.js/auto';
4
- import 'chartjs-adapter-date-fns';
5
- let { data, options: userOptions = $bindable(), resetZoom = $bindable(), ...rest } = $props();
6
- const defaultOptions = {
1
+ <script lang="ts">
2
+ import {
3
+ Chart,
4
+ Tooltip,
5
+ type ChartData,
6
+ type ChartOptions,
7
+ } from 'chart.js';
8
+ import type { HTMLCanvasAttributes } from 'svelte/elements';
9
+ import lodash from 'lodash'
10
+ import 'chart.js/auto';
11
+ import 'chartjs-adapter-date-fns';
12
+
13
+ interface Props extends HTMLCanvasAttributes {
14
+ data: ChartData<'line', number[], string>
15
+ options: ChartOptions<'line'>
16
+ resetZoom?: boolean
17
+ }
18
+
19
+ let {
20
+ data,
21
+ options: userOptions = $bindable(),
22
+ resetZoom = $bindable(),
23
+ ...rest
24
+ }: Props = $props();
25
+
26
+ const defaultOptions: ChartOptions<'line'> = {
7
27
  indexAxis: 'x', //horizontal ? 'y' : 'x'
8
28
  responsive: true, //responsive
9
- maintainAspectRatio: true, //maintainAspectRatio
29
+ maintainAspectRatio: true, //maintainAspectRatio
10
30
  elements: {
11
- line: {
12
- borderWidth: 3 //lineWidth
13
- },
14
- point: {
15
- radius: undefined, //pointRadius
16
- hitRadius: undefined, //hitRadius
17
- hoverRadius: undefined //hoverRadius
18
- }
31
+ line: {
32
+ borderWidth: 3 //lineWidth
33
+ },
34
+ point: {
35
+ radius: undefined, //pointRadius
36
+ hitRadius: undefined, //hitRadius
37
+ hoverRadius: undefined //hoverRadius
38
+ }
19
39
  },
20
40
  plugins: {
21
- legend: {
22
- display: true //showLegend
41
+ legend: {
42
+ display: true //showLegend
43
+ },
44
+ zoom: {
45
+ pan: {
46
+ enabled: true, //enableZoom
47
+ mode: 'x',
48
+ modifierKey: 'ctrl',
23
49
  },
24
50
  zoom: {
25
- pan: {
26
- enabled: true, //enableZoom
27
- mode: 'x',
28
- modifierKey: 'ctrl',
29
- },
30
- zoom: {
31
- drag: {
32
- enabled: true //enableZoom
33
- },
34
- mode: 'x',
35
- },
51
+ drag: {
52
+ enabled: true //enableZoom
53
+ },
54
+ mode: 'x',
36
55
  },
37
- tooltip: {
38
- enabled: true //!tooltipsDisabled
39
- }
56
+ },
57
+ tooltip: {
58
+ enabled: true //!tooltipsDisabled
59
+ }
40
60
  },
41
61
  interaction: {
42
- intersect: false,
62
+ intersect: false,
43
63
  },
44
64
  scales: {
45
- x: {
46
- max: undefined, //xMax
47
- min: undefined, //xMin
48
- display: true, //displayXGrid
49
- title: {
50
- display: true
51
- },
52
- grid: {
53
- display: false
54
- },
55
- border: {
56
- display: false
57
- },
58
- ticks: {
59
- display: false, //showYTicks
60
- stepSize: undefined //yTickStepSize
61
- }
65
+ x: {
66
+ max: undefined, //xMax
67
+ min: undefined, //xMin
68
+ display: true, //displayXGrid
69
+ title: {
70
+ display: true
71
+ },
72
+ grid: {
73
+ display: false
74
+ },
75
+ border: {
76
+ display: false
77
+ },
78
+ ticks: {
79
+ display: false, //showYTicks
80
+ stepSize: undefined //yTickStepSize
81
+ }
82
+ },
83
+ y: {
84
+ max: undefined, //yMax
85
+ min: undefined, //yMin
86
+ display: true, //displayYGrid
87
+ title: {
62
88
  },
63
- y: {
64
- max: undefined, //yMax
65
- min: undefined, //yMin
66
- display: true, //displayYGrid
67
- title: {},
68
- grid: {
69
- lineWidth: 1, //gridLineWidth
70
- color: undefined, //'rgb(' + (style.getPropertyValue('--global-color-background-200') || '200, 200, 200') + ', .3)'
71
- },
72
- border: {
73
- dash: [10, 10],
74
- display: false
75
- },
76
- ticks: {
77
- display: false, //showXTicks
78
- stepSize: undefined //xTickStepSize
79
- }
89
+ grid: {
90
+ lineWidth: 1, //gridLineWidth
91
+ color: undefined, //'rgb(' + (style.getPropertyValue('--global-color-background-200') || '200, 200, 200') + ', .3)'
92
+ },
93
+ border: {
94
+ dash: [10,10],
95
+ display: false
96
+ },
97
+ ticks: {
98
+ display: false, //showXTicks
99
+ stepSize: undefined //xTickStepSize
80
100
  }
101
+ }
81
102
  }
82
- };
83
- let options = $derived(lodash.clone(lodash.merge(defaultOptions, userOptions)));
84
- Chart.register(Tooltip);
85
- let canvasElem, chart;
86
- $effect(() => {
103
+ }
104
+
105
+ let options: ChartOptions<'line'> = $derived(
106
+ lodash.clone(lodash.merge(defaultOptions, userOptions))
107
+ )
108
+
109
+ Chart.register(Tooltip);
110
+
111
+ let canvasElem: HTMLCanvasElement,
112
+ chart: Chart;
113
+
114
+ $effect(() => {
87
115
  import('chartjs-plugin-zoom').then(({ default: zoomPlugin }) => {
88
- Chart.register(zoomPlugin);
89
- setTimeout(() => {
90
- if (!!chart.resetZoom)
91
- chart.resetZoom();
92
- }, 40);
93
- });
116
+ Chart.register(zoomPlugin)
117
+ setTimeout(() => {
118
+ if(!!chart.resetZoom)
119
+ chart.resetZoom()
120
+ }, 40);
121
+ })
122
+
94
123
  chart = new Chart(canvasElem, {
95
- type: 'line',
96
- data,
97
- options,
98
- });
124
+ type: 'line',
125
+ data,
126
+ options,
127
+ })
128
+
99
129
  return () => {
100
- chart.destroy();
130
+ chart.destroy();
101
131
  };
102
- });
103
- $effect(() => {
132
+ });
133
+
134
+ $effect(() => {
104
135
  if (chart) {
105
- chart.data = data;
106
- chart.update();
136
+ chart.data = data;
137
+ chart.update();
107
138
  }
108
- });
109
- $effect(() => {
110
- if (!!chart && !!resetZoom) {
111
- chart.resetZoom();
112
- resetZoom = false;
139
+ });
140
+
141
+ $effect(() => {
142
+ if(!!chart && !!resetZoom) {
143
+ chart.resetZoom()
144
+ resetZoom = false
113
145
  }
114
- });
146
+ });
115
147
  </script>
116
148
 
117
149
  <canvas bind:this={canvasElem} {...rest}></canvas>
@@ -1,36 +1,64 @@
1
- <script lang="ts">import { Chart, Tooltip, } from 'chart.js';
2
- import lodash from 'lodash';
3
- import 'chart.js/auto';
4
- import 'chartjs-adapter-date-fns';
5
- let { data = $bindable(), options: userOptions = $bindable(), chart = $bindable(), ...rest } = $props();
6
- const defaultOptions = {
1
+ <script lang="ts">
2
+ import {
3
+ Chart,
4
+ Tooltip,
5
+ type ChartData,
6
+ type ChartOptions,
7
+ } from 'chart.js';
8
+ import type { HTMLCanvasAttributes } from 'svelte/elements';
9
+ import lodash from 'lodash'
10
+ import 'chart.js/auto';
11
+ import 'chartjs-adapter-date-fns';
12
+
13
+ interface Props extends HTMLCanvasAttributes {
14
+ data: ChartData<'pie', number[], string>;
15
+ options?: ChartOptions<'pie'>;
16
+ chart?: Chart;
17
+ }
18
+
19
+ let {
20
+ data = $bindable(),
21
+ options: userOptions = $bindable(),
22
+ chart = $bindable(),
23
+ ...rest
24
+ }: Props = $props();
25
+
26
+ const defaultOptions: ChartOptions<'pie'> = {
7
27
  responsive: true, //responsive
8
28
  maintainAspectRatio: false, //maintainAspectRatio
9
29
  plugins: {
10
- legend: {
11
- display: true //showLegend
12
- }
30
+ legend: {
31
+ display: true //showLegend
32
+ }
13
33
  }
14
- };
15
- let options = $derived(lodash.clone(lodash.merge(defaultOptions, userOptions)));
16
- Chart.register(Tooltip);
17
- let canvasElem;
18
- $effect(() => {
34
+ }
35
+
36
+ let options: ChartOptions<'pie'> = $derived(
37
+ lodash.clone(lodash.merge(defaultOptions, userOptions))
38
+ )
39
+
40
+ Chart.register(Tooltip);
41
+
42
+ let canvasElem: HTMLCanvasElement;
43
+
44
+ $effect(() => {
19
45
  chart = new Chart(canvasElem, {
20
- type: 'pie',
21
- data: data,
22
- options,
46
+ type: 'pie',
47
+ data: data,
48
+ options,
23
49
  });
50
+
24
51
  return () => {
25
- chart?.destroy();
52
+ chart?.destroy();
26
53
  };
27
- });
28
- $effect(() => {
54
+ });
55
+
56
+ $effect(() => {
29
57
  if (chart) {
30
- chart.data = data;
31
- chart.update();
58
+ chart.data = data;
59
+ chart.update();
32
60
  }
33
- });
61
+ });
34
62
  </script>
35
63
 
36
64
  <canvas bind:this={canvasElem} {...rest}></canvas>