@m3ui-vue/m3ui-vue 1.2.2 → 1.3.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/API.md +3010 -376
- package/dist/MButton-Bl_BSUep.js +172 -0
- package/dist/MButton-Bl_BSUep.js.map +1 -0
- package/dist/MDialog-D_Yik8ou.js +173 -0
- package/dist/MDialog-D_Yik8ou.js.map +1 -0
- package/dist/MIconButton-DoNotQ9v.js +282 -0
- package/dist/MIconButton-DoNotQ9v.js.map +1 -0
- package/dist/MListItem-BxifHJdU.js +824 -0
- package/dist/MListItem-BxifHJdU.js.map +1 -0
- package/dist/MLoadingIndicator-BxbFhSX6.js +115 -0
- package/dist/MLoadingIndicator-BxbFhSX6.js.map +1 -0
- package/dist/MMenuItem-Bih0h4-n.js +604 -0
- package/dist/MMenuItem-Bih0h4-n.js.map +1 -0
- package/dist/MProgressBar-BCoruxA-.js +184 -0
- package/dist/MProgressBar-BCoruxA-.js.map +1 -0
- package/dist/MSeekBar-BeN9QcB3.js +435 -0
- package/dist/MSeekBar-BeN9QcB3.js.map +1 -0
- package/dist/MSegmentedButton-DL9JtJFX.js +65 -0
- package/dist/MSegmentedButton-DL9JtJFX.js.map +1 -0
- package/dist/MSlider-BVSbJlGS.js +691 -0
- package/dist/MSlider-BVSbJlGS.js.map +1 -0
- package/dist/MSpinner-C2SUnWk4.js +65 -0
- package/dist/MSpinner-C2SUnWk4.js.map +1 -0
- package/dist/MTextField-CEkWSZ2v.js +296 -0
- package/dist/MTextField-CEkWSZ2v.js.map +1 -0
- package/dist/MTooltip-CodJGEO-.js +756 -0
- package/dist/MTooltip-CodJGEO-.js.map +1 -0
- package/dist/_storageKeys-CYXsUBwK.js +18 -0
- package/dist/_storageKeys-CYXsUBwK.js.map +1 -0
- package/dist/_useEscapeStack-CjndQhqg.js +19 -0
- package/dist/_useEscapeStack-CjndQhqg.js.map +1 -0
- package/dist/api.json +1 -1
- package/dist/chart.js +1 -1
- package/dist/code-editor.js +1 -1
- package/dist/components/MAudioPlayer.vue.d.ts +115 -0
- package/dist/components/MBadge.vue.d.ts +1 -1
- package/dist/components/MBottomSheetScaffold.vue.d.ts +1 -1
- package/dist/components/MBox.vue.d.ts +1 -1
- package/dist/components/MButton.vue.d.ts +1 -1
- package/dist/components/MConfirmDialog.vue.d.ts +1 -1
- package/dist/components/MCopyButton.vue.d.ts +2 -2
- package/dist/components/MDataTable.vue.d.ts +2 -2
- package/dist/components/MDialog.vue.d.ts +2 -2
- package/dist/components/MDivider.vue.d.ts +1 -1
- package/dist/components/MDragHandle.vue.d.ts +1 -1
- package/dist/components/MDrawCanvas.vue.d.ts +150 -0
- package/dist/components/MDrawLayers.vue.d.ts +3 -0
- package/dist/components/MDrawToolbar.vue.d.ts +34 -0
- package/dist/components/MExportButton.vue.d.ts +1 -1
- package/dist/components/MFab.vue.d.ts +2 -2
- package/dist/components/MFabMenu.vue.d.ts +2 -2
- package/dist/components/MFixed.vue.d.ts +1 -1
- package/dist/components/MFlex.vue.d.ts +2 -2
- package/dist/components/MFloorPlan.vue.d.ts +248 -0
- package/dist/components/MFloorPlanInspector.vue.d.ts +56 -0
- package/dist/components/MFloorPlanToolbar.vue.d.ts +51 -0
- package/dist/components/MFlow.vue.d.ts +318 -0
- package/dist/components/MFlowControls.vue.d.ts +33 -0
- package/dist/components/MFlowHandle.vue.d.ts +16 -0
- package/dist/components/MFlowMinimap.vue.d.ts +22 -0
- package/dist/components/MFlowNode.vue.d.ts +35 -0
- package/dist/components/MGantt.vue.d.ts +141 -0
- package/dist/components/MGanttControls.vue.d.ts +32 -0
- package/dist/components/MIconButton.vue.d.ts +3 -1
- package/dist/components/MImageCropper.vue.d.ts +110 -0
- package/dist/components/MInfiniteScroll.vue.d.ts +1 -1
- package/dist/components/MLightbox.vue.d.ts +2 -2
- package/dist/components/MList.vue.d.ts +1 -1
- package/dist/components/MLoadingOverlay.vue.d.ts +1 -1
- package/dist/components/MMapControl.vue.d.ts +1 -1
- package/dist/components/MMapSearch.vue.d.ts +1 -1
- package/dist/components/MMaskField.vue.d.ts +12 -1
- package/dist/components/MMenu.vue.d.ts +1 -1
- package/dist/components/MNavigationDrawer.vue.d.ts +1 -1
- package/dist/components/MNumberField.vue.d.ts +11 -2
- package/dist/components/MPdfViewer.vue.d.ts +174 -0
- package/dist/components/MPullToRefresh.vue.d.ts +1 -1
- package/dist/components/MResourceTimeline.vue.d.ts +149 -0
- package/dist/components/MScheduler.vue.d.ts +3 -3
- package/dist/components/MScheme.vue.d.ts +1 -1
- package/dist/components/MSearchField.vue.d.ts +1 -1
- package/dist/components/MSeekBar.vue.d.ts +1 -1
- package/dist/components/MSimpleCarousel.vue.d.ts +1 -1
- package/dist/components/MSkeleton.vue.d.ts +1 -1
- package/dist/components/MSlider.vue.d.ts +2 -2
- package/dist/components/MSparkline.vue.d.ts +1 -1
- package/dist/components/MSplitter.vue.d.ts +1 -1
- package/dist/components/MStack.vue.d.ts +2 -2
- package/dist/components/MSwipeToDismiss.vue.d.ts +1 -1
- package/dist/components/MSwitch.vue.d.ts +1 -1
- package/dist/components/MTable.vue.d.ts +1 -1
- package/dist/components/MTagInput.vue.d.ts +12 -1
- package/dist/components/MTextField.vue.d.ts +13 -2
- package/dist/components/MToolbar.vue.d.ts +1 -1
- package/dist/components/MTree.vue.d.ts +2 -2
- package/dist/components/MVideoPlayer.vue.d.ts +253 -0
- package/dist/components/MVirtualTable.vue.d.ts +1 -1
- package/dist/components/MWindow.vue.d.ts +3 -3
- package/dist/components/_MFlowEdge.vue.d.ts +9 -0
- package/dist/components/_MFlowEdgeLabel.vue.d.ts +9 -0
- package/dist/components/_MFlowNodeShell.vue.d.ts +9 -0
- package/dist/components/_MPdfPage.vue.d.ts +76 -0
- package/dist/components/_MTimeBackground.vue.d.ts +14 -0
- package/dist/components/_MTimeHeader.vue.d.ts +20 -0
- package/dist/composables/_flowPanel.d.ts +2 -0
- package/dist/composables/_flowSlot.d.ts +5 -0
- package/dist/composables/_ganttTime.d.ts +41 -0
- package/dist/composables/_useTimeAxis.d.ts +90 -0
- package/dist/composables/drawGeometry.d.ts +119 -0
- package/dist/composables/flowFormats.d.ts +79 -0
- package/dist/composables/flowLayout.d.ts +45 -0
- package/dist/composables/flowPaths.d.ts +53 -0
- package/dist/composables/ganttFormats.d.ts +52 -0
- package/dist/composables/ganttSchedule.d.ts +99 -0
- package/dist/composables/useDrawing.d.ts +44 -0
- package/dist/composables/useFloorPlan.d.ts +58 -0
- package/dist/composables/useFlow.d.ts +266 -0
- package/dist/composables/useGantt.d.ts +87 -0
- package/dist/composables/useLocale.d.ts +204 -0
- package/dist/composables/useMediaPlayer.d.ts +101 -0
- package/dist/composables/usePdf.d.ts +119 -0
- package/dist/composables/useResourceTimeline.d.ts +70 -0
- package/dist/draw.d.ts +7 -0
- package/dist/draw.js +1702 -0
- package/dist/draw.js.map +1 -0
- package/dist/flow.d.ts +14 -0
- package/dist/flow.js +3547 -0
- package/dist/flow.js.map +1 -0
- package/dist/flowPaths-CUc6X373.js +161 -0
- package/dist/flowPaths-CUc6X373.js.map +1 -0
- package/dist/gantt.d.ts +12 -0
- package/dist/gantt.js +3575 -0
- package/dist/gantt.js.map +1 -0
- package/dist/index.d.ts +9 -0
- package/dist/locales/index.js +1435 -7
- package/dist/locales/index.js.map +1 -1
- package/dist/m3ui-vue.css +1 -1
- package/dist/m3ui.js +8248 -7637
- package/dist/m3ui.js.map +1 -1
- package/dist/map.js +113 -108
- package/dist/map.js.map +1 -1
- package/dist/media.d.ts +5 -0
- package/dist/media.js +1311 -0
- package/dist/media.js.map +1 -0
- package/dist/pdf.d.ts +4 -0
- package/dist/pdf.js +1871 -0
- package/dist/pdf.js.map +1 -0
- package/dist/rich-text-editor.js +28 -26
- package/dist/rich-text-editor.js.map +1 -1
- package/dist/styles.css +1 -1
- package/dist/{useLocale-JYxDDeXC.js → useLocale-CaWwi-b6.js} +206 -2
- package/dist/useLocale-CaWwi-b6.js.map +1 -0
- package/dist/{useThemeTokens-y0HZpyhL.js → useThemeTokens-DQQcaWbE.js} +40 -54
- package/dist/useThemeTokens-DQQcaWbE.js.map +1 -0
- package/package.json +29 -5
- package/src/__tests__/MAudioPlayer.test.ts +75 -0
- package/src/__tests__/MDrawCanvas.test.ts +118 -0
- package/src/__tests__/MFloorPlan.test.ts +299 -0
- package/src/__tests__/MFlow.test.ts +590 -0
- package/src/__tests__/MGantt.test.ts +130 -0
- package/src/__tests__/MImageCropper.test.ts +89 -0
- package/src/__tests__/MPdfViewer.test.ts +235 -0
- package/src/__tests__/MResourceTimeline.test.ts +102 -0
- package/src/__tests__/MVideoPlayer.test.ts +201 -0
- package/src/__tests__/drawGeometry.test.ts +58 -0
- package/src/__tests__/fieldExpose.test.ts +30 -0
- package/src/__tests__/flowFormats.test.ts +185 -0
- package/src/__tests__/flowLayout.test.ts +113 -0
- package/src/__tests__/ganttFormats.test.ts +76 -0
- package/src/__tests__/ganttSchedule.test.ts +136 -0
- package/src/__tests__/pdfMock.ts +83 -0
- package/src/__tests__/useMediaPlayer.test.ts +182 -0
- package/src/__tests__/usePdf.test.ts +102 -0
- package/src/components/MAudioPlayer.vue +319 -0
- package/src/components/MDrawCanvas.vue +819 -0
- package/src/components/MDrawLayers.vue +114 -0
- package/src/components/MDrawToolbar.vue +171 -0
- package/src/components/MFloorPlan.vue +1080 -0
- package/src/components/MFloorPlanInspector.vue +169 -0
- package/src/components/MFloorPlanToolbar.vue +128 -0
- package/src/components/MFlow.vue +2060 -0
- package/src/components/MFlowControls.vue +110 -0
- package/src/components/MFlowHandle.vue +60 -0
- package/src/components/MFlowMinimap.vue +134 -0
- package/src/components/MFlowNode.vue +98 -0
- package/src/components/MGantt.vue +1609 -0
- package/src/components/MGanttControls.vue +77 -0
- package/src/components/MIconButton.vue +3 -1
- package/src/components/MImageCropper.vue +507 -0
- package/src/components/MMaskField.vue +13 -0
- package/src/components/MNumberField.vue +13 -0
- package/src/components/MPdfViewer.vue +1270 -0
- package/src/components/MResourceTimeline.vue +1020 -0
- package/src/components/MTagInput.vue +13 -0
- package/src/components/MTextField.vue +16 -0
- package/src/components/MVideoPlayer.vue +839 -0
- package/src/components/_MFlowEdge.vue +100 -0
- package/src/components/_MFlowEdgeLabel.vue +56 -0
- package/src/components/_MFlowNodeShell.vue +111 -0
- package/src/components/_MPdfPage.vue +456 -0
- package/src/components/_MTimeBackground.vue +16 -0
- package/src/components/_MTimeHeader.vue +31 -0
- package/src/composables/_flowPanel.ts +13 -0
- package/src/composables/_flowSlot.ts +6 -0
- package/src/composables/_ganttTime.ts +200 -0
- package/src/composables/_useTimeAxis.ts +224 -0
- package/src/composables/drawGeometry.ts +405 -0
- package/src/composables/flowFormats.ts +916 -0
- package/src/composables/flowLayout.ts +297 -0
- package/src/composables/flowPaths.ts +239 -0
- package/src/composables/ganttFormats.ts +366 -0
- package/src/composables/ganttSchedule.ts +403 -0
- package/src/composables/useDrawing.ts +53 -0
- package/src/composables/useFloorPlan.ts +73 -0
- package/src/composables/useFlow.ts +250 -0
- package/src/composables/useGantt.ts +92 -0
- package/src/composables/useLocale.ts +410 -0
- package/src/composables/useMediaPlayer.ts +406 -0
- package/src/composables/usePdf.ts +456 -0
- package/src/composables/useResourceTimeline.ts +76 -0
- package/src/draw.ts +25 -0
- package/src/flow.ts +26 -0
- package/src/gantt.ts +12 -0
- package/src/index.ts +9 -0
- package/src/locales/de.ts +204 -0
- package/src/locales/es.ts +204 -0
- package/src/locales/fr.ts +204 -0
- package/src/locales/ja.ts +204 -0
- package/src/locales/ko.ts +204 -0
- package/src/locales/pt.ts +204 -0
- package/src/locales/zh.ts +204 -0
- package/src/media.ts +5 -0
- package/src/pdf.ts +15 -0
- package/dist/MMenuItem-D4Gx_l3F.js +0 -929
- package/dist/MMenuItem-D4Gx_l3F.js.map +0 -1
- package/dist/MSlider-Dx_S3vJ9.js +0 -1506
- package/dist/MSlider-Dx_S3vJ9.js.map +0 -1
- package/dist/MTextField-Bz8JIsnl.js +0 -633
- package/dist/MTextField-Bz8JIsnl.js.map +0 -1
- package/dist/useLocale-JYxDDeXC.js.map +0 -1
- package/dist/useThemeTokens-y0HZpyhL.js.map +0 -1
|
@@ -0,0 +1,366 @@
|
|
|
1
|
+
// Tasks as files for MGantt: CSV (a spreadsheet's export), JSON, and Microsoft Project's XML (MSPDI, which
|
|
2
|
+
// Project, ProjectLibre, GanttProject and most planning tools read and write). Pure functions without
|
|
3
|
+
// dependencies; the XML is read by a small parser of its own, so it works without a DOM too.
|
|
4
|
+
import { normalizeDependency, summaryIds, taskSpan, type GanttDependency, type GanttTask } from './ganttSchedule'
|
|
5
|
+
import { DAY, addDays, formatDate, isDateOnly, parseDate, startOfDay } from './_ganttTime'
|
|
6
|
+
|
|
7
|
+
// ── Dependencies as text: "a; b SS+2; c FF-1" ─────────────────────────────────────────────────────────────
|
|
8
|
+
|
|
9
|
+
function depToText(d: string | GanttDependency) {
|
|
10
|
+
const n = normalizeDependency(d)
|
|
11
|
+
return `${n.id}${n.type !== 'FS' || n.lag ? ` ${n.type}` : ''}${n.lag ? (n.lag > 0 ? `+${n.lag}` : String(n.lag)) : ''}`
|
|
12
|
+
}
|
|
13
|
+
function depsFromText(s: string): (string | GanttDependency)[] {
|
|
14
|
+
const out: (string | GanttDependency)[] = []
|
|
15
|
+
for (const part of s.split(/[;,]/)) {
|
|
16
|
+
const m = /^\s*(.+?)(?:\s+(FS|SS|FF|SF))?\s*([+-]\s*\d+(?:\.\d+)?)?\s*$/i.exec(part)
|
|
17
|
+
if (!m || !m[1]!.trim()) continue
|
|
18
|
+
const type = (m[2]?.toUpperCase() ?? 'FS') as GanttDependency['type']
|
|
19
|
+
const lag = m[3] ? Number(m[3].replace(/\s/g, '')) : 0
|
|
20
|
+
out.push(type === 'FS' && !lag ? m[1]!.trim() : { id: m[1]!.trim(), type, ...(lag ? { lag } : {}) })
|
|
21
|
+
}
|
|
22
|
+
return out
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
// ── CSV ───────────────────────────────────────────────────────────────────────────────────────────────────
|
|
26
|
+
|
|
27
|
+
export interface GanttCsvOptions {
|
|
28
|
+
/** Field separator (default `,`; reading, `;` and tabs are detected) */
|
|
29
|
+
separator?: string
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
const CSV_COLUMNS = ['id', 'name', 'start', 'end', 'progress', 'type', 'parent', 'dependencies', 'color', 'baselineStart', 'baselineEnd'] as const
|
|
33
|
+
|
|
34
|
+
function csvCell(v: string, sep: string) {
|
|
35
|
+
return /["\n\r]/.test(v) || v.includes(sep) ? `"${v.replace(/"/g, '""')}"` : v
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Tasks as CSV, one row each: id, name, start, end, progress, type, parent, dependencies (`a; b SS+2`), color and the
|
|
40
|
+
* baseline. `data` isn't written (keep it in JSON).
|
|
41
|
+
*/
|
|
42
|
+
export function toGanttCsv(tasks: readonly GanttTask[], options: GanttCsvOptions = {}): string {
|
|
43
|
+
const sep = options.separator ?? ','
|
|
44
|
+
const rows = [CSV_COLUMNS.join(sep)]
|
|
45
|
+
for (const t of tasks) {
|
|
46
|
+
const cells = [
|
|
47
|
+
t.id, t.name, t.start, t.end ?? '', t.progress === undefined ? '' : String(t.progress), t.type ?? '', t.parentId ?? '',
|
|
48
|
+
(t.dependencies ?? []).map(depToText).join('; '), t.color ?? '', t.baselineStart ?? '', t.baselineEnd ?? '',
|
|
49
|
+
]
|
|
50
|
+
rows.push(cells.map((c) => csvCell(c, sep)).join(sep))
|
|
51
|
+
}
|
|
52
|
+
return rows.join('\n') + '\n'
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
function parseCsvRows(text: string, sep: string): string[][] {
|
|
56
|
+
const rows: string[][] = []
|
|
57
|
+
let row: string[] = []
|
|
58
|
+
let cell = ''
|
|
59
|
+
let quoted = false
|
|
60
|
+
for (let i = 0; i < text.length; i++) {
|
|
61
|
+
const c = text[i]!
|
|
62
|
+
if (quoted) {
|
|
63
|
+
if (c === '"' && text[i + 1] === '"') { cell += '"'; i++ }
|
|
64
|
+
else if (c === '"') quoted = false
|
|
65
|
+
else cell += c
|
|
66
|
+
} else if (c === '"' && !cell) quoted = true
|
|
67
|
+
else if (c === sep) { row.push(cell); cell = '' }
|
|
68
|
+
else if (c === '\n' || c === '\r') {
|
|
69
|
+
if (c === '\r' && text[i + 1] === '\n') i++
|
|
70
|
+
row.push(cell)
|
|
71
|
+
if (row.some((x) => x.trim())) rows.push(row)
|
|
72
|
+
row = []
|
|
73
|
+
cell = ''
|
|
74
|
+
} else cell += c
|
|
75
|
+
}
|
|
76
|
+
row.push(cell)
|
|
77
|
+
if (row.some((x) => x.trim())) rows.push(row)
|
|
78
|
+
return rows
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
// Header names other tools use, lower case without spaces
|
|
82
|
+
const CSV_ALIASES: Record<string, (typeof CSV_COLUMNS)[number]> = {
|
|
83
|
+
id: 'id', uid: 'id', key: 'id', '#': 'id',
|
|
84
|
+
name: 'name', task: 'name', taskname: 'name', title: 'name', summary: 'name',
|
|
85
|
+
start: 'start', startdate: 'start', begin: 'start', from: 'start',
|
|
86
|
+
end: 'end', finish: 'end', enddate: 'end', finishdate: 'end', due: 'end', duedate: 'end', to: 'end',
|
|
87
|
+
progress: 'progress', percentcomplete: 'progress', '%complete': 'progress', complete: 'progress', done: 'progress',
|
|
88
|
+
type: 'type', kind: 'type',
|
|
89
|
+
parent: 'parent', parentid: 'parent',
|
|
90
|
+
dependencies: 'dependencies', predecessors: 'dependencies', dependson: 'dependencies', depends: 'dependencies',
|
|
91
|
+
color: 'color',
|
|
92
|
+
baselinestart: 'baselineStart', baselineend: 'baselineEnd', baselinefinish: 'baselineEnd',
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
// Dates as tools write them: ISO, or day/month/year (the separator decides nothing, so `dayFirst` does)
|
|
96
|
+
function csvDate(v: string, dayFirst: boolean): string | undefined {
|
|
97
|
+
const s = v.trim()
|
|
98
|
+
if (!s) return undefined
|
|
99
|
+
const iso = /^(\d{4}-\d{2}-\d{2})(?:[T ](\d{2}:\d{2}))?/.exec(s)
|
|
100
|
+
if (iso) return iso[2] ? `${iso[1]}T${iso[2]}` : iso[1]
|
|
101
|
+
const m = /^(\d{1,2})[/.-](\d{1,2})[/.-](\d{2,4})(?:\s+(\d{1,2}):(\d{2}))?$/.exec(s)
|
|
102
|
+
if (m) {
|
|
103
|
+
const [a, b] = dayFirst ? [m[2]!, m[1]!] : [m[1]!, m[2]!]
|
|
104
|
+
const y = m[3]!.length === 2 ? `20${m[3]}` : m[3]!
|
|
105
|
+
const date = `${y}-${a.padStart(2, '0')}-${b.padStart(2, '0')}`
|
|
106
|
+
return m[4] ? `${date}T${m[4].padStart(2, '0')}:${m[5]}` : date
|
|
107
|
+
}
|
|
108
|
+
const ms = Date.parse(s)
|
|
109
|
+
return Number.isNaN(ms) ? undefined : formatDate(ms, !/\d:\d/.test(s))
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* Reads tasks from CSV with a header row: the columns `toGanttCsv` writes, or what other tools call them (Task Name,
|
|
114
|
+
* Start Date, Finish, % Complete, Predecessors…; case and spaces don't matter). Rows without an id get one; without
|
|
115
|
+
* an end, a milestone. `dayFirst` reads `03/04/2026` as the 3rd of April (default true).
|
|
116
|
+
*/
|
|
117
|
+
export function parseGanttCsv(text: string, options: GanttCsvOptions & { dayFirst?: boolean } = {}): GanttTask[] {
|
|
118
|
+
const first = text.split(/\r?\n/, 1)[0] ?? ''
|
|
119
|
+
const sep = options.separator ?? ([',', ';', '\t'].map((s) => [s, first.split(s).length] as const).sort((a, b) => b[1] - a[1])[0]![0])
|
|
120
|
+
const rows = parseCsvRows(text.replace(/^\uFEFF/, ''), sep)
|
|
121
|
+
const header = rows.shift()
|
|
122
|
+
if (!header) return []
|
|
123
|
+
const cols = header.map((h) => CSV_ALIASES[h.toLowerCase().replace(/[\s_-]/g, '')])
|
|
124
|
+
if (!cols.includes('name') || !cols.includes('start')) throw new SyntaxError('The CSV needs a name and a start column')
|
|
125
|
+
const dayFirst = options.dayFirst ?? true
|
|
126
|
+
const tasks: GanttTask[] = []
|
|
127
|
+
rows.forEach((r, i) => {
|
|
128
|
+
const get = (k: (typeof CSV_COLUMNS)[number]) => {
|
|
129
|
+
const at = cols.indexOf(k)
|
|
130
|
+
return at < 0 ? '' : (r[at] ?? '').trim()
|
|
131
|
+
}
|
|
132
|
+
const start = csvDate(get('start'), dayFirst)
|
|
133
|
+
if (!start) return
|
|
134
|
+
const t: GanttTask = { id: get('id') || `t${i + 1}`, name: get('name'), start }
|
|
135
|
+
const end = csvDate(get('end'), dayFirst)
|
|
136
|
+
if (end) t.end = end
|
|
137
|
+
const progress = parseFloat(get('progress').replace('%', ''))
|
|
138
|
+
if (Number.isFinite(progress)) t.progress = progress > 0 && progress <= 1 && get('progress').includes('.') && !get('progress').includes('%') ? progress * 100 : progress
|
|
139
|
+
const type = get('type').toLowerCase()
|
|
140
|
+
if (type === 'task' || type === 'milestone' || type === 'summary') t.type = type
|
|
141
|
+
else if (!end) t.type = 'milestone'
|
|
142
|
+
if (get('parent')) t.parentId = get('parent')
|
|
143
|
+
if (get('dependencies')) t.dependencies = depsFromText(get('dependencies'))
|
|
144
|
+
const color = get('color')
|
|
145
|
+
if (['primary', 'secondary', 'tertiary', 'error', 'success', 'neutral'].includes(color)) t.color = color as GanttTask['color']
|
|
146
|
+
const bs = csvDate(get('baselineStart'), dayFirst)
|
|
147
|
+
const be = csvDate(get('baselineEnd'), dayFirst)
|
|
148
|
+
if (bs) t.baselineStart = bs
|
|
149
|
+
if (be) t.baselineEnd = be
|
|
150
|
+
tasks.push(t)
|
|
151
|
+
})
|
|
152
|
+
return tasks
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
// ── JSON ──────────────────────────────────────────────────────────────────────────────────────────────────
|
|
156
|
+
|
|
157
|
+
/** Tasks as JSON, `{ format: 'm3ui-gantt', version: 1, tasks }`, everything included (`data` too) */
|
|
158
|
+
export function toGanttJson(tasks: readonly GanttTask[], options: { space?: number } = {}): string {
|
|
159
|
+
return JSON.stringify({ format: 'm3ui-gantt', version: 1, tasks }, null, options.space ?? 2)
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
/**
|
|
163
|
+
* Reads tasks from JSON: what `toGanttJson` writes, a bare array of tasks, or `{ tasks: [...] }`. Each needs a name
|
|
164
|
+
* and a start; ids are filled in when missing. Throws a SyntaxError on anything else.
|
|
165
|
+
*/
|
|
166
|
+
export function parseGanttJson(text: string): GanttTask[] {
|
|
167
|
+
const v = JSON.parse(text) as unknown
|
|
168
|
+
const list = Array.isArray(v) ? v : v && typeof v === 'object' && Array.isArray((v as { tasks?: unknown }).tasks) ? (v as { tasks: unknown[] }).tasks : null
|
|
169
|
+
if (!list) throw new SyntaxError('Expected an array of tasks or { tasks: [...] }')
|
|
170
|
+
return list.map((raw, i) => {
|
|
171
|
+
if (!raw || typeof raw !== 'object') throw new SyntaxError(`Task ${i + 1} isn't an object`)
|
|
172
|
+
const t = raw as Partial<GanttTask>
|
|
173
|
+
if (typeof t.start !== 'string' || Number.isNaN(parseDate(t.start))) throw new SyntaxError(`Task ${i + 1} has no valid start`)
|
|
174
|
+
return { ...t, id: t.id === undefined || t.id === null ? `t${i + 1}` : String(t.id), name: String(t.name ?? ''), start: t.start } as GanttTask
|
|
175
|
+
})
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
// ── Microsoft Project XML (MSPDI) ─────────────────────────────────────────────────────────────────────────
|
|
179
|
+
|
|
180
|
+
interface XmlNode { name: string; children: XmlNode[]; text: string }
|
|
181
|
+
|
|
182
|
+
function decodeXml(s: string) {
|
|
183
|
+
return s
|
|
184
|
+
.replace(/<!\[CDATA\[([\s\S]*?)\]\]>/g, '$1')
|
|
185
|
+
.replace(/&#x([0-9a-f]+);/gi, (_, h) => String.fromCodePoint(parseInt(h, 16)))
|
|
186
|
+
.replace(/&#(\d+);/g, (_, d) => String.fromCodePoint(Number(d)))
|
|
187
|
+
.replace(/</g, '<').replace(/>/g, '>').replace(/"/g, '"').replace(/'/g, "'").replace(/&/g, '&')
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
// Elements and their text; attributes, comments and declarations are skipped (MSPDI keeps its data in elements)
|
|
191
|
+
function parseXml(src: string): XmlNode {
|
|
192
|
+
const root: XmlNode = { name: '#root', children: [], text: '' }
|
|
193
|
+
const stack = [root]
|
|
194
|
+
const re = /<!--[\s\S]*?-->|<\?[\s\S]*?\?>|<!\[CDATA\[[\s\S]*?\]\]>|<![^>]*>|<\/?([\w:.-]+)[^>]*?(\/?)>|[^<]+/g
|
|
195
|
+
for (let m: RegExpExecArray | null; (m = re.exec(src)); ) {
|
|
196
|
+
const tok = m[0]
|
|
197
|
+
const top = stack.at(-1)!
|
|
198
|
+
if (tok.startsWith('<![CDATA[')) top.text += decodeXml(tok)
|
|
199
|
+
else if (tok.startsWith('<!') || tok.startsWith('<?')) continue
|
|
200
|
+
else if (tok.startsWith('</')) {
|
|
201
|
+
const name = m[1]!.replace(/^.*:/, '')
|
|
202
|
+
while (stack.length > 1 && stack.pop()!.name !== name) { /* unclosed elements close with their parent */ }
|
|
203
|
+
} else if (tok.startsWith('<')) {
|
|
204
|
+
const node: XmlNode = { name: m[1]!.replace(/^.*:/, ''), children: [], text: '' }
|
|
205
|
+
top.children.push(node)
|
|
206
|
+
if (!m[2]) stack.push(node)
|
|
207
|
+
} else top.text += decodeXml(tok)
|
|
208
|
+
}
|
|
209
|
+
return root
|
|
210
|
+
}
|
|
211
|
+
const child = (n: XmlNode | undefined, name: string) => n?.children.find((c) => c.name === name)
|
|
212
|
+
const textOf = (n: XmlNode | undefined, name: string) => child(n, name)?.text.trim() ?? ''
|
|
213
|
+
|
|
214
|
+
// MSPDI dependency types: 0 FF, 1 FS, 2 SF, 3 SS
|
|
215
|
+
const LINK_TYPES: GanttDependency['type'][] = ['FF', 'FS', 'SF', 'SS']
|
|
216
|
+
// Lags are in tenths of a minute; LagFormat 7 is days (of 8 working hours), 5 elapsed days and so on
|
|
217
|
+
const TENTHS_PER_DAY = 8 * 60 * 10
|
|
218
|
+
|
|
219
|
+
export interface GanttXmlOptions {
|
|
220
|
+
/** The project's name */
|
|
221
|
+
name?: string
|
|
222
|
+
/** Working hours a date-only task's days run, for Project's datetimes (default 8 to 17) */
|
|
223
|
+
dayStart?: number
|
|
224
|
+
dayEnd?: number
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
const xmlEscape = (s: string) => s.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>')
|
|
228
|
+
function xmlTime(ms: number) {
|
|
229
|
+
return `${formatDate(ms, false).slice(0, 16)}:00`
|
|
230
|
+
}
|
|
231
|
+
// "PT40H0M0S"
|
|
232
|
+
function xmlDuration(ms: number) {
|
|
233
|
+
const minutes = Math.round(ms / 60_000)
|
|
234
|
+
return `PT${Math.floor(minutes / 60)}H${minutes % 60}M0S`
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
/**
|
|
238
|
+
* Tasks as a Microsoft Project XML file (MSPDI): outline levels for summaries, start and finish (a date-only
|
|
239
|
+
* task's days from `dayStart` to `dayEnd`), duration, percent complete, milestones, predecessors with their type
|
|
240
|
+
* and lag (in days), and the baseline. Project, ProjectLibre and GanttProject open it.
|
|
241
|
+
*/
|
|
242
|
+
export function toMsProjectXml(tasks: readonly GanttTask[], options: GanttXmlOptions = {}): string {
|
|
243
|
+
const ds = options.dayStart ?? 8
|
|
244
|
+
const de = options.dayEnd ?? 17
|
|
245
|
+
const ids = new Set(tasks.map((t) => t.id))
|
|
246
|
+
const sums = summaryIds(tasks)
|
|
247
|
+
const kids = new Map<string | undefined, GanttTask[]>()
|
|
248
|
+
for (const t of tasks) {
|
|
249
|
+
const p = t.parentId && ids.has(t.parentId) ? t.parentId : undefined
|
|
250
|
+
;(kids.get(p) ?? kids.set(p, []).get(p)!).push(t)
|
|
251
|
+
}
|
|
252
|
+
// Project lists tasks in outline order: each summary followed by its tasks
|
|
253
|
+
const ordered: { t: GanttTask; level: number }[] = []
|
|
254
|
+
const walk = (p: string | undefined, level: number) => {
|
|
255
|
+
for (const t of kids.get(p) ?? []) {
|
|
256
|
+
ordered.push({ t, level })
|
|
257
|
+
if (level < 100) walk(t.id, level + 1)
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
walk(undefined, 1)
|
|
261
|
+
const uid = new Map(ordered.map((o, i) => [o.t.id, i + 1]))
|
|
262
|
+
const times = (t: GanttTask, start?: string, end?: string) => {
|
|
263
|
+
const s = taskSpan({ start: start ?? t.start, end: end ?? t.end, type: t.type })
|
|
264
|
+
if (!s.dateOnly) return { start: s.start, finish: s.end, work: s.end - s.start }
|
|
265
|
+
const finishDay = s.end > s.start ? addDays(s.end, -1) : s.start
|
|
266
|
+
const days = Math.max(0, Math.round((startOfDay(s.end) - startOfDay(s.start)) / DAY))
|
|
267
|
+
return { start: s.start + ds * 3_600_000, finish: (s.end > s.start ? finishDay + de * 3_600_000 : s.start + ds * 3_600_000), work: days * (de - ds) * 3_600_000 }
|
|
268
|
+
}
|
|
269
|
+
const out = ['<?xml version="1.0" encoding="UTF-8" standalone="yes"?>', '<Project xmlns="http://schemas.microsoft.com/project">']
|
|
270
|
+
if (options.name) out.push(` <Name>${xmlEscape(options.name)}</Name>`, ` <Title>${xmlEscape(options.name)}</Title>`)
|
|
271
|
+
out.push(' <ScheduleFromStart>1</ScheduleFromStart>', ` <DefaultStartTime>${String(ds).padStart(2, '0')}:00:00</DefaultStartTime>`, ` <DefaultFinishTime>${String(de).padStart(2, '0')}:00:00</DefaultFinishTime>`, ' <Tasks>')
|
|
272
|
+
ordered.forEach(({ t, level }, i) => {
|
|
273
|
+
const tm = times(t)
|
|
274
|
+
const milestone = t.type === 'milestone' || !t.end
|
|
275
|
+
const lines = [
|
|
276
|
+
`<UID>${i + 1}</UID>`, `<ID>${i + 1}</ID>`, `<Name>${xmlEscape(t.name)}</Name>`,
|
|
277
|
+
`<OutlineLevel>${level}</OutlineLevel>`,
|
|
278
|
+
`<Start>${xmlTime(tm.start)}</Start>`, `<Finish>${xmlTime(tm.finish)}</Finish>`,
|
|
279
|
+
`<Duration>${xmlDuration(milestone ? 0 : tm.work)}</Duration>`, '<DurationFormat>7</DurationFormat>',
|
|
280
|
+
`<PercentComplete>${Math.round(t.progress ?? 0)}</PercentComplete>`,
|
|
281
|
+
`<Milestone>${milestone ? 1 : 0}</Milestone>`, `<Summary>${sums.has(t.id) ? 1 : 0}</Summary>`,
|
|
282
|
+
]
|
|
283
|
+
if (t.baselineStart) {
|
|
284
|
+
const b = times(t, t.baselineStart, t.baselineEnd ?? (t.end ? t.baselineStart : undefined))
|
|
285
|
+
lines.push(`<Baseline><Number>0</Number><Start>${xmlTime(b.start)}</Start><Finish>${xmlTime(b.finish)}</Finish><Duration>${xmlDuration(b.work)}</Duration></Baseline>`)
|
|
286
|
+
}
|
|
287
|
+
for (const raw of t.dependencies ?? []) {
|
|
288
|
+
const d = normalizeDependency(raw)
|
|
289
|
+
if (!uid.has(d.id)) continue
|
|
290
|
+
lines.push(`<PredecessorLink><PredecessorUID>${uid.get(d.id)}</PredecessorUID><Type>${LINK_TYPES.indexOf(d.type)}</Type><LinkLag>${Math.round(d.lag * TENTHS_PER_DAY)}</LinkLag><LagFormat>7</LagFormat></PredecessorLink>`)
|
|
291
|
+
}
|
|
292
|
+
out.push(' <Task>', ...lines.map((l) => ` ${l}`), ' </Task>')
|
|
293
|
+
})
|
|
294
|
+
out.push(' </Tasks>', '</Project>')
|
|
295
|
+
return out.join('\n') + '\n'
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
/**
|
|
299
|
+
* Reads a Microsoft Project XML file (MSPDI, as Project, ProjectLibre or GanttProject save it): the outline
|
|
300
|
+
* (summaries from outline levels), names, start and finish, percent complete, milestones, predecessors (type and lag
|
|
301
|
+
* in days) and the first baseline. With `dates: 'auto'` (default) a project whose tasks all start and finish at the
|
|
302
|
+
* day's working hours comes in as whole days; `'datetime'` keeps the times. The project's name comes back too.
|
|
303
|
+
*/
|
|
304
|
+
export function parseMsProjectXml(text: string, options: { dates?: 'auto' | 'date' | 'datetime' } = {}): { name?: string; tasks: GanttTask[] } {
|
|
305
|
+
const doc = parseXml(text)
|
|
306
|
+
const project = child(doc, 'Project')
|
|
307
|
+
if (!project) throw new SyntaxError('Not a Microsoft Project XML file (no <Project>)')
|
|
308
|
+
const items = child(project, 'Tasks')?.children.filter((c) => c.name === 'Task') ?? []
|
|
309
|
+
const raw = items
|
|
310
|
+
.map((n) => ({
|
|
311
|
+
uid: textOf(n, 'UID'),
|
|
312
|
+
name: textOf(n, 'Name'),
|
|
313
|
+
level: Number(textOf(n, 'OutlineLevel') || 1),
|
|
314
|
+
start: textOf(n, 'Start'),
|
|
315
|
+
finish: textOf(n, 'Finish'),
|
|
316
|
+
progress: Number(textOf(n, 'PercentComplete') || 0),
|
|
317
|
+
milestone: textOf(n, 'Milestone') === '1',
|
|
318
|
+
summary: textOf(n, 'Summary') === '1',
|
|
319
|
+
nullTask: textOf(n, 'IsNull') === '1',
|
|
320
|
+
baseline: n.children.find((c) => c.name === 'Baseline' && (textOf(c, 'Number') || '0') === '0'),
|
|
321
|
+
links: n.children.filter((c) => c.name === 'PredecessorLink'),
|
|
322
|
+
}))
|
|
323
|
+
// Project's task 0 is the project's own summary
|
|
324
|
+
.filter((t) => t.uid && t.start && !t.nullTask && !(t.uid === '0' && t.level <= 0))
|
|
325
|
+
const midnights = raw.every((t) => /T(0?0:00|0?8:00|0?9:00)/.test(t.start) && (t.milestone || /T(0?0:00|1[6-8]:00|23:59)/.test(t.finish)))
|
|
326
|
+
const dateOnly = options.dates === 'date' || (options.dates !== 'datetime' && midnights)
|
|
327
|
+
const toDate = (s: string) => {
|
|
328
|
+
const ms = parseDate(s.slice(0, 19))
|
|
329
|
+
return formatDate(ms, dateOnly)
|
|
330
|
+
}
|
|
331
|
+
// A finish at midnight belongs to the day before
|
|
332
|
+
const toEnd = (s: string) => {
|
|
333
|
+
if (!dateOnly) return toDate(s)
|
|
334
|
+
const ms = parseDate(s.slice(0, 19))
|
|
335
|
+
return formatDate(startOfDay(ms) === ms ? addDays(ms, -1) : ms, true)
|
|
336
|
+
}
|
|
337
|
+
const parents: string[] = []
|
|
338
|
+
const tasks: GanttTask[] = raw.map((r) => {
|
|
339
|
+
parents.length = Math.max(0, r.level - 1)
|
|
340
|
+
const t: GanttTask = { id: r.uid, name: r.name, start: toDate(r.start) }
|
|
341
|
+
if (r.milestone) t.type = 'milestone'
|
|
342
|
+
else t.end = isDateOnly(t.start) ? toEnd(r.finish) : toDate(r.finish)
|
|
343
|
+
if (t.end && parseDate(t.end) < parseDate(t.start)) t.end = t.start
|
|
344
|
+
if (r.progress) t.progress = r.progress
|
|
345
|
+
const parent = parents[r.level - 2]
|
|
346
|
+
if (parent) t.parentId = parent
|
|
347
|
+
parents[r.level - 1] = r.uid
|
|
348
|
+
if (r.summary) t.type = 'summary'
|
|
349
|
+
if (r.baseline && textOf(r.baseline, 'Start')) {
|
|
350
|
+
t.baselineStart = toDate(textOf(r.baseline, 'Start'))
|
|
351
|
+
if (!r.milestone && textOf(r.baseline, 'Finish')) t.baselineEnd = isDateOnly(t.baselineStart) ? toEnd(textOf(r.baseline, 'Finish')) : toDate(textOf(r.baseline, 'Finish'))
|
|
352
|
+
}
|
|
353
|
+
const deps: (string | GanttDependency)[] = []
|
|
354
|
+
for (const l of r.links) {
|
|
355
|
+
const id = textOf(l, 'PredecessorUID')
|
|
356
|
+
if (!id) continue
|
|
357
|
+
const type = LINK_TYPES[Number(textOf(l, 'Type') || 1)] ?? 'FS'
|
|
358
|
+
const lag = Math.round((Number(textOf(l, 'LinkLag') || 0) / TENTHS_PER_DAY) * 100) / 100
|
|
359
|
+
deps.push(type === 'FS' && !lag ? id : { id, type, ...(lag ? { lag } : {}) })
|
|
360
|
+
}
|
|
361
|
+
if (deps.length) t.dependencies = deps
|
|
362
|
+
return t
|
|
363
|
+
})
|
|
364
|
+
const name = textOf(project, 'Title') || textOf(project, 'Name') || undefined
|
|
365
|
+
return { ...(name ? { name } : {}), tasks }
|
|
366
|
+
}
|