Files
outline/shared/editor/extensions/DateTime.ts
Tom Moor bf45e97641 chore: Enforce type import consistency (#10968)
* Update types

* fix circular dep

* type imports

* lint type imports and --fix
2025-12-19 23:07:02 -05:00

49 lines
1.2 KiB
TypeScript

import type { Schema } from "prosemirror-model";
import type { Command } from "prosemirror-state";
import {
getCurrentDateAsString,
getCurrentDateTimeAsString,
getCurrentTimeAsString,
} from "../../utils/date";
import Extension from "../lib/Extension";
/**
* An editor extension that adds commands to insert the current date and time.
*/
export default class DateTime extends Extension {
get name() {
return "date_time";
}
commands(_options: { schema: Schema }) {
const { template } = this.editor.props;
return {
date: (): Command => (state, dispatch) => {
dispatch?.(
state.tr.insertText(
(template ? "{date}" : getCurrentDateAsString()) + " "
)
);
return true;
},
time: (): Command => (state, dispatch) => {
dispatch?.(
state.tr.insertText(
(template ? "{time}" : getCurrentTimeAsString()) + " "
)
);
return true;
},
datetime: (): Command => (state, dispatch) => {
dispatch?.(
state.tr.insertText(
(template ? "{datetime}" : getCurrentDateTimeAsString()) + " "
)
);
return true;
},
};
}
}