@conduction/nextcloud-vue 2.183.0 → 2.184.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.
@@ -0,0 +1,66 @@
1
+ /*
2
+ * SPDX-FileCopyrightText: 2026 Conduction B.V.
3
+ * SPDX-License-Identifier: EUPL-1.2
4
+ */
5
+
6
+ /**
7
+ * widgetData — a self-fetching widget tells its host what it shows.
8
+ *
9
+ * A widget that fetches its own data (CnChartWidget, CnStatsBlockWidget)
10
+ * keeps that data to itself, so a host that derives values from it (a
11
+ * dashboard's calculated fields, an export) has nothing to read. A widget
12
+ * using this mixin defines a `widgetData` computed returning a plain,
13
+ * serialisable summary of what it shows, or null while there is nothing yet;
14
+ * the mixin emits `data` with that summary whenever it changes, including the
15
+ * first time it is known.
16
+ *
17
+ * @spec openspec/changes/widget-data-event/specs/widget-data-event/spec.md#requirement-a-self-fetching-widget-tells-its-host-what-it-shows
18
+ */
19
+ export default {
20
+ emits: ['data'],
21
+
22
+ watch: {
23
+ widgetData: {
24
+ immediate: true,
25
+ /**
26
+ * Emit the summary once it is known, and on every change.
27
+ *
28
+ * @param {object|null} summary The widget's data summary.
29
+ * @return {void}
30
+ */
31
+ handler(summary) {
32
+ if (summary !== null && summary !== undefined) {
33
+ /**
34
+ * What the widget shows, as a plain summary.
35
+ *
36
+ * @event data
37
+ * @type {object}
38
+ */
39
+ this.$emit('data', summary)
40
+ }
41
+ },
42
+ },
43
+ },
44
+ }
45
+
46
+ /**
47
+ * The sum of the numbers in a chart series: a list of numbers (a pie or
48
+ * donut) or the `data` of its first named series. Non-numbers count as 0.
49
+ *
50
+ * @param {Array<number|object>|undefined} series The series.
51
+ * @return {number|null} The total, or null for no series.
52
+ * @spec openspec/changes/widget-data-event/specs/widget-data-event/spec.md#requirement-a-self-fetching-widget-tells-its-host-what-it-shows
53
+ */
54
+ export function seriesTotal(series) {
55
+ if (!Array.isArray(series) || series.length === 0) {
56
+ return null
57
+ }
58
+ const values = typeof series[0] === 'object' && series[0] !== null ? series[0].data : series
59
+ if (!Array.isArray(values)) {
60
+ return null
61
+ }
62
+ return values.reduce((sum, value) => {
63
+ const number = typeof value === 'object' && value !== null ? Number(value.y) : Number(value)
64
+ return Number.isFinite(number) ? sum + number : sum
65
+ }, 0)
66
+ }