@minnalstack/editor-plugin-date-time 0.0.0-stage → 0.3.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/LICENSE +21 -0
- package/README.md +16 -2
- package/dist/index.d.ts +33 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +45 -0
- package/dist/index.js.map +1 -0
- package/package.json +26 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Aranghat
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,17 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @minnalstack/editor-plugin-date-time
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
`DateTimePlugin` puts the date or the time now where the caret is, as plain text written the way the page's language writes it: from the slash menu ("Date", "Time"), or with `Alt-Shift-d` and `Alt-Shift-t`, as Word has them.
|
|
4
|
+
|
|
5
|
+
```ts
|
|
6
|
+
import { DateTimePlugin, InsertDate, InsertTime } from '@minnalstack/editor-plugin-date-time';
|
|
7
|
+
|
|
8
|
+
builder.plugins.add(new DateTimePlugin());
|
|
9
|
+
// In Malayalam, with the weekday, and a 24-hour clock:
|
|
10
|
+
builder.plugins.add(new DateTimePlugin({ locale: 'ml-IN', dateFormat: { dateStyle: 'full' }, timeFormat: { hour: '2-digit', minute: '2-digit', hourCycle: 'h23' } }));
|
|
11
|
+
|
|
12
|
+
editor.execute(InsertDate);
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
The language is the page's own, from `<html lang>`, or else the browser's, unless `locale` says one. The formats are any options `Intl.DateTimeFormat` takes; the defaults are a long date, as in "7 November 2026", and a short time. `clock` gives the time now, for tests.
|
|
16
|
+
|
|
17
|
+
It works on any preset.
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { EditorPlugin, type PluginContext } from '@minnalstack/editor-core';
|
|
2
|
+
/** Puts today's date where the selection is, as text. */
|
|
3
|
+
export declare const InsertDate: import("@minnalstack/editor-core").Command<void>;
|
|
4
|
+
/** Puts the time now where the selection is, as text. */
|
|
5
|
+
export declare const InsertTime: import("@minnalstack/editor-core").Command<void>;
|
|
6
|
+
export interface DateTimePluginOptions {
|
|
7
|
+
/** The language to write in, such as `en-GB` or `ml-IN`. The default is the page's own, from `<html lang>`, or else the browser's. */
|
|
8
|
+
readonly locale?: string;
|
|
9
|
+
/** How a date is written. The default is `{ dateStyle: 'long' }`, as in "7 November 2026". */
|
|
10
|
+
readonly dateFormat?: Intl.DateTimeFormatOptions;
|
|
11
|
+
/** How a time is written. The default is `{ timeStyle: 'short' }`, as in "14:05". */
|
|
12
|
+
readonly timeFormat?: Intl.DateTimeFormatOptions;
|
|
13
|
+
/** What says the time now. The default is the system's clock. */
|
|
14
|
+
readonly clock?: () => Date;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* The date or the time now, as text, written as the page's language writes it, from the slash menu ("Date", "Time") or a key: `Alt-Shift-d` and `Alt-Shift-t`, as Word has
|
|
18
|
+
* them. It is plain text, so it stays as it was written. Works on any preset.
|
|
19
|
+
*/
|
|
20
|
+
export declare class DateTimePlugin extends EditorPlugin {
|
|
21
|
+
readonly name = "date-time";
|
|
22
|
+
private readonly options;
|
|
23
|
+
private dates;
|
|
24
|
+
private times;
|
|
25
|
+
constructor(options?: DateTimePluginOptions);
|
|
26
|
+
/** A date as {@link InsertDate} writes it: today's, by default. */
|
|
27
|
+
formatDate(date?: Date): string;
|
|
28
|
+
/** A time as {@link InsertTime} writes it: now, by default. */
|
|
29
|
+
formatTime(date?: Date): string;
|
|
30
|
+
private now;
|
|
31
|
+
configure(context: PluginContext): void;
|
|
32
|
+
}
|
|
33
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAuB,YAAY,EAAE,KAAK,aAAa,EAAiB,MAAM,0BAA0B,CAAC;AAEhH,yDAAyD;AACzD,eAAO,MAAM,UAAU,kDAA0H,CAAC;AAClJ,yDAAyD;AACzD,eAAO,MAAM,UAAU,kDAA0H,CAAC;AAElJ,MAAM,WAAW,qBAAqB;IACpC,sIAAsI;IACtI,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;IACzB,8FAA8F;IAC9F,QAAQ,CAAC,UAAU,CAAC,EAAE,IAAI,CAAC,qBAAqB,CAAC;IACjD,qFAAqF;IACrF,QAAQ,CAAC,UAAU,CAAC,EAAE,IAAI,CAAC,qBAAqB,CAAC;IACjD,iEAAiE;IACjE,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,IAAI,CAAC;CAC7B;AAMD;;;GAGG;AACH,qBAAa,cAAe,SAAQ,YAAY;IAC9C,SAAkB,IAAI,eAAe;IACrC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAwB;IAChD,OAAO,CAAC,KAAK,CAAoC;IACjD,OAAO,CAAC,KAAK,CAAoC;IAEjD,YAAY,OAAO,GAAE,qBAA0B,EAG9C;IAED,mEAAmE;IACnE,UAAU,CAAC,IAAI,GAAE,IAAiB,GAAG,MAAM,CAG1C;IAED,+DAA+D;IAC/D,UAAU,CAAC,IAAI,GAAE,IAAiB,GAAG,MAAM,CAG1C;IAED,OAAO,CAAC,GAAG;IAIF,SAAS,CAAC,OAAO,EAAE,aAAa,GAAG,IAAI,CAQ/C;CACF"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { EditorPlugin, defineCommand } from '@minnalstack/editor-core';
|
|
2
|
+
/** Puts today's date where the selection is, as text. */
|
|
3
|
+
export const InsertDate = defineCommand('dateTime.insertDate', { description: "Puts today's date at the caret, written in the page's language" });
|
|
4
|
+
/** Puts the time now where the selection is, as text. */
|
|
5
|
+
export const InsertTime = defineCommand('dateTime.insertTime', { description: "Puts the time now at the caret, written in the page's language" });
|
|
6
|
+
function pageLocale() {
|
|
7
|
+
return typeof document === 'undefined' ? undefined : document.documentElement.lang || undefined;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* The date or the time now, as text, written as the page's language writes it, from the slash menu ("Date", "Time") or a key: `Alt-Shift-d` and `Alt-Shift-t`, as Word has
|
|
11
|
+
* them. It is plain text, so it stays as it was written. Works on any preset.
|
|
12
|
+
*/
|
|
13
|
+
export class DateTimePlugin extends EditorPlugin {
|
|
14
|
+
name = 'date-time';
|
|
15
|
+
options;
|
|
16
|
+
dates = null;
|
|
17
|
+
times = null;
|
|
18
|
+
constructor(options = {}) {
|
|
19
|
+
super();
|
|
20
|
+
this.options = options;
|
|
21
|
+
}
|
|
22
|
+
/** A date as {@link InsertDate} writes it: today's, by default. */
|
|
23
|
+
formatDate(date = this.now()) {
|
|
24
|
+
this.dates ??= new Intl.DateTimeFormat(this.options.locale ?? pageLocale(), this.options.dateFormat ?? { dateStyle: 'long' });
|
|
25
|
+
return this.dates.format(date);
|
|
26
|
+
}
|
|
27
|
+
/** A time as {@link InsertTime} writes it: now, by default. */
|
|
28
|
+
formatTime(date = this.now()) {
|
|
29
|
+
this.times ??= new Intl.DateTimeFormat(this.options.locale ?? pageLocale(), this.options.timeFormat ?? { timeStyle: 'short' });
|
|
30
|
+
return this.times.format(date);
|
|
31
|
+
}
|
|
32
|
+
now() {
|
|
33
|
+
return this.options.clock?.() ?? new Date();
|
|
34
|
+
}
|
|
35
|
+
configure(context) {
|
|
36
|
+
const canInsert = (ctx) => ctx.editor.selection?.kind === 'text';
|
|
37
|
+
context.commands.add(InsertDate, { canExecute: canInsert, execute: (ctx) => ctx.editor.edit((edit) => edit.replaceSelection(this.formatDate())) });
|
|
38
|
+
context.commands.add(InsertTime, { canExecute: canInsert, execute: (ctx) => ctx.editor.edit((edit) => edit.replaceSelection(this.formatTime())) });
|
|
39
|
+
context.keys.add('Alt-Shift-d', InsertDate);
|
|
40
|
+
context.keys.add('Alt-Shift-t', InsertTime);
|
|
41
|
+
context.menus.slash.add({ command: InsertDate, label: 'Date', icon: 'date', keywords: ['today', 'day'], category: 'Insert', group: 'insert', order: 47 });
|
|
42
|
+
context.menus.slash.add({ command: InsertTime, label: 'Time', icon: 'time', keywords: ['now', 'clock', 'hour'], category: 'Insert', group: 'insert', order: 48 });
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAuB,YAAY,EAAsB,aAAa,EAAE,MAAM,0BAA0B,CA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AAO,EAAE,KAAK,CAAC,EAAE,QAAQ,EAAE,QAAQ,EAAE,KAAK,EAAE,QAAQ,EAAE,KAAK,EAAE,EAAE,EAAE,CAAC,CAAC;QAC1J,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,EAAE,OAAO,EAAE,UAAU,EAAE,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,CAAC,KAAK,EAAE,OAAO,EAAE,MAAM,CAAC,EAAE,QAAQ,EAAE,QAAQ,EAAE,KAAK,EAAE,QAAQ,EAAE,KAAK,EAAE,EAAE,EAAE,CAAC,CAAC;IACpK,CAAC;CACF"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,28 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@minnalstack/editor-plugin-date-time",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"description": "
|
|
6
|
-
|
|
3
|
+
"version": "0.3.0",
|
|
4
|
+
"license": "MIT",
|
|
5
|
+
"description": "The date or the time now, as text in the page's language, for Minnal Editor: from the slash menu, or Alt-Shift-d and Alt-Shift-t.",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": {
|
|
9
|
+
"types": "./dist/index.d.ts",
|
|
10
|
+
"default": "./dist/index.js"
|
|
11
|
+
}
|
|
12
|
+
},
|
|
13
|
+
"types": "./dist/index.d.ts",
|
|
14
|
+
"files": [
|
|
15
|
+
"dist"
|
|
16
|
+
],
|
|
17
|
+
"sideEffects": false,
|
|
18
|
+
"scripts": {
|
|
19
|
+
"build": "tsc -p tsconfig.json"
|
|
20
|
+
},
|
|
21
|
+
"peerDependencies": {
|
|
22
|
+
"@minnalstack/editor-core": "^0.3.0"
|
|
23
|
+
},
|
|
24
|
+
"publishConfig": {
|
|
25
|
+
"access": "public",
|
|
26
|
+
"registry": "https://registry.npmjs.org/"
|
|
27
|
+
}
|
|
28
|
+
}
|