@antelopejs/dms-automation 0.6.0 → 0.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +21 -7
- package/dist/cluster/bus.js +8 -6
- package/dist/cluster/bus.js.map +1 -1
- package/dist/cluster/leader.js.map +1 -1
- package/dist/data/procedures-query.d.ts +19 -0
- package/dist/data/procedures-query.js +105 -0
- package/dist/data/procedures-query.js.map +1 -0
- package/dist/data/procedures-table.d.ts +5 -16
- package/dist/data/procedures-table.js +12 -101
- package/dist/data/procedures-table.js.map +1 -1
- package/dist/data/runs-table.js +0 -5
- package/dist/data/runs-table.js.map +1 -1
- package/dist/db/models/automation_template.model.d.ts +2 -4
- package/dist/db/models/automation_template.model.js +13 -14
- package/dist/db/models/automation_template.model.js.map +1 -1
- package/dist/db/models/procedure_run.model.js.map +1 -1
- package/dist/db/models/stats.model.js.map +1 -1
- package/dist/db/tables/procedure.table.d.ts +0 -1
- package/dist/db/tables/procedure.table.js +0 -4
- package/dist/db/tables/procedure.table.js.map +1 -1
- package/dist/db/tables/procedure_run.table.d.ts +2 -1
- package/dist/db/tables/procedure_run.table.js.map +1 -1
- package/dist/implementations/dms-automation/index.js.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/pages/category.js.map +1 -1
- package/dist/pages/index.js.map +1 -1
- package/dist/pages/overview.js.map +1 -1
- package/dist/pages/procedures.js.map +1 -1
- package/dist/pages/runs.js.map +1 -1
- package/dist/pages/shared.js +1 -1
- package/dist/pages/shared.js.map +1 -1
- package/dist/realtime.d.ts +2 -1
- package/dist/realtime.js.map +1 -1
- package/dist/routes/action-types.d.ts +2 -1
- package/dist/routes/action-types.js.map +1 -1
- package/dist/routes/deleteConfirm.js +4 -3
- package/dist/routes/deleteConfirm.js.map +1 -1
- package/dist/routes/graphSchema.d.ts +2 -1
- package/dist/routes/graphSchema.js +8 -7
- package/dist/routes/graphSchema.js.map +1 -1
- package/dist/routes/procedureChecks.js +5 -5
- package/dist/routes/procedureChecks.js.map +1 -1
- package/dist/routes/procedureRuns.d.ts +2 -2
- package/dist/routes/procedureRuns.js +1 -1
- package/dist/routes/procedureRuns.js.map +1 -1
- package/dist/routes/procedures.d.ts +14 -15
- package/dist/routes/procedures.js +2 -1
- package/dist/routes/procedures.js.map +1 -1
- package/dist/routes/requests.d.ts +11 -5
- package/dist/routes/requests.js.map +1 -1
- package/dist/routes/runs.d.ts +7 -7
- package/dist/routes/runs.js +5 -3
- package/dist/routes/runs.js.map +1 -1
- package/dist/routes/stats.js.map +1 -1
- package/dist/routes/templates.d.ts +3 -2
- package/dist/routes/templates.js +2 -1
- package/dist/routes/templates.js.map +1 -1
- package/dist/routes/trigger-types.d.ts +2 -1
- package/dist/routes/trigger-types.js.map +1 -1
- package/dist/routes/typeConfigShared.d.ts +2 -1
- package/dist/routes/typeConfigShared.js.map +1 -1
- package/dist/runtime/armErrors.d.ts +0 -1
- package/dist/runtime/armErrors.js +0 -7
- package/dist/runtime/armErrors.js.map +1 -1
- package/dist/runtime/boundRunLog.d.ts +1 -0
- package/dist/runtime/boundRunLog.js +11 -11
- package/dist/runtime/boundRunLog.js.map +1 -1
- package/dist/runtime/builtins/actions/http.js +16 -9
- package/dist/runtime/builtins/actions/http.js.map +1 -1
- package/dist/runtime/builtins/actions/log.js.map +1 -1
- package/dist/runtime/builtins/data/boolean.js +4 -5
- package/dist/runtime/builtins/data/boolean.js.map +1 -1
- package/dist/runtime/builtins/data/compare.js +8 -10
- package/dist/runtime/builtins/data/compare.js.map +1 -1
- package/dist/runtime/builtins/data/constant.js +1 -1
- package/dist/runtime/builtins/data/constant.js.map +1 -1
- package/dist/runtime/builtins/data/json.js +4 -5
- package/dist/runtime/builtins/data/json.js.map +1 -1
- package/dist/runtime/builtins/data/math.js +4 -4
- package/dist/runtime/builtins/data/math.js.map +1 -1
- package/dist/runtime/builtins/data/object.js +12 -17
- package/dist/runtime/builtins/data/object.js.map +1 -1
- package/dist/runtime/builtins/data/string.js +13 -18
- package/dist/runtime/builtins/data/string.js.map +1 -1
- package/dist/runtime/builtins/nodes/action.js +5 -2
- package/dist/runtime/builtins/nodes/action.js.map +1 -1
- package/dist/runtime/builtins/nodes/data.js +2 -2
- package/dist/runtime/builtins/nodes/data.js.map +1 -1
- package/dist/runtime/builtins/nodes/delay.js +2 -2
- package/dist/runtime/builtins/nodes/delay.js.map +1 -1
- package/dist/runtime/builtins/nodes/forRange.js +2 -2
- package/dist/runtime/builtins/nodes/forRange.js.map +1 -1
- package/dist/runtime/builtins/nodes/foreach.js +2 -2
- package/dist/runtime/builtins/nodes/foreach.js.map +1 -1
- package/dist/runtime/builtins/nodes/groupInput.js +2 -2
- package/dist/runtime/builtins/nodes/groupInput.js.map +1 -1
- package/dist/runtime/builtins/nodes/groupOutput.js +2 -2
- package/dist/runtime/builtins/nodes/groupOutput.js.map +1 -1
- package/dist/runtime/builtins/nodes/if.js +2 -2
- package/dist/runtime/builtins/nodes/if.js.map +1 -1
- package/dist/runtime/builtins/nodes/parallel.js +2 -2
- package/dist/runtime/builtins/nodes/parallel.js.map +1 -1
- package/dist/runtime/builtins/nodes/retry.js +5 -6
- package/dist/runtime/builtins/nodes/retry.js.map +1 -1
- package/dist/runtime/builtins/nodes/setVariable.js +2 -2
- package/dist/runtime/builtins/nodes/setVariable.js.map +1 -1
- package/dist/runtime/builtins/nodes/switch.js +2 -2
- package/dist/runtime/builtins/nodes/switch.js.map +1 -1
- package/dist/runtime/builtins/nodes/trigger.js +2 -2
- package/dist/runtime/builtins/nodes/trigger.js.map +1 -1
- package/dist/runtime/builtins/nodes/tryCatch.js +2 -4
- package/dist/runtime/builtins/nodes/tryCatch.js.map +1 -1
- package/dist/runtime/builtins/triggers/cron.d.ts +2 -1
- package/dist/runtime/builtins/triggers/cron.js +5 -7
- package/dist/runtime/builtins/triggers/cron.js.map +1 -1
- package/dist/runtime/builtins/triggers/webhook.d.ts +6 -5
- package/dist/runtime/builtins/triggers/webhook.js +9 -6
- package/dist/runtime/builtins/triggers/webhook.js.map +1 -1
- package/dist/runtime/declaredProcedures.d.ts +2 -2
- package/dist/runtime/declaredProcedures.js +17 -92
- package/dist/runtime/declaredProcedures.js.map +1 -1
- package/dist/runtime/describe.js +11 -10
- package/dist/runtime/describe.js.map +1 -1
- package/dist/runtime/executionResult.d.ts +1 -1
- package/dist/runtime/executor.js +12 -38
- package/dist/runtime/executor.js.map +1 -1
- package/dist/runtime/flatten.d.ts +1 -1
- package/dist/runtime/flatten.js +1 -1
- package/dist/runtime/flatten.js.map +1 -1
- package/dist/runtime/graphIssues.js +24 -22
- package/dist/runtime/graphIssues.js.map +1 -1
- package/dist/runtime/graphVersion.d.ts +1 -1
- package/dist/runtime/graphVersion.js +2 -1
- package/dist/runtime/graphVersion.js.map +1 -1
- package/dist/runtime/nodeKinds.d.ts +3 -2
- package/dist/runtime/nodeKinds.js.map +1 -1
- package/dist/runtime/reconcile.d.ts +3 -0
- package/dist/runtime/reconcile.js +178 -0
- package/dist/runtime/reconcile.js.map +1 -0
- package/dist/runtime/registry.d.ts +0 -7
- package/dist/runtime/registry.js +3 -24
- package/dist/runtime/registry.js.map +1 -1
- package/dist/runtime/resolveInputs.d.ts +4 -2
- package/dist/runtime/resolveInputs.js +13 -12
- package/dist/runtime/resolveInputs.js.map +1 -1
- package/dist/runtime/resolveSubgraph.js +4 -5
- package/dist/runtime/resolveSubgraph.js.map +1 -1
- package/dist/runtime/retention.js.map +1 -1
- package/dist/runtime/runProcedure.d.ts +1 -1
- package/dist/runtime/runProcedure.js +2 -1
- package/dist/runtime/runProcedure.js.map +1 -1
- package/dist/runtime/schedule.js +3 -0
- package/dist/runtime/schedule.js.map +1 -1
- package/dist/runtime/schemaProperties.d.ts +11 -0
- package/dist/runtime/schemaProperties.js +7 -0
- package/dist/runtime/schemaProperties.js.map +1 -0
- package/dist/runtime/serialQueue.d.ts +1 -1
- package/dist/runtime/serialQueue.js +4 -4
- package/dist/runtime/serialQueue.js.map +1 -1
- package/dist/runtime/subscriptions.js +21 -183
- package/dist/runtime/subscriptions.js.map +1 -1
- package/dist/runtime/subwalk.js.map +1 -1
- package/dist/runtime/templateCacheState.d.ts +6 -0
- package/dist/runtime/templateCacheState.js +10 -0
- package/dist/runtime/templateCacheState.js.map +1 -0
- package/dist/runtime/templateUsages.js +4 -5
- package/dist/runtime/templateUsages.js.map +1 -1
- package/dist/runtime/topo.js +2 -4
- package/dist/runtime/topo.js.map +1 -1
- package/dist/runtime/trace.js +12 -9
- package/dist/runtime/trace.js.map +1 -1
- package/dist/runtime/triggerHandles.d.ts +3 -0
- package/dist/runtime/triggerHandles.js +8 -3
- package/dist/runtime/triggerHandles.js.map +1 -1
- package/dist/runtime/typeOrigin.js +12 -1
- package/dist/runtime/typeOrigin.js.map +1 -1
- package/dist/runtime/validate.js.map +1 -1
- package/dist/runtime/validateTemplate.js.map +1 -1
- package/dist/runtime/withTimeout.js.map +1 -1
- package/dist/runtime/wording.js +12 -8
- package/dist/runtime/wording.js.map +1 -1
- package/dist/stats/health-banner.js.map +1 -1
- package/dist/stats/health.js +2 -3
- package/dist/stats/health.js.map +1 -1
- package/dist/stats/kpi.js +1 -1
- package/dist/stats/kpi.js.map +1 -1
- package/dist/stats/overview.js +2 -1
- package/dist/stats/overview.js.map +1 -1
- package/dist/types/dataValue.d.ts +8 -0
- package/dist/types/dataValue.js +36 -0
- package/dist/types/dataValue.js.map +1 -0
- package/dist/types/graph.d.ts +8 -1
- package/dist/types/graph.js +8 -0
- package/dist/types/graph.js.map +1 -1
- package/dist/types/guards.d.ts +8 -0
- package/dist/types/guards.js +35 -0
- package/dist/types/guards.js.map +1 -0
- package/frontend-vue/app/build/components/editor/EditorBanners.vue +120 -0
- package/frontend-vue/app/build/components/editor/EditorChoiceModal.vue +44 -0
- package/frontend-vue/app/build/components/editor/EditorForkModal.vue +51 -0
- package/frontend-vue/app/build/components/editor/EditorHeader.vue +146 -0
- package/frontend-vue/app/build/components/editor/EditorSaveTemplateModal.vue +105 -0
- package/frontend-vue/app/build/components/editor/NodeInspectorDocs.vue +28 -0
- package/frontend-vue/app/build/components/editor/NodeInspectorRun.vue +48 -0
- package/frontend-vue/app/build/composables/editor/useBuilderMount.ts +129 -0
- package/frontend-vue/app/build/composables/editor/useBuilderSave.ts +256 -0
- package/frontend-vue/app/build/composables/editor/useBuilderShortcuts.ts +270 -0
- package/frontend-vue/app/build/composables/editor/useDraftProblems.ts +288 -0
- package/frontend-vue/app/build/composables/editor/useEditorContext.ts +388 -0
- package/frontend-vue/app/build/composables/editor/useEditorLoad.ts +158 -0
- package/frontend-vue/app/build/composables/editor/useForkToLocal.ts +193 -0
- package/frontend-vue/app/build/composables/editor/useGraphHistory.ts +113 -0
- package/frontend-vue/app/build/composables/editor/useGroupEditing.ts +445 -0
- package/frontend-vue/app/build/composables/editor/usePalette.ts +41 -0
- package/frontend-vue/app/build/composables/editor/useProcedureActions.ts +96 -0
- package/frontend-vue/app/build/composables/editor/useRunOverlay.ts +466 -0
- package/frontend-vue/app/build/composables/editor/useSaveAsTemplate.ts +172 -0
- package/frontend-vue/app/build/composables/editor/useSavedTriggers.ts +100 -0
- package/frontend-vue/app/build/composables/editor/useSubgraphNavigation.ts +270 -0
- package/frontend-vue/app/build/composables/editor/useUnsavedGuards.ts +233 -0
- package/frontend-vue/app/build/composables/graphCanvas/connect.ts +273 -0
- package/frontend-vue/app/build/composables/graphCanvas/edgeEvents.ts +172 -0
- package/frontend-vue/app/build/composables/graphCanvas/edges.ts +55 -0
- package/frontend-vue/app/build/composables/graphCanvas/handles.ts +181 -0
- package/frontend-vue/app/build/composables/graphCanvas/linkMenu.ts +123 -0
- package/frontend-vue/app/build/composables/graphCanvas/nodeData.ts +222 -0
- package/frontend-vue/app/build/composables/graphCanvas/placement.ts +248 -0
- package/frontend-vue/app/build/composables/graphCanvas/selection.ts +150 -0
- package/frontend-vue/app/build/composables/graphCanvas/types.ts +188 -0
- package/frontend-vue/app/build/composables/graphCanvas/view.ts +230 -0
- package/frontend-vue/app/build/types/editor.ts +94 -0
- package/frontend-vue/app/build/utils/editor/apiErrors.ts +74 -0
- package/frontend-vue/app/build/utils/editor/graphShape.ts +68 -0
- package/frontend-vue/app/build/utils/editor/groupPlan.ts +322 -0
- package/frontend-vue/app/build/utils/editor/groupPorts.ts +210 -0
- package/frontend-vue/app/build/utils/editor/keyboard.ts +22 -0
- package/frontend-vue/app/build/utils/inspectorFields.ts +117 -0
- package/frontend-vue/app/build/utils/templates.ts +88 -0
- package/frontend-vue/app/components/AttentionList.vue +2 -6
- package/frontend-vue/app/components/Catalog.vue +2 -1
- package/frontend-vue/app/components/Editor/BottomDock.vue +0 -3
- package/frontend-vue/app/components/Editor/GraphCanvas.vue +78 -1337
- package/frontend-vue/app/components/Editor/NodeInspector.vue +31 -123
- package/frontend-vue/app/components/Editor.vue +134 -3490
- package/frontend-vue/app/components/Templates.vue +14 -84
- package/frontend-vue/app/composables/useAutomationRuns.ts +2 -2
- package/frontend-vue/build/backend-boundary.ts +122 -0
- package/frontend-vue/dms.frontend.build.ts +2 -0
- package/frontend-vue/eslint-rules/index.mjs +103 -0
- package/frontend-vue/eslint.config.mjs +15 -0
- package/frontend-vue/i18n/locales/dms-automation-en-GB.json +0 -3
- package/frontend-vue/i18n/locales/dms-automation-fr-FR.json +0 -3
- package/frontend-vue/package.json +7 -4
- package/frontend-vue/pnpm-lock.yaml +98 -68
- package/frontend-vue/tests/api-error-presentation.test.cjs +257 -0
- package/frontend-vue/tests/helpers/setup.cjs +44 -0
- package/package.json +10 -10
- package/skills/dms-automation/SKILL.md +4 -4
- package/skills/dms-automation/cases.json +58 -0
- package/dist/runtime/departed.d.ts +0 -6
- package/dist/runtime/departed.js +0 -38
- package/dist/runtime/departed.js.map +0 -1
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
import { computed, onMounted, watch } from "vue";
|
|
2
|
+
import type { EditorContext } from "./useEditorContext";
|
|
3
|
+
import { type TriggerSummary } from "../../../utils/describe";
|
|
4
|
+
import type { SubgraphNavigation } from "./useSubgraphNavigation";
|
|
5
|
+
import type { DraftProblems } from "./useDraftProblems";
|
|
6
|
+
import type { RunOverlay } from "./useRunOverlay";
|
|
7
|
+
|
|
8
|
+
/** What the builder does when another procedure opens, when it mounts, and when its triggers change. */
|
|
9
|
+
export function useBuilderMount(
|
|
10
|
+
ctx: EditorContext,
|
|
11
|
+
nav: SubgraphNavigation,
|
|
12
|
+
problems: DraftProblems,
|
|
13
|
+
runs: RunOverlay,
|
|
14
|
+
) {
|
|
15
|
+
const {
|
|
16
|
+
builderPath,
|
|
17
|
+
draftTriggers,
|
|
18
|
+
editorMode,
|
|
19
|
+
missingProcedureId,
|
|
20
|
+
overlayRun,
|
|
21
|
+
processI18n,
|
|
22
|
+
processText,
|
|
23
|
+
queryValue,
|
|
24
|
+
route,
|
|
25
|
+
router,
|
|
26
|
+
selected,
|
|
27
|
+
selectedId,
|
|
28
|
+
selectedNodeId,
|
|
29
|
+
subgraphPath,
|
|
30
|
+
switcherOpen,
|
|
31
|
+
testTriggerNodeId,
|
|
32
|
+
triggerTypes,
|
|
33
|
+
} = ctx;
|
|
34
|
+
const { onGroupEnter } = nav;
|
|
35
|
+
const { selectNode } = problems;
|
|
36
|
+
const { openRunFromUrl } = runs;
|
|
37
|
+
|
|
38
|
+
// Another procedure opened: what the bar and the dock show follows it
|
|
39
|
+
// through their reads' URLs.
|
|
40
|
+
watch(selectedId, (id) => {
|
|
41
|
+
if (id) missingProcedureId.value = null;
|
|
42
|
+
overlayRun.value = null;
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
function enterPathFromUrl(): boolean {
|
|
46
|
+
const ids = (queryValue("path") ?? "").split(",").filter(Boolean);
|
|
47
|
+
for (const id of ids) {
|
|
48
|
+
const depth = subgraphPath.value.length;
|
|
49
|
+
onGroupEnter({ id });
|
|
50
|
+
if (subgraphPath.value.length === depth) break;
|
|
51
|
+
}
|
|
52
|
+
return subgraphPath.value.length > 1;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
onMounted(async () => {
|
|
56
|
+
if (missingProcedureId.value) switcherOpen.value = true;
|
|
57
|
+
const runId = queryValue("run");
|
|
58
|
+
if (runId) await openRunFromUrl(runId);
|
|
59
|
+
const nodeId = queryValue("node");
|
|
60
|
+
if (nodeId) {
|
|
61
|
+
if (enterPathFromUrl()) selectedNodeId.value = nodeId;
|
|
62
|
+
else selectNode(nodeId);
|
|
63
|
+
}
|
|
64
|
+
// The URL names the procedure on screen, to share or reload it.
|
|
65
|
+
if (
|
|
66
|
+
editorMode.value === "procedure" &&
|
|
67
|
+
selectedId.value &&
|
|
68
|
+
queryValue("selected") !== selectedId.value
|
|
69
|
+
) {
|
|
70
|
+
void router.replace({
|
|
71
|
+
path: builderPath(),
|
|
72
|
+
query: { ...route.query, selected: selectedId.value },
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
const selectedTriggerSummaries = computed<TriggerSummary[]>(() =>
|
|
78
|
+
(selected.value?.graph.nodes ?? [])
|
|
79
|
+
.filter((n) => n.kind === "trigger" && n.typeId)
|
|
80
|
+
.map((n) => ({
|
|
81
|
+
nodeId: n.id,
|
|
82
|
+
typeId: n.typeId!,
|
|
83
|
+
typeName:
|
|
84
|
+
triggerTypes.value.find((x) => x.id === n.typeId)?.name ?? n.typeId!,
|
|
85
|
+
path: typeof n.config?.path === "string" ? n.config.path : undefined,
|
|
86
|
+
method:
|
|
87
|
+
typeof n.config?.method === "string" ? n.config.method : undefined,
|
|
88
|
+
cron: typeof n.config?.cron === "string" ? n.config.cron : undefined,
|
|
89
|
+
})),
|
|
90
|
+
);
|
|
91
|
+
|
|
92
|
+
// A draft trigger as the server words it, its type's name until it has.
|
|
93
|
+
function triggerLabel(trigger: TriggerSummary): string {
|
|
94
|
+
const worded = draftTriggers.value.find(
|
|
95
|
+
(tr) => tr.nodeId === trigger.nodeId,
|
|
96
|
+
);
|
|
97
|
+
return worded ? processText(worded.text) : processI18n(trigger.typeName);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
// Test run starts from the trigger picked in the dock: the manual one, else
|
|
101
|
+
// the first, until the user picks another; its last real payload prefills
|
|
102
|
+
// the test payload.
|
|
103
|
+
const testTriggerItems = computed(() =>
|
|
104
|
+
selectedTriggerSummaries.value.map((trigger) => ({
|
|
105
|
+
label: triggerLabel(trigger),
|
|
106
|
+
value: trigger.nodeId ?? "",
|
|
107
|
+
})),
|
|
108
|
+
);
|
|
109
|
+
watch(
|
|
110
|
+
selectedTriggerSummaries,
|
|
111
|
+
(triggers) => {
|
|
112
|
+
if (
|
|
113
|
+
triggers.some((trigger) => trigger.nodeId === testTriggerNodeId.value)
|
|
114
|
+
)
|
|
115
|
+
return;
|
|
116
|
+
testTriggerNodeId.value =
|
|
117
|
+
triggers.find((trigger) => trigger.typeId === "manual")?.nodeId ??
|
|
118
|
+
triggers[0]?.nodeId;
|
|
119
|
+
},
|
|
120
|
+
{ immediate: true },
|
|
121
|
+
);
|
|
122
|
+
|
|
123
|
+
return {
|
|
124
|
+
selectedTriggerSummaries,
|
|
125
|
+
testTriggerItems,
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
export type BuilderMount = ReturnType<typeof useBuilderMount>;
|
|
@@ -0,0 +1,256 @@
|
|
|
1
|
+
import { watch } from "vue";
|
|
2
|
+
import type { EditorContext } from "./useEditorContext";
|
|
3
|
+
import { issuesOf } from "../../utils/editor/apiErrors";
|
|
4
|
+
import type { GraphIssue, ProcedureRecord } from "../../types/editor";
|
|
5
|
+
import type { GraphHistory } from "./useGraphHistory";
|
|
6
|
+
import type { DraftProblems } from "./useDraftProblems";
|
|
7
|
+
import type { SavedTriggers } from "./useSavedTriggers";
|
|
8
|
+
import type { UnsavedGuards } from "./useUnsavedGuards";
|
|
9
|
+
import { seedSubgraphPath } from "./useSubgraphNavigation";
|
|
10
|
+
|
|
11
|
+
/** Saving the open procedure (or template), and the way out of a save the server refused. */
|
|
12
|
+
export function useBuilderSave(
|
|
13
|
+
ctx: EditorContext,
|
|
14
|
+
history: GraphHistory,
|
|
15
|
+
problems: DraftProblems,
|
|
16
|
+
triggers: SavedTriggers,
|
|
17
|
+
guards: UnsavedGuards,
|
|
18
|
+
later: { onTestRun: () => Promise<void> },
|
|
19
|
+
) {
|
|
20
|
+
const { presentError } = useApiErrorPresenter();
|
|
21
|
+
const {
|
|
22
|
+
$authFetch,
|
|
23
|
+
dockCollapsed,
|
|
24
|
+
dockTab,
|
|
25
|
+
editorMode,
|
|
26
|
+
issues,
|
|
27
|
+
procedures,
|
|
28
|
+
props,
|
|
29
|
+
saveBlocked,
|
|
30
|
+
savedSnapshot,
|
|
31
|
+
saving,
|
|
32
|
+
selected,
|
|
33
|
+
selectedNodeId,
|
|
34
|
+
t,
|
|
35
|
+
templateIcon,
|
|
36
|
+
toast,
|
|
37
|
+
} = ctx;
|
|
38
|
+
const { initHistoryAndSaved, takeSnapshot } = history;
|
|
39
|
+
const {
|
|
40
|
+
NAME_INPUT_ID,
|
|
41
|
+
blockingIssues,
|
|
42
|
+
nameMissing,
|
|
43
|
+
savedName,
|
|
44
|
+
selectNode,
|
|
45
|
+
summariesRead,
|
|
46
|
+
} = problems;
|
|
47
|
+
const { savedTriggersRead } = triggers;
|
|
48
|
+
const { askChoice } = guards;
|
|
49
|
+
const { onTestRun } = later;
|
|
50
|
+
|
|
51
|
+
async function enableNow() {
|
|
52
|
+
if (!selected.value) return;
|
|
53
|
+
selected.value.enabled = true;
|
|
54
|
+
await onSave();
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/** Save the open procedure (or template). Resolves whether it was saved. */
|
|
58
|
+
async function onSave(): Promise<boolean> {
|
|
59
|
+
if (!selected.value) return false;
|
|
60
|
+
if (nameMissing.value) {
|
|
61
|
+
document.getElementById(NAME_INPUT_ID)?.focus();
|
|
62
|
+
return false;
|
|
63
|
+
}
|
|
64
|
+
saving.value = true;
|
|
65
|
+
const current = selected.value;
|
|
66
|
+
// What is sent is what counts as saved: a change made while the request
|
|
67
|
+
// runs stays an unsaved change.
|
|
68
|
+
const sent = takeSnapshot(current);
|
|
69
|
+
try {
|
|
70
|
+
if (editorMode.value === "template") {
|
|
71
|
+
await $authFetch(`${props.apiUrl}/templates/${current._id}`, {
|
|
72
|
+
method: "PUT",
|
|
73
|
+
body: {
|
|
74
|
+
name: sent.name,
|
|
75
|
+
description: current.description,
|
|
76
|
+
icon: templateIcon.value,
|
|
77
|
+
ports: sent.ports ?? [],
|
|
78
|
+
subgraph: sent.graph,
|
|
79
|
+
},
|
|
80
|
+
});
|
|
81
|
+
savedSnapshot.value = sent;
|
|
82
|
+
toast.add({
|
|
83
|
+
title: t("dms_automation.templates.saved", { name: sent.name }),
|
|
84
|
+
color: "success",
|
|
85
|
+
icon: "i-ph-check-circle",
|
|
86
|
+
});
|
|
87
|
+
return true;
|
|
88
|
+
}
|
|
89
|
+
const res = await $authFetch<{
|
|
90
|
+
version: number;
|
|
91
|
+
revision: number;
|
|
92
|
+
issues?: GraphIssue[];
|
|
93
|
+
}>(`${props.apiUrl}/procedures/${current._id}`, {
|
|
94
|
+
method: "PUT",
|
|
95
|
+
body: {
|
|
96
|
+
name: sent.name,
|
|
97
|
+
description: current.description,
|
|
98
|
+
enabled: sent.enabled,
|
|
99
|
+
graph: sent.graph,
|
|
100
|
+
expectedRevision: current.revision,
|
|
101
|
+
},
|
|
102
|
+
});
|
|
103
|
+
current.version = res.version;
|
|
104
|
+
current.revision = res.revision;
|
|
105
|
+
savedSnapshot.value = sent;
|
|
106
|
+
if (res.issues) issues.value = res.issues;
|
|
107
|
+
toast.add({
|
|
108
|
+
title: t("dms_automation.editor.savedToast", { name: sent.name }),
|
|
109
|
+
description: res.issues?.length
|
|
110
|
+
? t("dms_automation.editor.savedWithProblems", {
|
|
111
|
+
count: res.issues.length,
|
|
112
|
+
})
|
|
113
|
+
: undefined,
|
|
114
|
+
color: "success",
|
|
115
|
+
icon: "i-ph-check-circle",
|
|
116
|
+
actions: [
|
|
117
|
+
{
|
|
118
|
+
label: t("dms_automation.editor.testRun"),
|
|
119
|
+
onClick: () => void onTestRun(),
|
|
120
|
+
},
|
|
121
|
+
],
|
|
122
|
+
});
|
|
123
|
+
void summariesRead.refresh();
|
|
124
|
+
void savedTriggersRead.refresh();
|
|
125
|
+
return true;
|
|
126
|
+
} catch (e) {
|
|
127
|
+
if (editorMode.value === "procedure" && apiErrorStatus(e) === 409)
|
|
128
|
+
return await resolveStale(current, e);
|
|
129
|
+
const refused = issuesOf(e);
|
|
130
|
+
if (refused) {
|
|
131
|
+
issues.value = refused;
|
|
132
|
+
saveBlocked.value = true;
|
|
133
|
+
dockTab.value = "problems";
|
|
134
|
+
dockCollapsed.value = false;
|
|
135
|
+
} else {
|
|
136
|
+
presentError(e, {
|
|
137
|
+
fallbackKey:
|
|
138
|
+
editorMode.value === "template"
|
|
139
|
+
? "dms_automation.templates.saveError"
|
|
140
|
+
: "dms_automation.editor.saveError",
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
return false;
|
|
144
|
+
} finally {
|
|
145
|
+
saving.value = false;
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
/**
|
|
150
|
+
* The procedure was saved elsewhere (another tab, a pause from the list)
|
|
151
|
+
* since this draft was loaded, and the server refused to overwrite it:
|
|
152
|
+
* reload what is saved now, or overwrite it with the draft.
|
|
153
|
+
*/
|
|
154
|
+
async function resolveStale(
|
|
155
|
+
current: ProcedureRecord,
|
|
156
|
+
error: unknown,
|
|
157
|
+
): Promise<boolean> {
|
|
158
|
+
saving.value = false;
|
|
159
|
+
let latest = (error as { data: { revision: number } }).data.revision;
|
|
160
|
+
const choice = await askChoice({
|
|
161
|
+
title: t("dms_automation.editor.stale.title", { name: savedName.value }),
|
|
162
|
+
description: t("dms_automation.editor.stale.description"),
|
|
163
|
+
choices: [
|
|
164
|
+
{
|
|
165
|
+
value: "stay",
|
|
166
|
+
label: t("dms_automation.editor.stale.keep"),
|
|
167
|
+
color: "neutral",
|
|
168
|
+
variant: "ghost",
|
|
169
|
+
},
|
|
170
|
+
{
|
|
171
|
+
value: "reload",
|
|
172
|
+
label: t("dms_automation.editor.stale.reload"),
|
|
173
|
+
color: "neutral",
|
|
174
|
+
variant: "outline",
|
|
175
|
+
},
|
|
176
|
+
{
|
|
177
|
+
value: "overwrite",
|
|
178
|
+
label: t("dms_automation.editor.stale.overwrite"),
|
|
179
|
+
color: "warning",
|
|
180
|
+
},
|
|
181
|
+
],
|
|
182
|
+
dismiss: "stay",
|
|
183
|
+
});
|
|
184
|
+
if (choice === "overwrite") {
|
|
185
|
+
// Overwriting puts the draft's edits over what was saved elsewhere, not
|
|
186
|
+
// its on/off state over a pause or a resume made elsewhere: unless the
|
|
187
|
+
// switch was flipped in this draft, the procedure stays as it is now.
|
|
188
|
+
if (current.enabled === savedSnapshot.value?.enabled) {
|
|
189
|
+
try {
|
|
190
|
+
const saved = await $authFetch<{
|
|
191
|
+
enabled: boolean;
|
|
192
|
+
revision: number;
|
|
193
|
+
}>(`${props.apiUrl}/procedures/${current._id}`);
|
|
194
|
+
current.enabled = saved.enabled;
|
|
195
|
+
latest = saved.revision;
|
|
196
|
+
} catch {
|
|
197
|
+
// Unreadable: the draft's state is saved, as before.
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
current.revision = latest;
|
|
201
|
+
return await onSave();
|
|
202
|
+
}
|
|
203
|
+
if (choice === "reload") await reloadSelected();
|
|
204
|
+
return false;
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
/** Replaces the draft with the procedure as it is saved now. */
|
|
208
|
+
async function reloadSelected() {
|
|
209
|
+
const current = selected.value;
|
|
210
|
+
if (!current) return;
|
|
211
|
+
try {
|
|
212
|
+
const fresh = await $authFetch<ProcedureRecord>(
|
|
213
|
+
`${props.apiUrl}/procedures/${current._id}`,
|
|
214
|
+
);
|
|
215
|
+
procedures.value = procedures.value.map((p) =>
|
|
216
|
+
p._id === fresh._id ? fresh : p,
|
|
217
|
+
);
|
|
218
|
+
selectedNodeId.value = null;
|
|
219
|
+
initHistoryAndSaved();
|
|
220
|
+
seedSubgraphPath(ctx);
|
|
221
|
+
saveBlocked.value = false;
|
|
222
|
+
void summariesRead.refresh();
|
|
223
|
+
void savedTriggersRead.refresh();
|
|
224
|
+
} catch (e) {
|
|
225
|
+
presentError(e, {
|
|
226
|
+
fallbackKey: "dms_automation.editor.loadProceduresError",
|
|
227
|
+
});
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
watch(blockingIssues, (list) => {
|
|
232
|
+
if (list.length === 0) saveBlocked.value = false;
|
|
233
|
+
});
|
|
234
|
+
|
|
235
|
+
async function saveAsDraft() {
|
|
236
|
+
if (!selected.value) return;
|
|
237
|
+
selected.value.enabled = false;
|
|
238
|
+
if (await onSave()) saveBlocked.value = false;
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
function goToFirstProblem() {
|
|
242
|
+
const first =
|
|
243
|
+
blockingIssues.value.find((i) => i.nodeId) ??
|
|
244
|
+
issues.value.find((i) => i.nodeId);
|
|
245
|
+
if (first?.nodeId) selectNode(first.nodeId);
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
return {
|
|
249
|
+
onSave,
|
|
250
|
+
enableNow,
|
|
251
|
+
saveAsDraft,
|
|
252
|
+
goToFirstProblem,
|
|
253
|
+
};
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
export type BuilderSave = ReturnType<typeof useBuilderSave>;
|
|
@@ -0,0 +1,270 @@
|
|
|
1
|
+
import { nextTick, onBeforeUnmount, onMounted } from "vue";
|
|
2
|
+
import type { EditorContext } from "./useEditorContext";
|
|
3
|
+
import type { ProcedureGraph } from "../../../composables/useGraphConnect";
|
|
4
|
+
import { newId } from "../../../utils/automation";
|
|
5
|
+
import { cloneGraph } from "../../utils/editor/graphShape";
|
|
6
|
+
import {
|
|
7
|
+
isActivatable,
|
|
8
|
+
isEditableTarget,
|
|
9
|
+
OVERLAY_SELECTOR,
|
|
10
|
+
} from "../../utils/editor/keyboard";
|
|
11
|
+
import type { GraphHistory } from "./useGraphHistory";
|
|
12
|
+
import type { SubgraphNavigation } from "./useSubgraphNavigation";
|
|
13
|
+
import type { GroupEditing } from "./useGroupEditing";
|
|
14
|
+
import type { UnsavedGuards } from "./useUnsavedGuards";
|
|
15
|
+
import type { BuilderSave } from "./useBuilderSave";
|
|
16
|
+
import type { SaveAsTemplate } from "./useSaveAsTemplate";
|
|
17
|
+
import type { ForkToLocal } from "./useForkToLocal";
|
|
18
|
+
|
|
19
|
+
/** The builder's keyboard shortcuts, and the clipboard they copy and paste through. */
|
|
20
|
+
export function useBuilderShortcuts(
|
|
21
|
+
ctx: EditorContext,
|
|
22
|
+
history: GraphHistory,
|
|
23
|
+
nav: SubgraphNavigation,
|
|
24
|
+
groups: GroupEditing,
|
|
25
|
+
guards: UnsavedGuards,
|
|
26
|
+
save: BuilderSave,
|
|
27
|
+
saveTpl: SaveAsTemplate,
|
|
28
|
+
fork: ForkToLocal,
|
|
29
|
+
later: { onTestRun: () => Promise<void>; exitDebug: () => void },
|
|
30
|
+
) {
|
|
31
|
+
const {
|
|
32
|
+
currentGraph,
|
|
33
|
+
editorMode,
|
|
34
|
+
isCurrentGraphReadOnly,
|
|
35
|
+
newProcedureOpen,
|
|
36
|
+
overlayRun,
|
|
37
|
+
runNowOpen,
|
|
38
|
+
selectedNode,
|
|
39
|
+
selectedNodeId,
|
|
40
|
+
selectedNodeIds,
|
|
41
|
+
subgraphPath,
|
|
42
|
+
switcherOpen,
|
|
43
|
+
} = ctx;
|
|
44
|
+
const { isDirty, onRedo, onUndo } = history;
|
|
45
|
+
const { canEnterGroup, enterSelectedGroup, exitSubgraph, onGraphUpdate } =
|
|
46
|
+
nav;
|
|
47
|
+
const { onDuplicateNode } = groups;
|
|
48
|
+
const { browserNavigation, choiceDialog, onInertiaBefore, onNavigate } =
|
|
49
|
+
guards;
|
|
50
|
+
const { onSave } = save;
|
|
51
|
+
const { saveAsTemplateOpen } = saveTpl;
|
|
52
|
+
const { forkOpen } = fork;
|
|
53
|
+
const { exitDebug, onTestRun } = later;
|
|
54
|
+
|
|
55
|
+
// Keyboard. With Ctrl (⌘ on macOS): S saves, Enter runs a test, P opens the
|
|
56
|
+
// switcher, Z / Shift+Z / Y undo and redo, D duplicates the selected step, C
|
|
57
|
+
// and V copy and paste the selection. Enter enters the selected group, Escape
|
|
58
|
+
// leaves the debug view, then the group, then the selection. Tab is left to
|
|
59
|
+
// the focus. Keys typed in a field, or while a dialog or a menu is open,
|
|
60
|
+
// belong to them.
|
|
61
|
+
|
|
62
|
+
function isOverlayOpen(): boolean {
|
|
63
|
+
return (
|
|
64
|
+
saveAsTemplateOpen.value ||
|
|
65
|
+
forkOpen.value ||
|
|
66
|
+
switcherOpen.value ||
|
|
67
|
+
runNowOpen.value ||
|
|
68
|
+
newProcedureOpen.value ||
|
|
69
|
+
choiceDialog.value.open ||
|
|
70
|
+
document.querySelector(OVERLAY_SELECTOR) !== null
|
|
71
|
+
);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Blurs the focused field so it commits what is typed in it (a JSON setting
|
|
76
|
+
* or the step name only do on blur), and returns it to focus again after.
|
|
77
|
+
*/
|
|
78
|
+
async function commitFocusedField(): Promise<HTMLElement | null> {
|
|
79
|
+
const field = document.activeElement;
|
|
80
|
+
if (!(field instanceof HTMLElement) || !isEditableTarget(field))
|
|
81
|
+
return null;
|
|
82
|
+
field.blur();
|
|
83
|
+
await nextTick();
|
|
84
|
+
return field;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
async function saveFromKeyboard() {
|
|
88
|
+
const field = await commitFocusedField();
|
|
89
|
+
if (isDirty.value) await onSave();
|
|
90
|
+
field?.focus();
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
async function testRunFromKeyboard() {
|
|
94
|
+
const field = await commitFocusedField();
|
|
95
|
+
await onTestRun();
|
|
96
|
+
field?.focus();
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
// Ctrl+C / Ctrl+V: the selected steps and the wires between them, pasted as
|
|
100
|
+
// new steps beside the originals, in this graph or another one.
|
|
101
|
+
let clipboard: ProcedureGraph | null = null;
|
|
102
|
+
|
|
103
|
+
function copySelection(): boolean {
|
|
104
|
+
const g = currentGraph.value;
|
|
105
|
+
const ids = new Set(
|
|
106
|
+
selectedNodeIds.value.length > 0
|
|
107
|
+
? selectedNodeIds.value
|
|
108
|
+
: selectedNodeId.value
|
|
109
|
+
? [selectedNodeId.value]
|
|
110
|
+
: [],
|
|
111
|
+
);
|
|
112
|
+
if (!g || ids.size === 0) return false;
|
|
113
|
+
const nodes = g.nodes.filter(
|
|
114
|
+
(n) =>
|
|
115
|
+
ids.has(n.id) && n.kind !== "groupInput" && n.kind !== "groupOutput",
|
|
116
|
+
);
|
|
117
|
+
if (nodes.length === 0) return false;
|
|
118
|
+
const kept = new Set(nodes.map((n) => n.id));
|
|
119
|
+
clipboard = cloneGraph({
|
|
120
|
+
nodes,
|
|
121
|
+
triggerEdges: g.triggerEdges.filter(
|
|
122
|
+
(e) => kept.has(e.from.node) && kept.has(e.to.node),
|
|
123
|
+
),
|
|
124
|
+
dataEdges: g.dataEdges.filter(
|
|
125
|
+
(e) => kept.has(e.from.node) && kept.has(e.to.node),
|
|
126
|
+
),
|
|
127
|
+
});
|
|
128
|
+
return true;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
function pasteClipboard(): boolean {
|
|
132
|
+
const g = currentGraph.value;
|
|
133
|
+
if (!g || !clipboard || isCurrentGraphReadOnly.value) return false;
|
|
134
|
+
// Triggers only live at the top level of a procedure.
|
|
135
|
+
const triggersAllowed =
|
|
136
|
+
editorMode.value === "procedure" && subgraphPath.value.length <= 1;
|
|
137
|
+
// Each paste lands one step further, like Duplicate.
|
|
138
|
+
clipboard.nodes = clipboard.nodes.map((n) => ({
|
|
139
|
+
...n,
|
|
140
|
+
position: { x: n.position.x + 40, y: n.position.y + 60 },
|
|
141
|
+
}));
|
|
142
|
+
const source = cloneGraph(clipboard);
|
|
143
|
+
const nodes = source.nodes.filter(
|
|
144
|
+
(n) => triggersAllowed || n.kind !== "trigger",
|
|
145
|
+
);
|
|
146
|
+
if (nodes.length === 0) return false;
|
|
147
|
+
const ids = new Map(nodes.map((n) => [n.id, newId()]));
|
|
148
|
+
const idOf = (id: string) => ids.get(id)!;
|
|
149
|
+
const pasted = nodes.map((n) => ({ ...n, id: idOf(n.id) }));
|
|
150
|
+
const triggerEdges = source.triggerEdges
|
|
151
|
+
.filter((e) => ids.has(e.from.node) && ids.has(e.to.node))
|
|
152
|
+
.map((e) => ({
|
|
153
|
+
...e,
|
|
154
|
+
id: newId(),
|
|
155
|
+
from: { ...e.from, node: idOf(e.from.node) },
|
|
156
|
+
to: { ...e.to, node: idOf(e.to.node) },
|
|
157
|
+
}));
|
|
158
|
+
const dataEdges = source.dataEdges
|
|
159
|
+
.filter((e) => ids.has(e.from.node) && ids.has(e.to.node))
|
|
160
|
+
.map((e) => ({
|
|
161
|
+
...e,
|
|
162
|
+
id: newId(),
|
|
163
|
+
from: { ...e.from, node: idOf(e.from.node) },
|
|
164
|
+
to: { ...e.to, node: idOf(e.to.node) },
|
|
165
|
+
}));
|
|
166
|
+
onGraphUpdate({
|
|
167
|
+
...g,
|
|
168
|
+
nodes: [...g.nodes, ...pasted],
|
|
169
|
+
triggerEdges: [...g.triggerEdges, ...triggerEdges],
|
|
170
|
+
dataEdges: [...g.dataEdges, ...dataEdges],
|
|
171
|
+
});
|
|
172
|
+
selectedNodeId.value = pasted.at(-1)!.id;
|
|
173
|
+
return true;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
/** The editing shortcuts, on the canvas: whatever is not typed in a field. */
|
|
177
|
+
function onEditShortcut(ev: KeyboardEvent, key: string): boolean {
|
|
178
|
+
if (isEditableTarget(ev.target)) return false;
|
|
179
|
+
if (key === "z" || key === "y") {
|
|
180
|
+
if (key === "y" || ev.shiftKey) onRedo();
|
|
181
|
+
else onUndo();
|
|
182
|
+
return true;
|
|
183
|
+
}
|
|
184
|
+
if (key === "d") {
|
|
185
|
+
const node = selectedNode.value;
|
|
186
|
+
if (node && node.kind !== "groupInput" && node.kind !== "groupOutput")
|
|
187
|
+
onDuplicateNode({ id: node.id });
|
|
188
|
+
return true;
|
|
189
|
+
}
|
|
190
|
+
// A text selected on the page is copied as text.
|
|
191
|
+
if (key === "c")
|
|
192
|
+
return !window.getSelection()?.toString() && copySelection();
|
|
193
|
+
if (key === "v") return pasteClipboard();
|
|
194
|
+
return false;
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
// Listened to in the capture phase, so a focused field (a select opens on
|
|
198
|
+
// Enter) never sees a shortcut meant for the builder.
|
|
199
|
+
function onShortcut(ev: KeyboardEvent): boolean {
|
|
200
|
+
if (!(ev.metaKey || ev.ctrlKey) || ev.altKey) return false;
|
|
201
|
+
const key = ev.key.toLowerCase();
|
|
202
|
+
// The browser's "Save page" is never what Ctrl+S means here.
|
|
203
|
+
if (key === "s") ev.preventDefault();
|
|
204
|
+
if (isOverlayOpen()) return false;
|
|
205
|
+
if (["s", "enter", "p"].includes(key)) ev.stopPropagation();
|
|
206
|
+
if (key === "s") {
|
|
207
|
+
void saveFromKeyboard();
|
|
208
|
+
return true;
|
|
209
|
+
}
|
|
210
|
+
if (key === "enter" && editorMode.value === "procedure") {
|
|
211
|
+
ev.preventDefault();
|
|
212
|
+
void testRunFromKeyboard();
|
|
213
|
+
return true;
|
|
214
|
+
}
|
|
215
|
+
if (key === "p" && editorMode.value === "procedure") {
|
|
216
|
+
ev.preventDefault();
|
|
217
|
+
switcherOpen.value = true;
|
|
218
|
+
return true;
|
|
219
|
+
}
|
|
220
|
+
if (onEditShortcut(ev, key)) {
|
|
221
|
+
ev.preventDefault();
|
|
222
|
+
ev.stopPropagation();
|
|
223
|
+
return true;
|
|
224
|
+
}
|
|
225
|
+
return false;
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
function onKeyDown(ev: KeyboardEvent) {
|
|
229
|
+
if (onShortcut(ev)) return;
|
|
230
|
+
if (isEditableTarget(ev.target) || isOverlayOpen()) return;
|
|
231
|
+
if (
|
|
232
|
+
ev.key === "Enter" &&
|
|
233
|
+
!ev.shiftKey &&
|
|
234
|
+
!ev.ctrlKey &&
|
|
235
|
+
!ev.metaKey &&
|
|
236
|
+
!ev.altKey
|
|
237
|
+
) {
|
|
238
|
+
if (!canEnterGroup.value || isActivatable(ev.target)) return;
|
|
239
|
+
ev.preventDefault();
|
|
240
|
+
enterSelectedGroup();
|
|
241
|
+
return;
|
|
242
|
+
}
|
|
243
|
+
if (ev.key !== "Escape") return;
|
|
244
|
+
if (overlayRun.value && subgraphPath.value.length <= 1) {
|
|
245
|
+
ev.preventDefault();
|
|
246
|
+
exitDebug();
|
|
247
|
+
} else if (subgraphPath.value.length > 1) {
|
|
248
|
+
ev.preventDefault();
|
|
249
|
+
exitSubgraph();
|
|
250
|
+
} else if (selectedNodeId.value) {
|
|
251
|
+
ev.preventDefault();
|
|
252
|
+
selectedNodeId.value = null;
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
onMounted(() => {
|
|
257
|
+
if (typeof window === "undefined") return;
|
|
258
|
+
window.addEventListener("keydown", onKeyDown, { capture: true });
|
|
259
|
+
document.addEventListener("inertia:before", onInertiaBefore);
|
|
260
|
+
browserNavigation()?.addEventListener("navigate", onNavigate);
|
|
261
|
+
});
|
|
262
|
+
onBeforeUnmount(() => {
|
|
263
|
+
if (typeof window === "undefined") return;
|
|
264
|
+
window.removeEventListener("keydown", onKeyDown, { capture: true });
|
|
265
|
+
document.removeEventListener("inertia:before", onInertiaBefore);
|
|
266
|
+
browserNavigation()?.removeEventListener("navigate", onNavigate);
|
|
267
|
+
});
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
export type BuilderShortcuts = ReturnType<typeof useBuilderShortcuts>;
|