@conduction/nextcloud-vue 2.174.0 → 2.176.1
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/dist/esm/components/CnActionDialog/CnActionDialog.vue.js +1 -1
- package/dist/esm/components/CnActionDialog/CnActionDialog.vue2.js +114 -11
- package/dist/esm/components/CnActionDialog/CnActionDialog.vue2.js.map +1 -1
- package/dist/esm/components/CnActionDialog/CnActionDialog.vue3.js +67 -17
- package/dist/esm/components/CnActionDialog/CnActionDialog.vue3.js.map +1 -1
- package/dist/esm/components/CnBlockListEditor/CnBlockListEditor.vue.js +9 -0
- package/dist/esm/components/CnBlockListEditor/CnBlockListEditor.vue.js.map +1 -0
- package/dist/esm/components/CnBlockListEditor/CnBlockListEditor.vue2.js +352 -0
- package/dist/esm/components/CnBlockListEditor/CnBlockListEditor.vue2.js.map +1 -0
- package/dist/esm/components/CnBlockListEditor/CnBlockListEditor.vue3.js +266 -0
- package/dist/esm/components/CnBlockListEditor/CnBlockListEditor.vue3.js.map +1 -0
- package/dist/esm/components/CnChecklistRunWidget/CnChecklistRunWidget.vue.js +1 -1
- package/dist/esm/components/CnChecklistRunWidget/CnChecklistRunWidget.vue2.js +323 -7
- package/dist/esm/components/CnChecklistRunWidget/CnChecklistRunWidget.vue2.js.map +1 -1
- package/dist/esm/components/CnChecklistRunWidget/CnChecklistRunWidget.vue3.js +113 -59
- package/dist/esm/components/CnChecklistRunWidget/CnChecklistRunWidget.vue3.js.map +1 -1
- package/dist/esm/components/CnChildRecordsField/CnChildRecordsField.vue.js +1 -1
- package/dist/esm/components/CnChildRecordsField/CnChildRecordsField.vue2.js +210 -5
- package/dist/esm/components/CnChildRecordsField/CnChildRecordsField.vue2.js.map +1 -1
- package/dist/esm/components/CnChildRecordsField/CnChildRecordsField.vue3.js +134 -46
- package/dist/esm/components/CnChildRecordsField/CnChildRecordsField.vue3.js.map +1 -1
- package/dist/esm/components/CnChoiceMatrix/CnChoiceMatrix.vue.js +9 -0
- package/dist/esm/components/CnChoiceMatrix/CnChoiceMatrix.vue.js.map +1 -0
- package/dist/esm/components/CnChoiceMatrix/CnChoiceMatrix.vue2.js +385 -0
- package/dist/esm/components/CnChoiceMatrix/CnChoiceMatrix.vue2.js.map +1 -0
- package/dist/esm/components/CnChoiceMatrix/CnChoiceMatrix.vue3.js +277 -0
- package/dist/esm/components/CnChoiceMatrix/CnChoiceMatrix.vue3.js.map +1 -0
- package/dist/esm/components/CnCountdownWidget/CnCountdownWidget.vue.js +1 -1
- package/dist/esm/components/CnCountdownWidget/CnCountdownWidget.vue2.js +175 -20
- package/dist/esm/components/CnCountdownWidget/CnCountdownWidget.vue2.js.map +1 -1
- package/dist/esm/components/CnCountdownWidget/CnCountdownWidget.vue3.js +30 -8
- package/dist/esm/components/CnCountdownWidget/CnCountdownWidget.vue3.js.map +1 -1
- package/dist/esm/components/CnCreateFormWidget/CnCreateFormWidget.vue.js +1 -1
- package/dist/esm/components/CnCreateFormWidget/CnCreateFormWidget.vue2.js +72 -6
- package/dist/esm/components/CnCreateFormWidget/CnCreateFormWidget.vue2.js.map +1 -1
- package/dist/esm/components/CnCreateFormWidget/CnCreateFormWidget.vue3.js +48 -14
- package/dist/esm/components/CnCreateFormWidget/CnCreateFormWidget.vue3.js.map +1 -1
- package/dist/esm/components/CnDataMatrix/CnDataMatrix.vue.js +1 -1
- package/dist/esm/components/CnDataMatrix/CnDataMatrix.vue2.js +255 -10
- package/dist/esm/components/CnDataMatrix/CnDataMatrix.vue2.js.map +1 -1
- package/dist/esm/components/CnDataMatrix/CnDataMatrix.vue3.js +70 -28
- package/dist/esm/components/CnDataMatrix/CnDataMatrix.vue3.js.map +1 -1
- package/dist/esm/components/CnDetailPage/CnDetailPage.vue2.js +55 -6
- package/dist/esm/components/CnDetailPage/CnDetailPage.vue2.js.map +1 -1
- package/dist/esm/components/CnDetailPage/CnDetailPage.vue3.js.map +1 -1
- package/dist/esm/components/CnDisplayScreen/CnDisplayScreen.vue.js +9 -0
- package/dist/esm/components/CnDisplayScreen/CnDisplayScreen.vue.js.map +1 -0
- package/dist/esm/components/CnDisplayScreen/CnDisplayScreen.vue2.js +175 -0
- package/dist/esm/components/CnDisplayScreen/CnDisplayScreen.vue2.js.map +1 -0
- package/dist/esm/components/CnDisplayScreen/CnDisplayScreen.vue3.js +114 -0
- package/dist/esm/components/CnDisplayScreen/CnDisplayScreen.vue3.js.map +1 -0
- package/dist/esm/components/CnDurationField/CnDurationField.vue.js +1 -1
- package/dist/esm/components/CnDurationField/CnDurationField.vue2.js +218 -4
- package/dist/esm/components/CnDurationField/CnDurationField.vue2.js.map +1 -1
- package/dist/esm/components/CnDurationField/CnDurationField.vue3.js +133 -44
- package/dist/esm/components/CnDurationField/CnDurationField.vue3.js.map +1 -1
- package/dist/esm/components/CnFormDialog/CnFormDialog.vue.js +1 -1
- package/dist/esm/components/CnFormDialog/CnFormDialog.vue2.js.map +1 -1
- package/dist/esm/components/CnFormDialog/CnFormDialog.vue3.js +5 -1
- package/dist/esm/components/CnFormDialog/CnFormDialog.vue3.js.map +1 -1
- package/dist/esm/components/CnGeoCaptureField/CnGeoCaptureField.vue.js +9 -0
- package/dist/esm/components/CnGeoCaptureField/CnGeoCaptureField.vue.js.map +1 -0
- package/dist/esm/components/CnGeoCaptureField/CnGeoCaptureField.vue2.js +113 -0
- package/dist/esm/components/CnGeoCaptureField/CnGeoCaptureField.vue2.js.map +1 -0
- package/dist/esm/components/CnGeoCaptureField/CnGeoCaptureField.vue3.js +43 -0
- package/dist/esm/components/CnGeoCaptureField/CnGeoCaptureField.vue3.js.map +1 -0
- package/dist/esm/components/CnIndexPage/CnIndexPage.vue2.js +40 -1
- package/dist/esm/components/CnIndexPage/CnIndexPage.vue2.js.map +1 -1
- package/dist/esm/components/CnIndexPage/CnIndexPage.vue3.js.map +1 -1
- package/dist/esm/components/CnMarkdownEditor/CnMarkdownEditor.vue.js +1 -1
- package/dist/esm/components/CnMarkdownEditor/CnMarkdownEditor.vue2.js +110 -1
- package/dist/esm/components/CnMarkdownEditor/CnMarkdownEditor.vue2.js.map +1 -1
- package/dist/esm/components/CnMarkdownEditor/CnMarkdownEditor.vue3.js +60 -18
- package/dist/esm/components/CnMarkdownEditor/CnMarkdownEditor.vue3.js.map +1 -1
- package/dist/esm/components/CnMenuTreeNode/CnMenuTreeNode.vue2.js +2 -2
- package/dist/esm/components/CnMenuTreeNode/CnMenuTreeNode.vue2.js.map +1 -1
- package/dist/esm/components/CnObjectKanban/CnObjectKanban.vue2.js +2 -2
- package/dist/esm/components/CnObjectKanban/CnObjectKanban.vue2.js.map +1 -1
- package/dist/esm/components/CnPageTreeNode/CnPageTreeNode.vue2.js +2 -2
- package/dist/esm/components/CnPageTreeNode/CnPageTreeNode.vue2.js.map +1 -1
- package/dist/esm/components/CnQrCode/CnQrCode.vue.js +9 -0
- package/dist/esm/components/CnQrCode/CnQrCode.vue.js.map +1 -0
- package/dist/esm/components/CnQrCode/CnQrCode.vue2.js +241 -0
- package/dist/esm/components/CnQrCode/CnQrCode.vue2.js.map +1 -0
- package/dist/esm/components/CnQrCode/CnQrCode.vue3.js +75 -0
- package/dist/esm/components/CnQrCode/CnQrCode.vue3.js.map +1 -0
- package/dist/esm/components/CnReadinessChecklist/CnReadinessChecklist.vue.js +1 -1
- package/dist/esm/components/CnReadinessChecklist/CnReadinessChecklist.vue2.js +34 -3
- package/dist/esm/components/CnReadinessChecklist/CnReadinessChecklist.vue2.js.map +1 -1
- package/dist/esm/components/CnReadinessChecklist/CnReadinessChecklist.vue3.js +81 -19
- package/dist/esm/components/CnReadinessChecklist/CnReadinessChecklist.vue3.js.map +1 -1
- package/dist/esm/components/CnRecordListWidget/CnRecordListWidget.vue.js +1 -1
- package/dist/esm/components/CnRecordListWidget/CnRecordListWidget.vue2.js +11 -0
- package/dist/esm/components/CnRecordListWidget/CnRecordListWidget.vue2.js.map +1 -1
- package/dist/esm/components/CnRecordListWidget/CnRecordListWidget.vue3.js +112 -88
- package/dist/esm/components/CnRecordListWidget/CnRecordListWidget.vue3.js.map +1 -1
- package/dist/esm/components/CnRevealField/CnRevealField.vue.js +9 -0
- package/dist/esm/components/CnRevealField/CnRevealField.vue.js.map +1 -0
- package/dist/esm/components/CnRevealField/CnRevealField.vue2.js +157 -0
- package/dist/esm/components/CnRevealField/CnRevealField.vue2.js.map +1 -0
- package/dist/esm/components/CnRevealField/CnRevealField.vue3.js +116 -0
- package/dist/esm/components/CnRevealField/CnRevealField.vue3.js.map +1 -0
- package/dist/esm/components/CnStorePage/CnStorePage.vue.js +1 -1
- package/dist/esm/components/CnStorePage/CnStorePage.vue2.js +3 -3
- package/dist/esm/components/CnStorePage/CnStorePage.vue2.js.map +1 -1
- package/dist/esm/components/CnStorePage/CnStorePage.vue3.js +5 -5
- package/dist/esm/components/CnStorePage/CnStorePage.vue3.js.map +1 -1
- package/dist/esm/components/CnStorePage/CnStorePublishDialog.vue.js +1 -1
- package/dist/esm/components/CnStorePage/CnStorePublishDialog.vue2.js +6 -6
- package/dist/esm/components/CnStorePage/CnStorePublishDialog.vue2.js.map +1 -1
- package/dist/esm/components/CnStorePage/CnStorePublishDialog.vue3.js +1 -1
- package/dist/esm/components/CnStorePage/CnStorePublishDialog.vue3.js.map +1 -1
- package/dist/esm/components/CnTextWidget/CnTextWidget.vue.js +1 -1
- package/dist/esm/components/CnTextWidget/CnTextWidget.vue2.js +43 -3
- package/dist/esm/components/CnTextWidget/CnTextWidget.vue2.js.map +1 -1
- package/dist/esm/components/CnTextWidget/CnTextWidget.vue3.js +19 -12
- package/dist/esm/components/CnTextWidget/CnTextWidget.vue3.js.map +1 -1
- package/dist/esm/components/CnTransferCard/CnTransferCard.vue.js +9 -0
- package/dist/esm/components/CnTransferCard/CnTransferCard.vue.js.map +1 -0
- package/dist/esm/components/CnTransferCard/CnTransferCard.vue2.js +87 -0
- package/dist/esm/components/CnTransferCard/CnTransferCard.vue2.js.map +1 -0
- package/dist/esm/components/CnTransferCard/CnTransferCard.vue3.js +126 -0
- package/dist/esm/components/CnTransferCard/CnTransferCard.vue3.js.map +1 -0
- package/dist/esm/components/CnTreeView/CnTreeNode.vue.js +1 -1
- package/dist/esm/components/CnTreeView/CnTreeNode.vue2.js +66 -1
- package/dist/esm/components/CnTreeView/CnTreeNode.vue2.js.map +1 -1
- package/dist/esm/components/CnTreeView/CnTreeNode.vue3.js +129 -29
- package/dist/esm/components/CnTreeView/CnTreeNode.vue3.js.map +1 -1
- package/dist/esm/components/CnTreeView/CnTreeView.vue.js +1 -1
- package/dist/esm/components/CnTreeView/CnTreeView.vue2.js +158 -6
- package/dist/esm/components/CnTreeView/CnTreeView.vue2.js.map +1 -1
- package/dist/esm/components/CnTreeView/CnTreeView.vue3.js +100 -39
- package/dist/esm/components/CnTreeView/CnTreeView.vue3.js.map +1 -1
- package/dist/esm/index.js +8 -0
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/l10n/en.json.js +79 -14
- package/dist/esm/l10n/en.json.js.map +1 -1
- package/dist/esm/l10n/nl.json.js +79 -14
- package/dist/esm/l10n/nl.json.js.map +1 -1
- package/dist/esm/library-style.js +1 -1
- package/dist/esm/nextcloud-vue.css +1162 -523
- package/dist/esm/node_modules/vuedraggable/dist/vuedraggable.umd.js +2 -2
- package/dist/esm/utils/captureLocation.js +32 -0
- package/dist/esm/utils/captureLocation.js.map +1 -0
- package/dist/esm/utils/childRecordTotals.js +157 -0
- package/dist/esm/utils/childRecordTotals.js.map +1 -0
- package/dist/esm/utils/isoDuration.js +51 -1
- package/dist/esm/utils/isoDuration.js.map +1 -1
- package/dist/esm/utils/parentCrumb.js +86 -0
- package/dist/esm/utils/parentCrumb.js.map +1 -0
- package/dist/esm/utils/qr.js +649 -0
- package/dist/esm/utils/qr.js.map +1 -0
- package/dist/esm/utils/schema.js +3 -0
- package/dist/esm/utils/schema.js.map +1 -1
- package/dist/esm/utils/templateVariables.js +54 -0
- package/dist/esm/utils/templateVariables.js.map +1 -0
- package/dist/nextcloud-vue.cjs.js +21125 -15025
- package/dist/nextcloud-vue.cjs.js.map +2 -2
- package/dist/nextcloud-vue.css +1162 -523
- package/l10n/en.json +79 -14
- package/l10n/nl.json +79 -14
- package/package.json +1 -1
- package/src/components/CnActionDialog/CnActionDialog.vue +156 -9
- package/src/components/CnBlockListEditor/CnBlockListEditor.vue +615 -0
- package/src/components/CnBlockListEditor/index.js +9 -0
- package/src/components/CnChecklistRunWidget/CnChecklistRunWidget.vue +377 -10
- package/src/components/CnChildRecordsField/CnChildRecordsField.vue +306 -15
- package/src/components/CnChoiceMatrix/CnChoiceMatrix.vue +710 -0
- package/src/components/CnChoiceMatrix/index.js +9 -0
- package/src/components/CnCountdownWidget/CnCountdownWidget.vue +223 -28
- package/src/components/CnCreateFormWidget/CnCreateFormWidget.vue +97 -6
- package/src/components/CnDataMatrix/CnDataMatrix.vue +304 -17
- package/src/components/CnDetailPage/CnDetailPage.vue +55 -6
- package/src/components/CnDisplayScreen/CnDisplayScreen.vue +308 -0
- package/src/components/CnDisplayScreen/index.js +9 -0
- package/src/components/CnDurationField/CnDurationField.vue +330 -5
- package/src/components/CnFormDialog/CnFormDialog.vue +4 -0
- package/src/components/CnGeoCaptureField/CnGeoCaptureField.vue +148 -0
- package/src/components/CnGeoCaptureField/index.js +9 -0
- package/src/components/CnIndexPage/CnIndexPage.vue +40 -1
- package/src/components/CnMarkdownEditor/CnMarkdownEditor.vue +139 -1
- package/src/components/CnQrCode/CnQrCode.vue +321 -0
- package/src/components/CnQrCode/index.js +9 -0
- package/src/components/CnReadinessChecklist/CnReadinessChecklist.vue +80 -3
- package/src/components/CnRecordListWidget/CnRecordListWidget.vue +34 -1
- package/src/components/CnRevealField/CnRevealField.vue +273 -0
- package/src/components/CnRevealField/index.js +9 -0
- package/src/components/CnStorePage/CnStorePage.vue +8 -8
- package/src/components/CnStorePage/CnStorePublishDialog.vue +7 -7
- package/src/components/CnTextWidget/CnTextWidget.vue +62 -3
- package/src/components/CnTransferCard/CnTransferCard.vue +205 -0
- package/src/components/CnTransferCard/index.js +9 -0
- package/src/components/CnTreeView/CnTreeNode.vue +145 -2
- package/src/components/CnTreeView/CnTreeView.vue +210 -6
- package/src/components/index.js +7 -0
- package/src/index.js +8 -0
- package/src/utils/captureLocation.js +29 -0
- package/src/utils/childRecordTotals.js +153 -0
- package/src/utils/isoDuration.js +50 -0
- package/src/utils/parentCrumb.js +83 -0
- package/src/utils/qr.js +681 -0
- package/src/utils/schema.js +3 -0
- package/src/utils/templateVariables.js +51 -0
|
@@ -5098,7 +5098,7 @@ import require$$1 from '../../../_virtual/sortable.esm.js';
|
|
|
5098
5098
|
} (vuedraggable_umd));
|
|
5099
5099
|
|
|
5100
5100
|
var vuedraggable_umdExports = vuedraggable_umd.exports;
|
|
5101
|
-
var
|
|
5101
|
+
var Draggable = /*@__PURE__*/getDefaultExportFromCjs(vuedraggable_umdExports);
|
|
5102
5102
|
|
|
5103
|
-
export {
|
|
5103
|
+
export { Draggable as default };
|
|
5104
5104
|
//# sourceMappingURL=vuedraggable.umd.js.map
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SPDX-FileCopyrightText: 2026 Conduction B.V.
|
|
3
|
+
* SPDX-License-Identifier: EUPL-1.2
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Ask the device where it is. Never rejects: no geolocation, a refusal and a
|
|
8
|
+
* timeout all answer null, so a caller can carry on without a location.
|
|
9
|
+
*
|
|
10
|
+
* @param {number} [timeout] How long to wait, in ms.
|
|
11
|
+
* @return {Promise<{lat: number, lng: number, accuracy: number, at: string}|null>} The position.
|
|
12
|
+
*/
|
|
13
|
+
function captureLocation(timeout = 10000) {
|
|
14
|
+
if (typeof navigator === 'undefined' || !navigator.geolocation) {
|
|
15
|
+
return Promise.resolve(null)
|
|
16
|
+
}
|
|
17
|
+
return new Promise((resolve) => {
|
|
18
|
+
navigator.geolocation.getCurrentPosition(
|
|
19
|
+
(position) => resolve({
|
|
20
|
+
lat: position.coords.latitude,
|
|
21
|
+
lng: position.coords.longitude,
|
|
22
|
+
accuracy: position.coords.accuracy,
|
|
23
|
+
at: new Date().toISOString(),
|
|
24
|
+
}),
|
|
25
|
+
() => resolve(null),
|
|
26
|
+
{ enableHighAccuracy: true, timeout },
|
|
27
|
+
);
|
|
28
|
+
})
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export { captureLocation };
|
|
32
|
+
//# sourceMappingURL=captureLocation.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"captureLocation.js","sources":["../../../src/utils/captureLocation.js"],"sourcesContent":["/**\n * SPDX-FileCopyrightText: 2026 Conduction B.V.\n * SPDX-License-Identifier: EUPL-1.2\n */\n\n/**\n * Ask the device where it is. Never rejects: no geolocation, a refusal and a\n * timeout all answer null, so a caller can carry on without a location.\n *\n * @param {number} [timeout] How long to wait, in ms.\n * @return {Promise<{lat: number, lng: number, accuracy: number, at: string}|null>} The position.\n */\nexport function captureLocation(timeout = 10000) {\n\tif (typeof navigator === 'undefined' || !navigator.geolocation) {\n\t\treturn Promise.resolve(null)\n\t}\n\treturn new Promise((resolve) => {\n\t\tnavigator.geolocation.getCurrentPosition(\n\t\t\t(position) => resolve({\n\t\t\t\tlat: position.coords.latitude,\n\t\t\t\tlng: position.coords.longitude,\n\t\t\t\taccuracy: position.coords.accuracy,\n\t\t\t\tat: new Date().toISOString(),\n\t\t\t}),\n\t\t\t() => resolve(null),\n\t\t\t{ enableHighAccuracy: true, timeout },\n\t\t)\n\t})\n}\n"],"names":[],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAAS,eAAe,CAAC,OAAO,GAAG,KAAK,EAAE;AACjD,CAAC,IAAI,OAAO,SAAS,KAAK,WAAW,IAAI,CAAC,SAAS,CAAC,WAAW,EAAE;AACjE,EAAE,OAAO,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC;AAC9B,EAAE;AACF,CAAC,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,KAAK;AACjC,EAAE,SAAS,CAAC,WAAW,CAAC,kBAAkB;AAC1C,GAAG,CAAC,QAAQ,KAAK,OAAO,CAAC;AACzB,IAAI,GAAG,EAAE,QAAQ,CAAC,MAAM,CAAC,QAAQ;AACjC,IAAI,GAAG,EAAE,QAAQ,CAAC,MAAM,CAAC,SAAS;AAClC,IAAI,QAAQ,EAAE,QAAQ,CAAC,MAAM,CAAC,QAAQ;AACtC,IAAI,EAAE,EAAE,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE;AAChC,IAAI,CAAC;AACL,GAAG,MAAM,OAAO,CAAC,IAAI,CAAC;AACtB,GAAG,EAAE,kBAAkB,EAAE,IAAI,EAAE,OAAO,EAAE;AACxC,IAAG;AACH,EAAE,CAAC;AACH;;;;"}
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
import { evalFormula } from './evalFormula.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* SPDX-FileCopyrightText: 2026 Conduction B.V.
|
|
5
|
+
* SPDX-License-Identifier: EUPL-1.2
|
|
6
|
+
*
|
|
7
|
+
* Arithmetic for the rows of `CnChildRecordsField`: computed columns per row,
|
|
8
|
+
* totals over all rows, and the values a picked source record gives a new row.
|
|
9
|
+
* Formulas go through `evalFormula`, so no `eval` runs.
|
|
10
|
+
*
|
|
11
|
+
* @module utils/childRecordTotals
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* The identifiers a formula names.
|
|
17
|
+
*
|
|
18
|
+
* @param {string} formula The formula.
|
|
19
|
+
* @return {string[]} The identifiers.
|
|
20
|
+
*/
|
|
21
|
+
function identifiersOf(formula) {
|
|
22
|
+
return String(formula || '').match(/[A-Za-z_][A-Za-z0-9_]*/g) || []
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* The variables for a formula: every identifier it names, as a number, 0 when
|
|
27
|
+
* the value is empty or no number, so a half-filled row still computes.
|
|
28
|
+
*
|
|
29
|
+
* @param {string} formula The formula.
|
|
30
|
+
* @param {object} values The named values.
|
|
31
|
+
* @return {Object<string, number>} The variables.
|
|
32
|
+
*/
|
|
33
|
+
function varsFor(formula, values) {
|
|
34
|
+
const vars = {};
|
|
35
|
+
for (const id of identifiersOf(formula)) {
|
|
36
|
+
const n = Number(values?.[id]);
|
|
37
|
+
vars[id] = Number.isFinite(n) ? n : 0;
|
|
38
|
+
}
|
|
39
|
+
return vars
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Evaluate a formula over named values.
|
|
44
|
+
*
|
|
45
|
+
* @param {string} formula The formula (`quantity * price`).
|
|
46
|
+
* @param {object} values The named values.
|
|
47
|
+
* @return {number|null} The result, or null on an invalid formula or a division by zero.
|
|
48
|
+
* @spec openspec/changes/child-records-totals/tasks.md#task-1
|
|
49
|
+
*/
|
|
50
|
+
function evalOver(formula, values) {
|
|
51
|
+
if (typeof formula !== 'string' || formula.trim() === '') {
|
|
52
|
+
return null
|
|
53
|
+
}
|
|
54
|
+
return evalFormula(formula, varsFor(formula, values))
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* The computed values of one row, in order, so a later computed column can
|
|
59
|
+
* name an earlier one.
|
|
60
|
+
*
|
|
61
|
+
* @param {object} row The row.
|
|
62
|
+
* @param {Array<{key: string, formula: string}>} computed The computed columns.
|
|
63
|
+
* @return {Object<string, number|null>} Computed value per key.
|
|
64
|
+
* @spec openspec/changes/child-records-totals/tasks.md#task-1
|
|
65
|
+
*/
|
|
66
|
+
function computeRow(row, computed) {
|
|
67
|
+
const out = {};
|
|
68
|
+
const scope = { ...(row || {}) };
|
|
69
|
+
for (const col of Array.isArray(computed) ? computed : []) {
|
|
70
|
+
if (!col || !col.key) {
|
|
71
|
+
continue
|
|
72
|
+
}
|
|
73
|
+
const value = evalOver(col.formula, scope);
|
|
74
|
+
out[col.key] = value;
|
|
75
|
+
scope[col.key] = value;
|
|
76
|
+
}
|
|
77
|
+
return out
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* The row with every computed column marked `store` written into it.
|
|
82
|
+
*
|
|
83
|
+
* @param {object} row The row.
|
|
84
|
+
* @param {Array<{key: string, formula: string, store?: boolean}>} computed The computed columns.
|
|
85
|
+
* @return {object} The row, a new object when something was written.
|
|
86
|
+
* @spec openspec/changes/child-records-totals/tasks.md#task-1
|
|
87
|
+
*/
|
|
88
|
+
function storeComputed(row, computed) {
|
|
89
|
+
const stored = (Array.isArray(computed) ? computed : []).filter((c) => c && c.key && c.store);
|
|
90
|
+
if (stored.length === 0) {
|
|
91
|
+
return row
|
|
92
|
+
}
|
|
93
|
+
const values = computeRow(row, computed);
|
|
94
|
+
const next = { ...row };
|
|
95
|
+
for (const col of stored) {
|
|
96
|
+
next[col.key] = values[col.key];
|
|
97
|
+
}
|
|
98
|
+
return next
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* The totals over all rows. A total with `sum` adds that formula over every
|
|
103
|
+
* row (a column key is a formula too); a total with `formula` computes over
|
|
104
|
+
* the totals before it (`subtotal + tax`).
|
|
105
|
+
*
|
|
106
|
+
* @param {object[]} rows The rows.
|
|
107
|
+
* @param {Array<{key: string, sum?: string, formula?: string}>} totals The totals.
|
|
108
|
+
* @param {Array<{key: string, formula: string}>} [computed] The computed columns, which `sum` may name.
|
|
109
|
+
* @return {Object<string, number|null>} Total per key.
|
|
110
|
+
* @spec openspec/changes/child-records-totals/tasks.md#task-2
|
|
111
|
+
*/
|
|
112
|
+
function computeTotals(rows, totals, computed = []) {
|
|
113
|
+
const list = Array.isArray(rows) ? rows : [];
|
|
114
|
+
const scoped = list.map((row) => ({ ...(row || {}), ...computeRow(row, computed) }));
|
|
115
|
+
const out = {};
|
|
116
|
+
for (const total of Array.isArray(totals) ? totals : []) {
|
|
117
|
+
if (!total || !total.key) {
|
|
118
|
+
continue
|
|
119
|
+
}
|
|
120
|
+
if (typeof total.sum === 'string' && total.sum !== '') {
|
|
121
|
+
let sum = 0;
|
|
122
|
+
let valid = true;
|
|
123
|
+
for (const row of scoped) {
|
|
124
|
+
const value = evalOver(total.sum, row);
|
|
125
|
+
if (value === null) {
|
|
126
|
+
valid = false;
|
|
127
|
+
break
|
|
128
|
+
}
|
|
129
|
+
sum += value;
|
|
130
|
+
}
|
|
131
|
+
out[total.key] = valid ? sum : null;
|
|
132
|
+
} else {
|
|
133
|
+
out[total.key] = evalOver(total.formula, out);
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
return out
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* The values a picked source record gives a new row. `map` names, per row
|
|
141
|
+
* key, the source key to copy; `@id` copies the source's id (or uuid).
|
|
142
|
+
*
|
|
143
|
+
* @param {object} source The picked record.
|
|
144
|
+
* @param {Object<string, string>} map Row key to source key.
|
|
145
|
+
* @return {object} The new row.
|
|
146
|
+
* @spec openspec/changes/child-records-totals/tasks.md#task-3
|
|
147
|
+
*/
|
|
148
|
+
function rowFromSource(source, map) {
|
|
149
|
+
const row = {};
|
|
150
|
+
for (const [rowKey, sourceKey] of Object.entries(map || {})) {
|
|
151
|
+
row[rowKey] = sourceKey === '@id' ? (source?.id ?? source?.uuid ?? null) : (source?.[sourceKey] ?? null);
|
|
152
|
+
}
|
|
153
|
+
return row
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
export { computeRow, computeTotals, evalOver, rowFromSource, storeComputed };
|
|
157
|
+
//# sourceMappingURL=childRecordTotals.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"childRecordTotals.js","sources":["../../../src/utils/childRecordTotals.js"],"sourcesContent":["/**\n * SPDX-FileCopyrightText: 2026 Conduction B.V.\n * SPDX-License-Identifier: EUPL-1.2\n *\n * Arithmetic for the rows of `CnChildRecordsField`: computed columns per row,\n * totals over all rows, and the values a picked source record gives a new row.\n * Formulas go through `evalFormula`, so no `eval` runs.\n *\n * @module utils/childRecordTotals\n */\n\nimport { evalFormula } from './evalFormula.js'\n\n/**\n * The identifiers a formula names.\n *\n * @param {string} formula The formula.\n * @return {string[]} The identifiers.\n */\nfunction identifiersOf(formula) {\n\treturn String(formula || '').match(/[A-Za-z_][A-Za-z0-9_]*/g) || []\n}\n\n/**\n * The variables for a formula: every identifier it names, as a number, 0 when\n * the value is empty or no number, so a half-filled row still computes.\n *\n * @param {string} formula The formula.\n * @param {object} values The named values.\n * @return {Object<string, number>} The variables.\n */\nfunction varsFor(formula, values) {\n\tconst vars = {}\n\tfor (const id of identifiersOf(formula)) {\n\t\tconst n = Number(values?.[id])\n\t\tvars[id] = Number.isFinite(n) ? n : 0\n\t}\n\treturn vars\n}\n\n/**\n * Evaluate a formula over named values.\n *\n * @param {string} formula The formula (`quantity * price`).\n * @param {object} values The named values.\n * @return {number|null} The result, or null on an invalid formula or a division by zero.\n * @spec openspec/changes/child-records-totals/tasks.md#task-1\n */\nexport function evalOver(formula, values) {\n\tif (typeof formula !== 'string' || formula.trim() === '') {\n\t\treturn null\n\t}\n\treturn evalFormula(formula, varsFor(formula, values))\n}\n\n/**\n * The computed values of one row, in order, so a later computed column can\n * name an earlier one.\n *\n * @param {object} row The row.\n * @param {Array<{key: string, formula: string}>} computed The computed columns.\n * @return {Object<string, number|null>} Computed value per key.\n * @spec openspec/changes/child-records-totals/tasks.md#task-1\n */\nexport function computeRow(row, computed) {\n\tconst out = {}\n\tconst scope = { ...(row || {}) }\n\tfor (const col of Array.isArray(computed) ? computed : []) {\n\t\tif (!col || !col.key) {\n\t\t\tcontinue\n\t\t}\n\t\tconst value = evalOver(col.formula, scope)\n\t\tout[col.key] = value\n\t\tscope[col.key] = value\n\t}\n\treturn out\n}\n\n/**\n * The row with every computed column marked `store` written into it.\n *\n * @param {object} row The row.\n * @param {Array<{key: string, formula: string, store?: boolean}>} computed The computed columns.\n * @return {object} The row, a new object when something was written.\n * @spec openspec/changes/child-records-totals/tasks.md#task-1\n */\nexport function storeComputed(row, computed) {\n\tconst stored = (Array.isArray(computed) ? computed : []).filter((c) => c && c.key && c.store)\n\tif (stored.length === 0) {\n\t\treturn row\n\t}\n\tconst values = computeRow(row, computed)\n\tconst next = { ...row }\n\tfor (const col of stored) {\n\t\tnext[col.key] = values[col.key]\n\t}\n\treturn next\n}\n\n/**\n * The totals over all rows. A total with `sum` adds that formula over every\n * row (a column key is a formula too); a total with `formula` computes over\n * the totals before it (`subtotal + tax`).\n *\n * @param {object[]} rows The rows.\n * @param {Array<{key: string, sum?: string, formula?: string}>} totals The totals.\n * @param {Array<{key: string, formula: string}>} [computed] The computed columns, which `sum` may name.\n * @return {Object<string, number|null>} Total per key.\n * @spec openspec/changes/child-records-totals/tasks.md#task-2\n */\nexport function computeTotals(rows, totals, computed = []) {\n\tconst list = Array.isArray(rows) ? rows : []\n\tconst scoped = list.map((row) => ({ ...(row || {}), ...computeRow(row, computed) }))\n\tconst out = {}\n\tfor (const total of Array.isArray(totals) ? totals : []) {\n\t\tif (!total || !total.key) {\n\t\t\tcontinue\n\t\t}\n\t\tif (typeof total.sum === 'string' && total.sum !== '') {\n\t\t\tlet sum = 0\n\t\t\tlet valid = true\n\t\t\tfor (const row of scoped) {\n\t\t\t\tconst value = evalOver(total.sum, row)\n\t\t\t\tif (value === null) {\n\t\t\t\t\tvalid = false\n\t\t\t\t\tbreak\n\t\t\t\t}\n\t\t\t\tsum += value\n\t\t\t}\n\t\t\tout[total.key] = valid ? sum : null\n\t\t} else {\n\t\t\tout[total.key] = evalOver(total.formula, out)\n\t\t}\n\t}\n\treturn out\n}\n\n/**\n * The values a picked source record gives a new row. `map` names, per row\n * key, the source key to copy; `@id` copies the source's id (or uuid).\n *\n * @param {object} source The picked record.\n * @param {Object<string, string>} map Row key to source key.\n * @return {object} The new row.\n * @spec openspec/changes/child-records-totals/tasks.md#task-3\n */\nexport function rowFromSource(source, map) {\n\tconst row = {}\n\tfor (const [rowKey, sourceKey] of Object.entries(map || {})) {\n\t\trow[rowKey] = sourceKey === '@id' ? (source?.id ?? source?.uuid ?? null) : (source?.[sourceKey] ?? null)\n\t}\n\treturn row\n}\n"],"names":[],"mappings":";;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAAS,aAAa,CAAC,OAAO,EAAE;AAChC,CAAC,OAAO,MAAM,CAAC,OAAO,IAAI,EAAE,CAAC,CAAC,KAAK,CAAC,yBAAyB,CAAC,IAAI,EAAE;AACpE,CAAC;AACD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAAS,OAAO,CAAC,OAAO,EAAE,MAAM,EAAE;AAClC,CAAC,MAAM,IAAI,GAAG,GAAE;AAChB,CAAC,KAAK,MAAM,EAAE,IAAI,aAAa,CAAC,OAAO,CAAC,EAAE;AAC1C,EAAE,MAAM,CAAC,GAAG,MAAM,CAAC,MAAM,GAAG,EAAE,CAAC,EAAC;AAChC,EAAE,IAAI,CAAC,EAAE,CAAC,GAAG,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAC,GAAG,CAAC,GAAG,EAAC;AACvC,EAAE;AACF,CAAC,OAAO,IAAI;AACZ,CAAC;AACD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAAS,QAAQ,CAAC,OAAO,EAAE,MAAM,EAAE;AAC1C,CAAC,IAAI,OAAO,OAAO,KAAK,QAAQ,IAAI,OAAO,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE;AAC3D,EAAE,OAAO,IAAI;AACb,EAAE;AACF,CAAC,OAAO,WAAW,CAAC,OAAO,EAAE,OAAO,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;AACtD,CAAC;AACD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAAS,UAAU,CAAC,GAAG,EAAE,QAAQ,EAAE;AAC1C,CAA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Q,CAAC,KAAK,CAAC,OAAO,EAAE,GAAG,EAAC;AAChD,GAAG;AACH,EAAE;AACF,CAAC,OAAO,GAAG;AACX,CAAC;AACD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAAS,aAAa,CAAC,MAAM,EAAE,GAAG,EAAE;AAC3C,CAAC,MAAM,GAAG,GAAG,GAAE;AACf,CAAC,KAAK,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,GAAG,IAAI,EAAE,CAAC,EAAE;AAC9D,EAAE,GAAG,CAAC,MAAM,CAAC,GAAG,SAAS,KAAK,KAAK,IAAI,MAAM,EAAE,EAAE,IAAI,MAAM,EAAE,IAAI,IAAI,IAAI,KAAK,MAAM,GAAG,SAAS,CAAC,IAAI,IAAI,EAAC;AAC1G,EAAE;AACF,CAAC,OAAO,GAAG;AACX;;;;"}
|
|
@@ -96,5 +96,55 @@ function durationSeconds(value) {
|
|
|
96
96
|
return Object.keys(p).reduce((sum, k) => sum + p[k] * SECONDS[k], 0)
|
|
97
97
|
}
|
|
98
98
|
|
|
99
|
-
|
|
99
|
+
/**
|
|
100
|
+
* Write a number of seconds as the canonical hours, minutes and seconds.
|
|
101
|
+
*
|
|
102
|
+
* @param {number} seconds The length; negative or fractional parts are dropped.
|
|
103
|
+
* @return {string} `PT1H4M23S`, `PT6M`, `PT0S`.
|
|
104
|
+
*/
|
|
105
|
+
function secondsToDuration(seconds) {
|
|
106
|
+
const total = Math.max(0, Math.trunc(Number(seconds) || 0));
|
|
107
|
+
const h = Math.floor(total / 3600);
|
|
108
|
+
const m = Math.floor((total % 3600) / 60);
|
|
109
|
+
const s = total % 60;
|
|
110
|
+
if (total === 0) {
|
|
111
|
+
return 'PT0S'
|
|
112
|
+
}
|
|
113
|
+
return `PT${h ? `${h}H` : ''}${m ? `${m}M` : ''}${s ? `${s}S` : ''}`
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* Show a number of seconds as a clock: `04:23`, or `1:04:23` from an hour.
|
|
118
|
+
*
|
|
119
|
+
* @param {number} seconds The length.
|
|
120
|
+
* @return {string}
|
|
121
|
+
*/
|
|
122
|
+
function formatClock(seconds) {
|
|
123
|
+
const total = Math.max(0, Math.trunc(Number(seconds) || 0));
|
|
124
|
+
const h = Math.floor(total / 3600);
|
|
125
|
+
const m = String(Math.floor((total % 3600) / 60)).padStart(2, '0');
|
|
126
|
+
const s = String(total % 60).padStart(2, '0');
|
|
127
|
+
return h ? `${h}:${m}:${s}` : `${m}:${s}`
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* Read what a user typed as a length: `6` is minutes, `04:23` is minutes and
|
|
132
|
+
* seconds, `1:04:23` adds hours.
|
|
133
|
+
*
|
|
134
|
+
* @param {string} text The typed text.
|
|
135
|
+
* @return {number|null} Seconds, or null when the text is no length.
|
|
136
|
+
*/
|
|
137
|
+
function parseClock(text) {
|
|
138
|
+
const trimmed = String(text ?? '').trim();
|
|
139
|
+
if (/^\d+$/.test(trimmed)) {
|
|
140
|
+
return Number(trimmed) * 60
|
|
141
|
+
}
|
|
142
|
+
const m = trimmed.match(/^(?:(\d+):)?(\d{1,3}):([0-5]\d)$/);
|
|
143
|
+
if (!m) {
|
|
144
|
+
return null
|
|
145
|
+
}
|
|
146
|
+
return Number(m[1] || 0) * 3600 + Number(m[2]) * 60 + Number(m[3])
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
export { DURATION_UNITS, durationSeconds, formatClock, formatDuration, isIsoDuration, parseClock, parseDuration, secondsToDuration };
|
|
100
150
|
//# sourceMappingURL=isoDuration.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"isoDuration.js","sources":["../../../src/utils/isoDuration.js"],"sourcesContent":["/**\n * SPDX-FileCopyrightText: 2026 Conduction B.V.\n * SPDX-License-Identifier: EUPL-1.2\n *\n * ISO 8601 duration helpers for the `duration` form widget.\n *\n * @spec openspec/changes/form-widgets-duration-and-subobject-table/tasks.md#task-1\n */\n\nconst PATTERN = /^P(?:(\\d+)Y)?(?:(\\d+)M)?(?:(\\d+)W)?(?:(\\d+)D)?(?:T(?:(\\d+)H)?(?:(\\d+)M)?(?:(\\d+)S)?)?$/\n\n/** Units the widget edits, in select order. `date` units sit before the `T`. */\nexport const DURATION_UNITS = ['minutes', 'hours', 'days', 'weeks', 'months', 'years']\n\nconst DESIGNATOR = { minutes: 'TM', hours: 'TH', days: 'D', weeks: 'W', months: 'M', years: 'Y' }\nconst SECONDS = { seconds: 1, minutes: 60, hours: 3600, days: 86400, weeks: 604800, months: 2592000, years: 31536000 }\n\n/**\n * Whether a string is a well-formed ISO 8601 duration.\n *\n * @param {string} value The text to test.\n * @return {boolean}\n */\nexport function isIsoDuration(value) {\n\treturn typeof value === 'string' && value !== 'P' && !value.endsWith('T') && PATTERN.test(value)\n}\n\n/**\n * Split a duration into its non-zero parts, or null when it is not ISO.\n *\n * @param {string} value ISO 8601 duration.\n * @return {Object<string, number>|null} Parts keyed by unit name, e.g. `{ days: 1, hours: 2 }`.\n */\nfunction parts(value) {\n\tif (!isIsoDuration(value)) {\n\t\treturn null\n\t}\n\tconst m = value.match(PATTERN)\n\tconst names = ['years', 'months', 'weeks', 'days', 'hours', 'minutes', 'seconds']\n\tconst out = {}\n\tnames.forEach((name, i) => {\n\t\tconst n = Number(m[i + 1])\n\t\tif (m[i + 1] !== undefined && n !== 0) {\n\t\t\tout[name] = n\n\t\t}\n\t})\n\treturn out\n}\n\n/**\n * Reduce a duration to one number and unit. Anything that is not exactly one\n * unit (`P1DT2H`, seconds) returns null so the widget never rounds.\n *\n * @param {string} value ISO 8601 duration, e.g. `P56D`.\n * @return {{amount: number, unit: string}|null} The single unit, or null.\n */\nexport function parseDuration(value) {\n\tconst p = parts(value)\n\tif (!p) {\n\t\treturn null\n\t}\n\tconst keys = Object.keys(p)\n\tif (keys.length !== 1 || !DURATION_UNITS.includes(keys[0])) {\n\t\treturn null\n\t}\n\treturn { amount: p[keys[0]], unit: keys[0] }\n}\n\n/**\n * Write the canonical ISO string for a number of one unit.\n *\n * @param {number} amount The count.\n * @param {string} unit One of DURATION_UNITS.\n * @return {string|null} `P56D`, `PT4H`, ...; null for an empty or invalid amount.\n */\nexport function formatDuration(amount, unit) {\n\tconst n = Number(amount)\n\tif (amount === '' || amount === null || amount === undefined || !Number.isFinite(n) || n < 0 || !DESIGNATOR[unit]) {\n\t\treturn null\n\t}\n\tconst d = DESIGNATOR[unit]\n\treturn d.startsWith('T') ? `PT${Math.trunc(n)}${d.slice(1)}` : `P${Math.trunc(n)}${d}`\n}\n\n/**\n * Length of a duration in seconds (months as 30 days, years as 365) for min/max checks.\n *\n * @param {string} value ISO 8601 duration.\n * @return {number|null} Seconds, or null when not ISO.\n */\nexport function durationSeconds(value) {\n\tconst p = parts(value)\n\tif (!p) {\n\t\treturn null\n\t}\n\treturn Object.keys(p).reduce((sum, k) => sum + p[k] * SECONDS[k], 0)\n}\n"],"names":[],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAM,OAAO,GAAG,yFAAwF;AACxG;AACA;AACY,MAAC,cAAc,GAAG,CAAC,SAAS,EAAE,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAC;AACtF;AACA,MAAM,UAAU,GAAG,EAAE,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,IAAI,EAAE,GAAG,EAAE,KAAK,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,KAAK,EAAE,GAAG,GAAE;AACjG,MAAM,OAAO,GAAG,EAAE,OAAO,EAAE,CAAC,EAAE,OAAO,EAAE,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,KAAK,EAAE,QAAQ,GAAE;AACtH;AACA;AACA;AAC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AAC,CAAC,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,CAAC,KAAK,GAAG,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;AACrE;;;;"}
|
|
1
|
+
{"version":3,"file":"isoDuration.js","sources":["../../../src/utils/isoDuration.js"],"sourcesContent":["/**\n * SPDX-FileCopyrightText: 2026 Conduction B.V.\n * SPDX-License-Identifier: EUPL-1.2\n *\n * ISO 8601 duration helpers for the `duration` form widget.\n *\n * @spec openspec/changes/form-widgets-duration-and-subobject-table/tasks.md#task-1\n */\n\nconst PATTERN = /^P(?:(\\d+)Y)?(?:(\\d+)M)?(?:(\\d+)W)?(?:(\\d+)D)?(?:T(?:(\\d+)H)?(?:(\\d+)M)?(?:(\\d+)S)?)?$/\n\n/** Units the widget edits, in select order. `date` units sit before the `T`. */\nexport const DURATION_UNITS = ['minutes', 'hours', 'days', 'weeks', 'months', 'years']\n\nconst DESIGNATOR = { minutes: 'TM', hours: 'TH', days: 'D', weeks: 'W', months: 'M', years: 'Y' }\nconst SECONDS = { seconds: 1, minutes: 60, hours: 3600, days: 86400, weeks: 604800, months: 2592000, years: 31536000 }\n\n/**\n * Whether a string is a well-formed ISO 8601 duration.\n *\n * @param {string} value The text to test.\n * @return {boolean}\n */\nexport function isIsoDuration(value) {\n\treturn typeof value === 'string' && value !== 'P' && !value.endsWith('T') && PATTERN.test(value)\n}\n\n/**\n * Split a duration into its non-zero parts, or null when it is not ISO.\n *\n * @param {string} value ISO 8601 duration.\n * @return {Object<string, number>|null} Parts keyed by unit name, e.g. `{ days: 1, hours: 2 }`.\n */\nfunction parts(value) {\n\tif (!isIsoDuration(value)) {\n\t\treturn null\n\t}\n\tconst m = value.match(PATTERN)\n\tconst names = ['years', 'months', 'weeks', 'days', 'hours', 'minutes', 'seconds']\n\tconst out = {}\n\tnames.forEach((name, i) => {\n\t\tconst n = Number(m[i + 1])\n\t\tif (m[i + 1] !== undefined && n !== 0) {\n\t\t\tout[name] = n\n\t\t}\n\t})\n\treturn out\n}\n\n/**\n * Reduce a duration to one number and unit. Anything that is not exactly one\n * unit (`P1DT2H`, seconds) returns null so the widget never rounds.\n *\n * @param {string} value ISO 8601 duration, e.g. `P56D`.\n * @return {{amount: number, unit: string}|null} The single unit, or null.\n */\nexport function parseDuration(value) {\n\tconst p = parts(value)\n\tif (!p) {\n\t\treturn null\n\t}\n\tconst keys = Object.keys(p)\n\tif (keys.length !== 1 || !DURATION_UNITS.includes(keys[0])) {\n\t\treturn null\n\t}\n\treturn { amount: p[keys[0]], unit: keys[0] }\n}\n\n/**\n * Write the canonical ISO string for a number of one unit.\n *\n * @param {number} amount The count.\n * @param {string} unit One of DURATION_UNITS.\n * @return {string|null} `P56D`, `PT4H`, ...; null for an empty or invalid amount.\n */\nexport function formatDuration(amount, unit) {\n\tconst n = Number(amount)\n\tif (amount === '' || amount === null || amount === undefined || !Number.isFinite(n) || n < 0 || !DESIGNATOR[unit]) {\n\t\treturn null\n\t}\n\tconst d = DESIGNATOR[unit]\n\treturn d.startsWith('T') ? `PT${Math.trunc(n)}${d.slice(1)}` : `P${Math.trunc(n)}${d}`\n}\n\n/**\n * Length of a duration in seconds (months as 30 days, years as 365) for min/max checks.\n *\n * @param {string} value ISO 8601 duration.\n * @return {number|null} Seconds, or null when not ISO.\n */\nexport function durationSeconds(value) {\n\tconst p = parts(value)\n\tif (!p) {\n\t\treturn null\n\t}\n\treturn Object.keys(p).reduce((sum, k) => sum + p[k] * SECONDS[k], 0)\n}\n\n/**\n * Write a number of seconds as the canonical hours, minutes and seconds.\n *\n * @param {number} seconds The length; negative or fractional parts are dropped.\n * @return {string} `PT1H4M23S`, `PT6M`, `PT0S`.\n */\nexport function secondsToDuration(seconds) {\n\tconst total = Math.max(0, Math.trunc(Number(seconds) || 0))\n\tconst h = Math.floor(total / 3600)\n\tconst m = Math.floor((total % 3600) / 60)\n\tconst s = total % 60\n\tif (total === 0) {\n\t\treturn 'PT0S'\n\t}\n\treturn `PT${h ? `${h}H` : ''}${m ? `${m}M` : ''}${s ? `${s}S` : ''}`\n}\n\n/**\n * Show a number of seconds as a clock: `04:23`, or `1:04:23` from an hour.\n *\n * @param {number} seconds The length.\n * @return {string}\n */\nexport function formatClock(seconds) {\n\tconst total = Math.max(0, Math.trunc(Number(seconds) || 0))\n\tconst h = Math.floor(total / 3600)\n\tconst m = String(Math.floor((total % 3600) / 60)).padStart(2, '0')\n\tconst s = String(total % 60).padStart(2, '0')\n\treturn h ? `${h}:${m}:${s}` : `${m}:${s}`\n}\n\n/**\n * Read what a user typed as a length: `6` is minutes, `04:23` is minutes and\n * seconds, `1:04:23` adds hours.\n *\n * @param {string} text The typed text.\n * @return {number|null} Seconds, or null when the text is no length.\n */\nexport function parseClock(text) {\n\tconst trimmed = String(text ?? '').trim()\n\tif (/^\\d+$/.test(trimmed)) {\n\t\treturn Number(trimmed) * 60\n\t}\n\tconst m = trimmed.match(/^(?:(\\d+):)?(\\d{1,3}):([0-5]\\d)$/)\n\tif (!m) {\n\t\treturn null\n\t}\n\treturn Number(m[1] || 0) * 3600 + Number(m[2]) * 60 + Number(m[3])\n}\n"],"names":[],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAM,OAAO,GAAG,yFAAwF;AACxG;AACA;AACY,MAAC,cAAc,GAAG,CAAC,SAAS,EAAE,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAC;AACtF;AACA,MAAM,UAAU,GAAG,EAAE,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,IAAI,EAAE,GAAG,EAAE,KAAK,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,KAAK,EAAE,GAAG,GAAE;AACjG,MAAM,OAAO,GAAG,EAAE,OAAO,EAAE,CAAC,EAAE,OAAO,EAAE,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE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2026 Conduction B.V.
|
|
3
|
+
* SPDX-License-Identifier: EUPL-1.2
|
|
4
|
+
*
|
|
5
|
+
* parentCrumb: the breadcrumb entry for the record a sub-record belongs to.
|
|
6
|
+
*
|
|
7
|
+
* A crumb that carries `parent` names a `visibilityContext` entry of the
|
|
8
|
+
* detail page. The page reads that record beside the loaded one; this
|
|
9
|
+
* helper turns it into a crumb with the parent's label and a link to its
|
|
10
|
+
* page.
|
|
11
|
+
*
|
|
12
|
+
* @module utils/parentCrumb
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Read a dotted path from an object.
|
|
17
|
+
*
|
|
18
|
+
* @param {object|null} obj The object to read.
|
|
19
|
+
* @param {string} path A dotted path, e.g. `identifier` or `@self.name`.
|
|
20
|
+
* @return {unknown} The value, or undefined.
|
|
21
|
+
*/
|
|
22
|
+
function readPath(obj, path) {
|
|
23
|
+
return path.split('.').reduce((o, part) => (o === null || o === undefined ? undefined : o[part]), obj)
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* A non-empty string for a value, or ''.
|
|
28
|
+
*
|
|
29
|
+
* @param {unknown} value Any value.
|
|
30
|
+
* @return {string} The text.
|
|
31
|
+
*/
|
|
32
|
+
function text(value) {
|
|
33
|
+
if (typeof value === 'number') {
|
|
34
|
+
return String(value)
|
|
35
|
+
}
|
|
36
|
+
return typeof value === 'string' ? value.trim() : ''
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* The crumb for a record's parent.
|
|
41
|
+
*
|
|
42
|
+
* The crumb is dropped (null) when the record holds no reference to a
|
|
43
|
+
* parent. Its label is the parent's `labelField` value, else the parent's
|
|
44
|
+
* name or title, else the crumb's own `label` (translated); without any of
|
|
45
|
+
* those it is dropped too. The link goes to `route` with the parent's id in
|
|
46
|
+
* `param` (default `id`), or to `href` with `{id}` filled in.
|
|
47
|
+
*
|
|
48
|
+
* @param {object} crumb `{ parent, labelField?, label?, route?, params?, param?, href?, icon? }`.
|
|
49
|
+
* @param {Array<{key: string, id: string}>} refs The page's context references.
|
|
50
|
+
* @param {object} rows The context records read so far, by name.
|
|
51
|
+
* @param {(key: string) => string} translate The host translate function.
|
|
52
|
+
* @return {{label: string, to?: object, href?: string, icon?: string}|null} The crumb, or null.
|
|
53
|
+
* @spec openspec/changes/detail-parent-crumb/specs/detail-page/spec.md#requirement-a-sub-record-trail-can-show-its-parent-record
|
|
54
|
+
*/
|
|
55
|
+
function parentCrumb(crumb, refs, rows, translate) {
|
|
56
|
+
const ref = (refs || []).find((r) => r.key === crumb.parent);
|
|
57
|
+
if (!ref || !ref.id) {
|
|
58
|
+
return null
|
|
59
|
+
}
|
|
60
|
+
const row = rows && rows[crumb.parent] && typeof rows[crumb.parent] === 'object' ? rows[crumb.parent] : null;
|
|
61
|
+
let label = '';
|
|
62
|
+
if (row) {
|
|
63
|
+
label = (typeof crumb.labelField === 'string' && crumb.labelField !== '' ? text(readPath(row, crumb.labelField)) : '')
|
|
64
|
+
|| text(readPath(row, '@self.name')) || text(row.name) || text(row.title);
|
|
65
|
+
}
|
|
66
|
+
if (label === '' && typeof crumb.label === 'string' && crumb.label !== '') {
|
|
67
|
+
label = translate(crumb.label);
|
|
68
|
+
}
|
|
69
|
+
if (label === '') {
|
|
70
|
+
return null
|
|
71
|
+
}
|
|
72
|
+
const entry = { label };
|
|
73
|
+
if (typeof crumb.icon === 'string' && crumb.icon !== '') {
|
|
74
|
+
entry.icon = crumb.icon;
|
|
75
|
+
}
|
|
76
|
+
if (crumb.route) {
|
|
77
|
+
const param = typeof crumb.param === 'string' && crumb.param !== '' ? crumb.param : 'id';
|
|
78
|
+
entry.to = { name: crumb.route, params: { ...(crumb.params || {}), [param]: ref.id } };
|
|
79
|
+
} else if (typeof crumb.href === 'string' && crumb.href !== '') {
|
|
80
|
+
entry.href = crumb.href.split('{id}').join(encodeURIComponent(ref.id));
|
|
81
|
+
}
|
|
82
|
+
return entry
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
export { parentCrumb };
|
|
86
|
+
//# sourceMappingURL=parentCrumb.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parentCrumb.js","sources":["../../../src/utils/parentCrumb.js"],"sourcesContent":["/**\n * SPDX-FileCopyrightText: 2026 Conduction B.V.\n * SPDX-License-Identifier: EUPL-1.2\n *\n * parentCrumb: the breadcrumb entry for the record a sub-record belongs to.\n *\n * A crumb that carries `parent` names a `visibilityContext` entry of the\n * detail page. The page reads that record beside the loaded one; this\n * helper turns it into a crumb with the parent's label and a link to its\n * page.\n *\n * @module utils/parentCrumb\n */\n\n/**\n * Read a dotted path from an object.\n *\n * @param {object|null} obj The object to read.\n * @param {string} path A dotted path, e.g. `identifier` or `@self.name`.\n * @return {unknown} The value, or undefined.\n */\nfunction readPath(obj, path) {\n\treturn path.split('.').reduce((o, part) => (o === null || o === undefined ? undefined : o[part]), obj)\n}\n\n/**\n * A non-empty string for a value, or ''.\n *\n * @param {unknown} value Any value.\n * @return {string} The text.\n */\nfunction text(value) {\n\tif (typeof value === 'number') {\n\t\treturn String(value)\n\t}\n\treturn typeof value === 'string' ? value.trim() : ''\n}\n\n/**\n * The crumb for a record's parent.\n *\n * The crumb is dropped (null) when the record holds no reference to a\n * parent. Its label is the parent's `labelField` value, else the parent's\n * name or title, else the crumb's own `label` (translated); without any of\n * those it is dropped too. The link goes to `route` with the parent's id in\n * `param` (default `id`), or to `href` with `{id}` filled in.\n *\n * @param {object} crumb `{ parent, labelField?, label?, route?, params?, param?, href?, icon? }`.\n * @param {Array<{key: string, id: string}>} refs The page's context references.\n * @param {object} rows The context records read so far, by name.\n * @param {(key: string) => string} translate The host translate function.\n * @return {{label: string, to?: object, href?: string, icon?: string}|null} The crumb, or null.\n * @spec openspec/changes/detail-parent-crumb/specs/detail-page/spec.md#requirement-a-sub-record-trail-can-show-its-parent-record\n */\nexport function parentCrumb(crumb, refs, rows, translate) {\n\tconst ref = (refs || []).find((r) => r.key === crumb.parent)\n\tif (!ref || !ref.id) {\n\t\treturn null\n\t}\n\tconst row = rows && rows[crumb.parent] && typeof rows[crumb.parent] === 'object' ? rows[crumb.parent] : null\n\tlet label = ''\n\tif (row) {\n\t\tlabel = (typeof crumb.labelField === 'string' && crumb.labelField !== '' ? text(readPath(row, crumb.labelField)) : '')\n\t\t\t|| text(readPath(row, '@self.name')) || text(row.name) || text(row.title)\n\t}\n\tif (label === '' && typeof crumb.label === 'string' && crumb.label !== '') {\n\t\tlabel = translate(crumb.label)\n\t}\n\tif (label === '') {\n\t\treturn null\n\t}\n\tconst entry = { label }\n\tif (typeof crumb.icon === 'string' && crumb.icon !== '') {\n\t\tentry.icon = crumb.icon\n\t}\n\tif (crumb.route) {\n\t\tconst param = typeof crumb.param === 'string' && crumb.param !== '' ? crumb.param : 'id'\n\t\tentry.to = { name: crumb.route, params: { ...(crumb.params || {}), [param]: ref.id } }\n\t} else if (typeof crumb.href === 'string' && crumb.href !== '') {\n\t\tentry.href = crumb.href.split('{id}').join(encodeURIComponent(ref.id))\n\t}\n\treturn entry\n}\n"],"names":[],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAAS,QAAQ,CAAC,GAAG,EAAE,IAAI,EAAE;AAC7B,CAAC,OAAO,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,IAAI,MAAM,CAAC,KAAK,IAAI,IAAI,CAAC,KAAK,SAAS,GAAG,SAAS,GAAG,CAAC,CAAC,IAAI,CAAC,CAAC,EAAE,GAAG,CAAC;AACvG,CAAC;AACD;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAAS,IAAI,CAAC,KAAK,EAAE;AACrB,CAAC,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE;AAChC,EAAE,OAAO,MAAM,CAAC,KAAK,CA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