@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,403 @@
|
|
|
1
|
+
// Scheduling for MGantt, as pure functions over tasks: summaries rolled up from their children, dependencies pushed
|
|
2
|
+
// forward (or tasks pulled as soon as possible), the critical path with each task's slack, and working days.
|
|
3
|
+
// Tasks are treated as immutable: what changes comes back as new objects, the rest as they were.
|
|
4
|
+
import { DAY, addDays, daysBetween, formatDate, isDateOnly, isWorkingDay, parseDate, startOfDay } from './_ganttTime'
|
|
5
|
+
|
|
6
|
+
/** A predecessor of a task: finish-to-start (default), start-to-start, finish-to-finish or start-to-finish */
|
|
7
|
+
export interface GanttDependency {
|
|
8
|
+
/** The predecessor's id */
|
|
9
|
+
id: string
|
|
10
|
+
type?: 'FS' | 'SS' | 'FF' | 'SF'
|
|
11
|
+
/** Days between them (negative overlaps them); working days with a calendar */
|
|
12
|
+
lag?: number
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/** A task. MGantt emits new arrays with new objects for whatever changed (`v-model:tasks`) */
|
|
16
|
+
export interface GanttTask<D = any> {
|
|
17
|
+
id: string
|
|
18
|
+
name: string
|
|
19
|
+
/** `YYYY-MM-DD` (whole days) or a datetime (`YYYY-MM-DDTHH:mm`, local, or ISO with a zone) */
|
|
20
|
+
start: string
|
|
21
|
+
/** A date is the last day (inclusive); a datetime is when it ends. A milestone needs none */
|
|
22
|
+
end?: string
|
|
23
|
+
/** 0 to 100 */
|
|
24
|
+
progress?: number
|
|
25
|
+
/** `summary` is implied for a task with children (its dates and progress roll up from them) */
|
|
26
|
+
type?: 'task' | 'milestone' | 'summary'
|
|
27
|
+
/** The summary task it belongs to */
|
|
28
|
+
parentId?: string
|
|
29
|
+
/** Its predecessors: ids (finish-to-start) or `GanttDependency` */
|
|
30
|
+
dependencies?: (string | GanttDependency)[]
|
|
31
|
+
/** An M3 role (default `primary`; `summary` defaults to `neutral`) */
|
|
32
|
+
color?: 'primary' | 'secondary' | 'tertiary' | 'error' | 'success' | 'neutral'
|
|
33
|
+
/** The plan it's compared with (MGantt's `baselines`) */
|
|
34
|
+
baselineStart?: string
|
|
35
|
+
baselineEnd?: string
|
|
36
|
+
/** `false` keeps it from being moved, resized, linked, deleted or selected */
|
|
37
|
+
draggable?: boolean
|
|
38
|
+
resizable?: boolean
|
|
39
|
+
linkable?: boolean
|
|
40
|
+
deletable?: boolean
|
|
41
|
+
selectable?: boolean
|
|
42
|
+
class?: string
|
|
43
|
+
data?: D
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/** Which days are worked: weekdays (0 Sunday … 6 Saturday, default Monday to Friday) and holidays (`YYYY-MM-DD`) */
|
|
47
|
+
export interface GanttCalendar {
|
|
48
|
+
workingDays?: number[]
|
|
49
|
+
holidays?: string[]
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export interface GanttScheduleOptions {
|
|
53
|
+
/** `'push'` (default) moves tasks only as late as their dependencies need; `'asap'` also pulls them back to the earliest they can start */
|
|
54
|
+
mode?: 'push' | 'asap'
|
|
55
|
+
/** Count durations and lags in working days (date-only tasks), starting on working days */
|
|
56
|
+
calendar?: GanttCalendar
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export interface GanttCriticalPath {
|
|
60
|
+
/** Tasks with no slack (and summaries holding one) */
|
|
61
|
+
tasks: string[]
|
|
62
|
+
/** Dependencies on the path, as `'<predecessor>><successor>'` */
|
|
63
|
+
dependencies: string[]
|
|
64
|
+
/** Each task's total slack in days: how late it can finish without delaying the end */
|
|
65
|
+
slack: Record<string, number>
|
|
66
|
+
/** When the last task ends */
|
|
67
|
+
finish: string
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export function normalizeDependency(d: string | GanttDependency): Required<GanttDependency> {
|
|
71
|
+
return typeof d === 'string' ? { id: d, type: 'FS', lag: 0 } : { id: d.id, type: d.type ?? 'FS', lag: d.lag ?? 0 }
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/** Ids of tasks that have children */
|
|
75
|
+
export function summaryIds(tasks: readonly GanttTask[]): Set<string> {
|
|
76
|
+
const ids = new Set(tasks.map((t) => t.id))
|
|
77
|
+
const out = new Set<string>()
|
|
78
|
+
for (const t of tasks) if (t.parentId && ids.has(t.parentId)) out.add(t.parentId)
|
|
79
|
+
for (const t of tasks) if (t.type === 'summary') out.add(t.id)
|
|
80
|
+
return out
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
export function isMilestone(t: GanttTask): boolean {
|
|
84
|
+
return t.type === 'milestone' || (!t.end && t.type !== 'summary')
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/** A task's span in ms, end exclusive: a date-only end runs to the next midnight; a milestone has none */
|
|
88
|
+
export function taskSpan(t: Pick<GanttTask, 'start' | 'end' | 'type'>): { start: number; end: number; dateOnly: boolean } {
|
|
89
|
+
const start = parseDate(t.start)
|
|
90
|
+
const dateOnly = isDateOnly(t.start)
|
|
91
|
+
if (t.type === 'milestone' || !t.end) return { start, end: start, dateOnly }
|
|
92
|
+
const e = parseDate(t.end)
|
|
93
|
+
const end = isDateOnly(t.end) ? addDays(startOfDay(e), 1) : e
|
|
94
|
+
return { start, end: Math.max(start, end), dateOnly }
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/** The task's `start`/`end` strings for a span (end exclusive), in the format it came in */
|
|
98
|
+
export function spanDates(t: Pick<GanttTask, 'start' | 'end' | 'type'>, start: number, end: number): { start: string; end?: string } {
|
|
99
|
+
const dateOnly = isDateOnly(t.start)
|
|
100
|
+
if (t.type === 'milestone' || !t.end) return { start: formatDate(dateOnly ? startOfDay(start) : start, dateOnly) }
|
|
101
|
+
if (dateOnly) {
|
|
102
|
+
const s = startOfDay(start)
|
|
103
|
+
const last = Math.max(s, startOfDay(end - 1))
|
|
104
|
+
return { start: formatDate(s, true), end: formatDate(last, true) }
|
|
105
|
+
}
|
|
106
|
+
return { start: formatDate(start, false), end: formatDate(Math.max(start, end), false) }
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/** Duration in whole days (date-only tasks) or fractions of a day */
|
|
110
|
+
export function taskDays(t: GanttTask): number {
|
|
111
|
+
const s = taskSpan(t)
|
|
112
|
+
return s.dateOnly ? daysBetween(s.start, s.end) : (s.end - s.start) / DAY
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* Summaries take the span of their children (deepest first) and their progress, weighted by duration. Returns the
|
|
117
|
+
* same array when nothing changes.
|
|
118
|
+
*/
|
|
119
|
+
export function rollupSummaries<T extends GanttTask>(tasks: readonly T[]): T[] {
|
|
120
|
+
const sums = summaryIds(tasks)
|
|
121
|
+
if (!sums.size) return tasks as T[]
|
|
122
|
+
const kids = new Map<string, T[]>()
|
|
123
|
+
for (const t of tasks) if (t.parentId && sums.has(t.parentId)) (kids.get(t.parentId) ?? kids.set(t.parentId, []).get(t.parentId)!).push(t)
|
|
124
|
+
const out = new Map<string, T>()
|
|
125
|
+
const visiting = new Set<string>()
|
|
126
|
+
const resolve = (t: T): T => {
|
|
127
|
+
if (!sums.has(t.id) || !kids.has(t.id)) return out.get(t.id) ?? t
|
|
128
|
+
if (out.has(t.id)) return out.get(t.id)!
|
|
129
|
+
if (visiting.has(t.id)) return t
|
|
130
|
+
visiting.add(t.id)
|
|
131
|
+
let start = Infinity
|
|
132
|
+
let end = -Infinity
|
|
133
|
+
let dateOnly = true
|
|
134
|
+
let work = 0
|
|
135
|
+
let done = 0
|
|
136
|
+
for (const k of kids.get(t.id)!) {
|
|
137
|
+
const r = resolve(k)
|
|
138
|
+
const s = taskSpan(r)
|
|
139
|
+
if (!Number.isFinite(s.start)) continue
|
|
140
|
+
start = Math.min(start, s.start)
|
|
141
|
+
end = Math.max(end, s.end)
|
|
142
|
+
if (!s.dateOnly) dateOnly = false
|
|
143
|
+
const w = Math.max(s.end - s.start, isMilestone(r) ? 0 : 1)
|
|
144
|
+
work += w
|
|
145
|
+
done += w * (r.progress ?? 0)
|
|
146
|
+
}
|
|
147
|
+
visiting.delete(t.id)
|
|
148
|
+
if (!Number.isFinite(start)) return t
|
|
149
|
+
const dates = dateOnly
|
|
150
|
+
? { start: formatDate(start, true), end: formatDate(Math.max(start, startOfDay(end - 1)), true) }
|
|
151
|
+
: { start: formatDate(start, false), end: formatDate(end, false) }
|
|
152
|
+
const progress = work ? Math.round(done / work) : (t.progress ?? 0)
|
|
153
|
+
const next = dates.start === t.start && dates.end === t.end && progress === (t.progress ?? 0) ? t : { ...t, start: dates.start, end: dates.end, progress }
|
|
154
|
+
out.set(t.id, next)
|
|
155
|
+
return next
|
|
156
|
+
}
|
|
157
|
+
let changed = false
|
|
158
|
+
const result = tasks.map((t) => {
|
|
159
|
+
const r = resolve(t)
|
|
160
|
+
if (r !== t) changed = true
|
|
161
|
+
return r
|
|
162
|
+
})
|
|
163
|
+
return changed ? result : (tasks as T[])
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
// ── Working days ──────────────────────────────────────────────────────────────────────────────────────────
|
|
167
|
+
|
|
168
|
+
function calendarOf(c?: GanttCalendar) {
|
|
169
|
+
return { days: c?.workingDays ?? [1, 2, 3, 4, 5], holidays: new Set(c?.holidays ?? []) }
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
/** Working days from `start` to `end`, both included (`YYYY-MM-DD`) */
|
|
173
|
+
export function workingDays(start: string, end: string, calendar?: GanttCalendar): number {
|
|
174
|
+
const c = calendarOf(calendar)
|
|
175
|
+
let n = 0
|
|
176
|
+
const last = startOfDay(parseDate(end))
|
|
177
|
+
for (let d = startOfDay(parseDate(start)); d <= last; d = addDays(d, 1)) if (isWorkingDay(d, c.days, c.holidays)) n++
|
|
178
|
+
return n
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
/** The date `n` working days after `date` (before it when negative); 0 moves a day off to the next working day */
|
|
182
|
+
export function addWorkingDays(date: string, n: number, calendar?: GanttCalendar): string {
|
|
183
|
+
const c = calendarOf(calendar)
|
|
184
|
+
if (!c.days.length) return date
|
|
185
|
+
let d = startOfDay(parseDate(date))
|
|
186
|
+
while (!isWorkingDay(d, c.days, c.holidays)) d = addDays(d, 1)
|
|
187
|
+
const step = n < 0 ? -1 : 1
|
|
188
|
+
for (let left = Math.abs(n); left > 0; ) {
|
|
189
|
+
d = addDays(d, step)
|
|
190
|
+
if (isWorkingDay(d, c.days, c.holidays)) left--
|
|
191
|
+
}
|
|
192
|
+
return formatDate(d, true)
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
// ── Scheduling ────────────────────────────────────────────────────────────────────────────────────────────
|
|
196
|
+
|
|
197
|
+
interface Link { pred: string; succ: string; type: 'FS' | 'SS' | 'FF' | 'SF'; lag: number; key: string }
|
|
198
|
+
|
|
199
|
+
// Dependencies between plain tasks: one onto a summary applies to each of its tasks (as MS Project does), one
|
|
200
|
+
// from a summary is resolved against its span once its tasks are placed
|
|
201
|
+
function expandLinks(tasks: readonly GanttTask[]) {
|
|
202
|
+
const byId = new Map(tasks.map((t) => [t.id, t]))
|
|
203
|
+
const sums = summaryIds(tasks)
|
|
204
|
+
const kids = new Map<string, string[]>()
|
|
205
|
+
for (const t of tasks) if (t.parentId && byId.has(t.parentId)) (kids.get(t.parentId) ?? kids.set(t.parentId, []).get(t.parentId)!).push(t.id)
|
|
206
|
+
const leaves = (id: string, depth = 0): string[] => (sums.has(id) && kids.has(id) && depth < 100 ? kids.get(id)!.flatMap((k) => leaves(k, depth + 1)) : [id])
|
|
207
|
+
const links: Link[] = []
|
|
208
|
+
for (const t of tasks) {
|
|
209
|
+
for (const raw of t.dependencies ?? []) {
|
|
210
|
+
const d = normalizeDependency(raw)
|
|
211
|
+
if (!byId.has(d.id) || d.id === t.id) continue
|
|
212
|
+
for (const succ of leaves(t.id)) links.push({ pred: d.id, succ, type: d.type, lag: d.lag, key: `${d.id}>${t.id}` })
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
return { byId, sums, kids, leaves, links }
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
// Order: a task after everything it waits for; a summary used as a predecessor after its tasks. Cycles are cut
|
|
219
|
+
function order(ids: string[], deps: Map<string, string[]>): string[] {
|
|
220
|
+
const out: string[] = []
|
|
221
|
+
const state = new Map<string, 1 | 2>()
|
|
222
|
+
const visit = (id: string) => {
|
|
223
|
+
if (state.get(id)) return
|
|
224
|
+
state.set(id, 1)
|
|
225
|
+
for (const p of deps.get(id) ?? []) if (state.get(p) !== 1) visit(p)
|
|
226
|
+
state.set(id, 2)
|
|
227
|
+
out.push(id)
|
|
228
|
+
}
|
|
229
|
+
for (const id of ids) visit(id)
|
|
230
|
+
return out
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
/**
|
|
234
|
+
* Moves tasks so every dependency holds: by default only later (`'push'`, what dragging a predecessor does), or as
|
|
235
|
+
* soon as possible (`'asap'`), keeping each task's duration. Summaries follow their tasks. Returns the same array
|
|
236
|
+
* when nothing moves.
|
|
237
|
+
*/
|
|
238
|
+
export function scheduleTasks<T extends GanttTask>(tasks: readonly T[], options: GanttScheduleOptions = {}): T[] {
|
|
239
|
+
const { sums, kids, leaves, links } = expandLinks(tasks)
|
|
240
|
+
const cal = options.calendar ? calendarOf(options.calendar) : null
|
|
241
|
+
const spans = new Map<string, { start: number; end: number; dateOnly: boolean }>()
|
|
242
|
+
for (const t of tasks) if (!sums.has(t.id)) spans.set(t.id, taskSpan(t))
|
|
243
|
+
const deps = new Map<string, string[]>()
|
|
244
|
+
for (const l of links) (deps.get(l.succ) ?? deps.set(l.succ, []).get(l.succ)!).push(l.pred)
|
|
245
|
+
for (const s of sums) deps.set(s, [...(deps.get(s) ?? []), ...leaves(s)])
|
|
246
|
+
const bySucc = new Map<string, Link[]>()
|
|
247
|
+
for (const l of links) (bySucc.get(l.succ) ?? bySucc.set(l.succ, []).get(l.succ)!).push(l)
|
|
248
|
+
|
|
249
|
+
const span = (id: string) => {
|
|
250
|
+
if (!sums.has(id)) return spans.get(id)
|
|
251
|
+
let start = Infinity
|
|
252
|
+
let end = -Infinity
|
|
253
|
+
for (const l of leaves(id)) {
|
|
254
|
+
const s = spans.get(l)
|
|
255
|
+
if (!s) continue
|
|
256
|
+
start = Math.min(start, s.start)
|
|
257
|
+
end = Math.max(end, s.end)
|
|
258
|
+
}
|
|
259
|
+
return Number.isFinite(start) ? { start, end, dateOnly: true } : undefined
|
|
260
|
+
}
|
|
261
|
+
// Shift by days, on working days with a calendar
|
|
262
|
+
const shift = (ms: number, days: number, dateOnly: boolean) => {
|
|
263
|
+
if (!cal || !dateOnly) return ms + days * DAY
|
|
264
|
+
return parseDate(addWorkingDays(formatDate(ms, true), days, options.calendar))
|
|
265
|
+
}
|
|
266
|
+
const workLength = (s: { start: number; end: number }) => {
|
|
267
|
+
let n = 0
|
|
268
|
+
for (let d = s.start; d < s.end; d = addDays(d, 1)) if (isWorkingDay(d, cal!.days, cal!.holidays)) n++
|
|
269
|
+
return n
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
let moved = false
|
|
273
|
+
for (const id of order([...spans.keys(), ...sums], deps)) {
|
|
274
|
+
if (sums.has(id)) continue
|
|
275
|
+
const own = spans.get(id)!
|
|
276
|
+
const incoming = bySucc.get(id)
|
|
277
|
+
if (!incoming?.length || !Number.isFinite(own.start)) continue
|
|
278
|
+
const dur = own.end - own.start
|
|
279
|
+
let earliest = -Infinity
|
|
280
|
+
for (const l of incoming) {
|
|
281
|
+
const p = span(l.pred)
|
|
282
|
+
if (!p) continue
|
|
283
|
+
const pd = p.dateOnly && own.dateOnly
|
|
284
|
+
let need: number
|
|
285
|
+
if (l.type === 'FS') need = shift(p.end, l.lag, pd)
|
|
286
|
+
else if (l.type === 'SS') need = shift(p.start, l.lag, pd)
|
|
287
|
+
else if (l.type === 'FF') need = shift(p.end, l.lag, pd) - dur
|
|
288
|
+
else need = shift(p.start, l.lag, pd) - dur
|
|
289
|
+
earliest = Math.max(earliest, need)
|
|
290
|
+
}
|
|
291
|
+
if (!Number.isFinite(earliest)) continue
|
|
292
|
+
let start = options.mode === 'asap' ? earliest : Math.max(own.start, earliest)
|
|
293
|
+
if (own.dateOnly) start = startOfDay(start + 12 * 3_600_000)
|
|
294
|
+
let end = start + dur
|
|
295
|
+
if (cal && own.dateOnly) {
|
|
296
|
+
// Starts on a working day and lasts as many working days as before
|
|
297
|
+
const days = workLength(own)
|
|
298
|
+
start = parseDate(addWorkingDays(formatDate(start, true), 0, options.calendar))
|
|
299
|
+
end = days ? addDays(parseDate(addWorkingDays(formatDate(start, true), Math.max(0, days - 1), options.calendar)), 1) : start
|
|
300
|
+
} else if (own.dateOnly) end = addDays(start, daysBetween(own.start, own.end))
|
|
301
|
+
if (start !== own.start || end !== own.end) {
|
|
302
|
+
spans.set(id, { start, end, dateOnly: own.dateOnly })
|
|
303
|
+
moved = true
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
if (!moved) return rollupSummaries(tasks)
|
|
307
|
+
const next = tasks.map((t) => {
|
|
308
|
+
if (sums.has(t.id) && kids.has(t.id)) return t
|
|
309
|
+
const s = spans.get(t.id)
|
|
310
|
+
const before = taskSpan(t)
|
|
311
|
+
if (!s || (s.start === before.start && s.end === before.end)) return t
|
|
312
|
+
return { ...t, ...spanDates(t, s.start, s.end) }
|
|
313
|
+
})
|
|
314
|
+
return rollupSummaries(next)
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
/**
|
|
318
|
+
* The critical path over the tasks' current dates: tasks whose delay would delay the last one's end (no slack),
|
|
319
|
+
* through their dependencies. Slack is in calendar days, or working days with a calendar (so a weekend between
|
|
320
|
+
* two tasks isn't slack).
|
|
321
|
+
*/
|
|
322
|
+
export function criticalPath(tasks: readonly GanttTask[], options: { calendar?: GanttCalendar } = {}): GanttCriticalPath {
|
|
323
|
+
const { sums, kids, leaves, links } = expandLinks(tasks)
|
|
324
|
+
const real = new Map<string, { start: number; end: number }>()
|
|
325
|
+
for (const t of tasks) if (!sums.has(t.id) || !kids.has(t.id)) real.set(t.id, taskSpan(t))
|
|
326
|
+
const ids = [...real.keys()].filter((id) => Number.isFinite(real.get(id)!.start))
|
|
327
|
+
if (!ids.length) return { tasks: [], dependencies: [], slack: {}, finish: '' }
|
|
328
|
+
|
|
329
|
+
// Everything below runs in days: calendar days, or with a calendar working days (a day off has no length), so
|
|
330
|
+
// the weekend between two tasks is neither slack nor duration
|
|
331
|
+
const cal = options.calendar ? calendarOf(options.calendar) : null
|
|
332
|
+
let toDays = (ms: number) => ms / DAY
|
|
333
|
+
if (cal) {
|
|
334
|
+
const first = startOfDay(Math.min(...ids.map((id) => real.get(id)!.start)))
|
|
335
|
+
const index = new Map<number, number>()
|
|
336
|
+
toDays = (ms: number) => {
|
|
337
|
+
const day = startOfDay(ms)
|
|
338
|
+
let n = index.get(day)
|
|
339
|
+
if (n === undefined) {
|
|
340
|
+
n = 0
|
|
341
|
+
const step = day >= first ? 1 : -1
|
|
342
|
+
for (let d = first; d !== day; d = addDays(d, step)) if (isWorkingDay(step > 0 ? d : addDays(d, -1), cal.days, cal.holidays)) n += step
|
|
343
|
+
index.set(day, n)
|
|
344
|
+
}
|
|
345
|
+
return n + (isWorkingDay(day, cal.days, cal.holidays) ? (ms - day) / DAY : 0)
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
const spans = new Map(ids.map((id) => [id, { start: toDays(real.get(id)!.start), end: toDays(real.get(id)!.end) }]))
|
|
349
|
+
// Links from a summary come from each of its tasks
|
|
350
|
+
const flat: Link[] = links.flatMap((l) => (sums.has(l.pred) && kids.has(l.pred) ? leaves(l.pred).map((p) => ({ ...l, pred: p })) : [l]))
|
|
351
|
+
.filter((l) => spans.has(l.pred) && spans.has(l.succ))
|
|
352
|
+
const finish = Math.max(...ids.map((id) => spans.get(id)!.end))
|
|
353
|
+
const out = new Map<string, Link[]>()
|
|
354
|
+
const deps = new Map<string, string[]>()
|
|
355
|
+
for (const l of flat) {
|
|
356
|
+
;(out.get(l.pred) ?? out.set(l.pred, []).get(l.pred)!).push(l)
|
|
357
|
+
;(deps.get(l.succ) ?? deps.set(l.succ, []).get(l.succ)!).push(l.pred)
|
|
358
|
+
}
|
|
359
|
+
const late = new Map<string, number>()
|
|
360
|
+
// Backward pass: successors first
|
|
361
|
+
for (const id of order(ids, deps).reverse()) {
|
|
362
|
+
const s = spans.get(id)!
|
|
363
|
+
const dur = s.end - s.start
|
|
364
|
+
let lf = finish
|
|
365
|
+
for (const l of out.get(id) ?? []) {
|
|
366
|
+
const ls = late.get(l.succ)
|
|
367
|
+
if (ls === undefined) continue
|
|
368
|
+
const succ = spans.get(l.succ)!
|
|
369
|
+
const lfSucc = ls + (succ.end - succ.start)
|
|
370
|
+
if (l.type === 'FS') lf = Math.min(lf, ls - l.lag)
|
|
371
|
+
else if (l.type === 'SS') lf = Math.min(lf, ls - l.lag + dur)
|
|
372
|
+
else if (l.type === 'FF') lf = Math.min(lf, lfSucc - l.lag)
|
|
373
|
+
else lf = Math.min(lf, lfSucc - l.lag + dur)
|
|
374
|
+
}
|
|
375
|
+
late.set(id, lf - dur)
|
|
376
|
+
}
|
|
377
|
+
const slack: Record<string, number> = {}
|
|
378
|
+
const critical = new Set<string>()
|
|
379
|
+
for (const id of ids) {
|
|
380
|
+
const days = late.get(id)! - spans.get(id)!.start
|
|
381
|
+
slack[id] = Math.round(days * 1000) / 1000
|
|
382
|
+
if (days < 1e-6) critical.add(id)
|
|
383
|
+
}
|
|
384
|
+
// A dependency is on the path when both ends are and it's what holds the successor back
|
|
385
|
+
const tight = new Set<string>()
|
|
386
|
+
for (const l of flat) {
|
|
387
|
+
if (!critical.has(l.pred) || !critical.has(l.succ)) continue
|
|
388
|
+
const p = spans.get(l.pred)!
|
|
389
|
+
const s = spans.get(l.succ)!
|
|
390
|
+
const from = (l.type === 'FS' || l.type === 'FF' ? p.end : p.start) + l.lag
|
|
391
|
+
const to = l.type === 'FS' || l.type === 'SS' ? s.start : s.end
|
|
392
|
+
if (Math.abs(to - from) < 1e-6) tight.add(l.key)
|
|
393
|
+
}
|
|
394
|
+
for (const s of sums) if (kids.has(s) && leaves(s).some((l) => critical.has(l))) critical.add(s)
|
|
395
|
+
const end = Math.max(...ids.map((id) => real.get(id)!.end))
|
|
396
|
+
const last = tasks.find((t) => real.get(t.id)?.end === end)
|
|
397
|
+
return {
|
|
398
|
+
tasks: tasks.filter((t) => critical.has(t.id)).map((t) => t.id),
|
|
399
|
+
dependencies: [...tight],
|
|
400
|
+
slack,
|
|
401
|
+
finish: formatDate(isDateOnly(last?.start) ? addDays(end, -1) : end, isDateOnly(last?.start)),
|
|
402
|
+
}
|
|
403
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { inject, type ComputedRef, type InjectionKey, type Ref } from 'vue'
|
|
2
|
+
import type { DrawItem, DrawLayer, DrawPen, DrawShapeKind } from './drawGeometry'
|
|
3
|
+
|
|
4
|
+
/** What a pointer does on an MDrawCanvas */
|
|
5
|
+
export type DrawTool = DrawPen | 'eraser' | 'stroke-eraser' | DrawShapeKind | 'text' | 'select' | 'pan'
|
|
6
|
+
|
|
7
|
+
export interface DrawExportOptions {
|
|
8
|
+
/** In `mode="pages"`: the page to export (default 0) */
|
|
9
|
+
page?: number
|
|
10
|
+
/** PNG: pixels per drawing unit (default 2) */
|
|
11
|
+
scale?: number
|
|
12
|
+
/** Paint the paper color behind the drawing (default true) */
|
|
13
|
+
background?: boolean
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/** What an MDrawCanvas shares with MDrawToolbar, MDrawLayers and anything built with useDrawing() inside it */
|
|
17
|
+
export interface DrawContext {
|
|
18
|
+
tool: Ref<DrawTool>
|
|
19
|
+
color: Ref<string>
|
|
20
|
+
size: Ref<number>
|
|
21
|
+
/** New rects and ellipses are filled with the color */
|
|
22
|
+
fill: Ref<boolean>
|
|
23
|
+
items: ComputedRef<DrawItem[]>
|
|
24
|
+
selection: Ref<string[]>
|
|
25
|
+
layers: ComputedRef<DrawLayer[]>
|
|
26
|
+
setLayers(layers: DrawLayer[]): void
|
|
27
|
+
/** The layer new items go on */
|
|
28
|
+
layer: Ref<string | undefined>
|
|
29
|
+
mode: ComputedRef<'infinite' | 'pages'>
|
|
30
|
+
pages: Ref<number>
|
|
31
|
+
addPage(): void
|
|
32
|
+
zoom: ComputedRef<number>
|
|
33
|
+
zoomIn(): void
|
|
34
|
+
zoomOut(): void
|
|
35
|
+
fitView(): void
|
|
36
|
+
canUndo: ComputedRef<boolean>
|
|
37
|
+
canRedo: ComputedRef<boolean>
|
|
38
|
+
undo(): void
|
|
39
|
+
redo(): void
|
|
40
|
+
clear(): void
|
|
41
|
+
deleteSelection(): void
|
|
42
|
+
exportSvg(opts?: DrawExportOptions): string
|
|
43
|
+
exportPng(opts?: DrawExportOptions): Promise<Blob>
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export const DRAW_KEY: InjectionKey<DrawContext> = Symbol('m3-draw')
|
|
47
|
+
|
|
48
|
+
/** The surrounding MDrawCanvas' state and actions, for a toolbar or panel of your own inside it */
|
|
49
|
+
export function useDrawing(): DrawContext {
|
|
50
|
+
const ctx = inject(DRAW_KEY, null)
|
|
51
|
+
if (!ctx) throw new Error('useDrawing() must be called inside <MDrawCanvas>')
|
|
52
|
+
return ctx
|
|
53
|
+
}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { inject, type ComputedRef, type InjectionKey, type Ref } from 'vue'
|
|
2
|
+
import type { M3Locale } from './useLocale'
|
|
3
|
+
import type { FloorArea, FloorDecor, FloorDecorKind, FloorMerge, FloorPick, FloorStatus, FloorTable, FloorWall } from '../components/MFloorPlan.vue'
|
|
4
|
+
|
|
5
|
+
export type FloorTool = 'select' | 'wall' | 'area'
|
|
6
|
+
export type FloorItemKind = 'table' | 'area' | 'wall' | 'decor'
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* An MFloorPlan's state and actions. MFloorPlanToolbar and MFloorPlanInspector are built on it, and so can controls
|
|
10
|
+
* of your own: inside the plan's slots with `useFloorPlan()`, or anywhere from its template ref (`plan.context`).
|
|
11
|
+
* Every edit made through it is a step of the plan's undo history.
|
|
12
|
+
*/
|
|
13
|
+
export interface FloorPlanContext {
|
|
14
|
+
tables: Ref<FloorTable[]>
|
|
15
|
+
areas: Ref<FloorArea[]>
|
|
16
|
+
walls: Ref<FloorWall[]>
|
|
17
|
+
decor: Ref<FloorDecor[]>
|
|
18
|
+
merges: Ref<FloorMerge[]>
|
|
19
|
+
selection: Ref<(string | number)[]>
|
|
20
|
+
picked: Ref<FloorPick>
|
|
21
|
+
tool: Ref<FloorTool>
|
|
22
|
+
editable: ComputedRef<boolean>
|
|
23
|
+
/** A wall is being drawn (tool `wall`): finish it (also double-click / Enter) or cancel it (Escape) */
|
|
24
|
+
drawingWall: ComputedRef<boolean>
|
|
25
|
+
finishWall(): void
|
|
26
|
+
cancelWall(): void
|
|
27
|
+
/** The decor kinds: built-in ones merged with `decorKinds` */
|
|
28
|
+
kinds: ComputedRef<Record<string, FloorDecorKind>>
|
|
29
|
+
statuses: ComputedRef<Record<string, FloorStatus>>
|
|
30
|
+
/** The plan's size in plan units */
|
|
31
|
+
size: ComputedRef<{ width: number; height: number }>
|
|
32
|
+
canUndo: ComputedRef<boolean>
|
|
33
|
+
canRedo: ComputedRef<boolean>
|
|
34
|
+
undo(): void
|
|
35
|
+
redo(): void
|
|
36
|
+
/** Adds a table (at the plan's middle unless placed; numbered after the highest numbered one) and selects it */
|
|
37
|
+
addTable(table?: Partial<FloorTable>): FloorTable
|
|
38
|
+
/** Adds a decor item of a kind and picks it */
|
|
39
|
+
addDecor(kind: string, item?: Partial<FloorDecor>): FloorDecor
|
|
40
|
+
/** Changes one item (consecutive changes to the same item within a moment are one undo step) */
|
|
41
|
+
update(kind: 'table', id: string | number, patch: Partial<FloorTable>): void
|
|
42
|
+
update(kind: 'area', id: string | number, patch: Partial<FloorArea>): void
|
|
43
|
+
update(kind: 'wall', id: string | number, patch: Partial<FloorWall>): void
|
|
44
|
+
update(kind: 'decor', id: string | number, patch: Partial<FloorDecor>): void
|
|
45
|
+
/** Removes what's picked (a wall's picked corner, or the whole item), or else the selected tables */
|
|
46
|
+
removeSelected(): void
|
|
47
|
+
removeTables(ids: (string | number)[]): void
|
|
48
|
+
/** Copies the selected tables, or the picked zone or decor */
|
|
49
|
+
duplicate(): void
|
|
50
|
+
merge(ids?: (string | number)[], label?: string): FloorMerge | null
|
|
51
|
+
split(idOrTable: string | number): void
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export const FLOOR_PLAN_KEY: InjectionKey<FloorPlanContext> = Symbol('m3-floor-plan')
|
|
55
|
+
|
|
56
|
+
/** The enclosing MFloorPlan's state and actions (inside its slots) */
|
|
57
|
+
export function useFloorPlan(): FloorPlanContext {
|
|
58
|
+
const ctx = inject(FLOOR_PLAN_KEY, null)
|
|
59
|
+
if (!ctx) throw new Error('useFloorPlan() must be called inside <MFloorPlan> (or pass the plan to your component)')
|
|
60
|
+
return ctx
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
const BUILTIN_NAMES: Record<string, keyof M3Locale> = {
|
|
64
|
+
door: 'floorDecorDoor', window: 'floorDecorWindow', plant: 'floorDecorPlant', column: 'floorDecorColumn', restroom: 'floorDecorRestroom',
|
|
65
|
+
kitchen: 'floorDecorKitchen', register: 'floorDecorRegister', stairs: 'floorDecorStairs', label: 'floorDecorLabel',
|
|
66
|
+
}
|
|
67
|
+
const BUILTIN_LABELS = new Set(['Door', 'Window', 'Plant', 'Column', 'Restroom', 'Kitchen', 'Register', 'Stairs', 'Label'])
|
|
68
|
+
/** A decor kind's name: a built-in one in the app's language (unless renamed), else its label or key */
|
|
69
|
+
export function floorDecorName(kind: string, kinds: Record<string, FloorDecorKind>, locale: M3Locale): string {
|
|
70
|
+
const k = kinds[kind]
|
|
71
|
+
if (BUILTIN_NAMES[kind] && (!k?.label || BUILTIN_LABELS.has(k.label))) return locale[BUILTIN_NAMES[kind]!] as string
|
|
72
|
+
return k?.label ?? kind
|
|
73
|
+
}
|