@atlaskit/editor-plugin-date 0.1.0 → 0.2.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/CHANGELOG.md +10 -0
- package/dist/cjs/actions.js +105 -0
- package/dist/cjs/commands.js +114 -1
- package/dist/cjs/index.js +9 -1
- package/dist/cjs/nodeviews/date.js +44 -0
- package/dist/cjs/plugin.js +197 -0
- package/dist/cjs/pm-plugins/keymap.js +41 -0
- package/dist/cjs/pm-plugins/main.js +39 -0
- package/dist/cjs/pm-plugins/plugin-key.js +8 -0
- package/dist/cjs/pm-plugins/types.js +5 -0
- package/dist/cjs/pm-plugins/utils.js +70 -0
- package/dist/cjs/ui/DatePicker/date-picker-input.js +253 -0
- package/dist/cjs/ui/DatePicker/index.js +170 -0
- package/dist/cjs/utils/formatParse.js +88 -0
- package/dist/cjs/utils/internal.js +176 -0
- package/dist/es2019/actions.js +93 -0
- package/dist/es2019/commands.js +113 -1
- package/dist/es2019/index.js +1 -1
- package/dist/es2019/nodeviews/date.js +47 -0
- package/dist/es2019/plugin.js +183 -0
- package/dist/es2019/pm-plugins/keymap.js +34 -0
- package/dist/es2019/pm-plugins/main.js +35 -0
- package/dist/es2019/pm-plugins/plugin-key.js +2 -0
- package/dist/es2019/pm-plugins/types.js +1 -0
- package/dist/es2019/pm-plugins/utils.js +70 -0
- package/dist/es2019/ui/DatePicker/date-picker-input.js +242 -0
- package/dist/es2019/ui/DatePicker/index.js +154 -0
- package/dist/es2019/utils/formatParse.js +83 -0
- package/dist/es2019/utils/internal.js +151 -0
- package/dist/esm/actions.js +99 -0
- package/dist/esm/commands.js +112 -1
- package/dist/esm/index.js +1 -1
- package/dist/esm/nodeviews/date.js +37 -0
- package/dist/esm/plugin.js +185 -0
- package/dist/esm/pm-plugins/keymap.js +34 -0
- package/dist/esm/pm-plugins/main.js +34 -0
- package/dist/esm/pm-plugins/plugin-key.js +2 -0
- package/dist/esm/pm-plugins/types.js +1 -0
- package/dist/esm/pm-plugins/utils.js +61 -0
- package/dist/esm/ui/DatePicker/date-picker-input.js +247 -0
- package/dist/esm/ui/DatePicker/index.js +164 -0
- package/dist/esm/utils/formatParse.js +79 -0
- package/dist/esm/utils/internal.js +165 -0
- package/dist/types/actions.d.ts +49 -0
- package/dist/types/commands.d.ts +12 -10
- package/dist/types/index.d.ts +1 -1
- package/dist/types/nodeviews/date.d.ts +3 -0
- package/dist/types/plugin.d.ts +3 -0
- package/dist/types/pm-plugins/keymap.d.ts +3 -0
- package/dist/types/pm-plugins/main.d.ts +6 -0
- package/dist/types/pm-plugins/plugin-key.d.ts +3 -0
- package/dist/types/pm-plugins/types.d.ts +12 -0
- package/dist/types/pm-plugins/utils.d.ts +5 -0
- package/dist/types/types.d.ts +10 -2
- package/dist/types/ui/DatePicker/date-picker-input.d.ts +25 -0
- package/dist/types/ui/DatePicker/index.d.ts +36 -0
- package/dist/types/utils/formatParse.d.ts +27 -0
- package/dist/types/utils/internal.d.ts +32 -0
- package/dist/types-ts4.5/actions.d.ts +60 -0
- package/dist/types-ts4.5/commands.d.ts +14 -10
- package/dist/types-ts4.5/index.d.ts +1 -1
- package/dist/types-ts4.5/nodeviews/date.d.ts +3 -0
- package/dist/types-ts4.5/plugin.d.ts +3 -0
- package/dist/types-ts4.5/pm-plugins/keymap.d.ts +3 -0
- package/dist/types-ts4.5/pm-plugins/main.d.ts +6 -0
- package/dist/types-ts4.5/pm-plugins/plugin-key.d.ts +3 -0
- package/dist/types-ts4.5/pm-plugins/types.d.ts +12 -0
- package/dist/types-ts4.5/pm-plugins/utils.d.ts +5 -0
- package/dist/types-ts4.5/types.d.ts +10 -2
- package/dist/types-ts4.5/ui/DatePicker/date-picker-input.d.ts +25 -0
- package/dist/types-ts4.5/ui/DatePicker/index.d.ts +36 -0
- package/dist/types-ts4.5/utils/formatParse.d.ts +27 -0
- package/dist/types-ts4.5/utils/internal.d.ts +32 -0
- package/package.json +29 -4
- package/report.api.md +5 -2
- package/tmp/api-report-tmp.d.ts +5 -2
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import type { Command, CommandDispatch, ExtractInjectionAPI } from '@atlaskit/editor-common/types';
|
|
2
|
+
import type { EditorState, Transaction } from '@atlaskit/editor-prosemirror/state';
|
|
3
|
+
import type { DatePlugin, DateType } from './types';
|
|
4
|
+
export declare const createDate: (isQuickInsertAction?: boolean) => (insert: (node: Node | Object | string, opts?: {
|
|
5
|
+
selectInlineNode: boolean;
|
|
6
|
+
}) => Transaction, state: EditorState) => Transaction;
|
|
7
|
+
/** Focus input */
|
|
8
|
+
export declare const focusDateInput: () => (state: EditorState, dispatch: CommandDispatch | undefined) => boolean;
|
|
9
|
+
export declare const setDatePickerAt: (showDatePickerAt: number | null) => (state: EditorState, dispatch: (tr: Transaction) => void) => boolean;
|
|
10
|
+
export declare const closeDatePicker: () => Command;
|
|
11
|
+
export declare const closeDatePickerWithAnalytics: ({ date, pluginInjectionApi, }: {
|
|
12
|
+
date?: DateType | undefined;
|
|
13
|
+
pluginInjectionApi?: import("@atlaskit/editor-common/types").PublicPluginAPI<[import("@atlaskit/editor-common/types").NextEditorPluginFunctionOptionalConfigDefinition<"date", {
|
|
14
|
+
pluginConfiguration: import("./types").DatePluginConfig | undefined;
|
|
15
|
+
dependencies: [import("@atlaskit/editor-common/types").NextEditorPluginFunctionOptionalConfigDefinition<"analytics", {
|
|
16
|
+
pluginConfiguration: import("@atlaskit/editor-plugin-analytics").AnalyticsPluginOptions;
|
|
17
|
+
sharedState: {
|
|
18
|
+
createAnalyticsEvent: import("@atlaskit/analytics-next").CreateUIAnalyticsEvent | null;
|
|
19
|
+
attachAnalyticsEvent: import("@atlaskit/editor-plugin-analytics").CreateAttachPayloadIntoTransaction | null;
|
|
20
|
+
};
|
|
21
|
+
dependencies: [import("@atlaskit/editor-common/types").NextEditorPluginFunctionOptionalConfigDefinition<"featureFlags", {
|
|
22
|
+
pluginConfiguration: import("@atlaskit/editor-common/types").FeatureFlags;
|
|
23
|
+
sharedState: import("@atlaskit/editor-common/types").FeatureFlags;
|
|
24
|
+
}, import("@atlaskit/editor-common/types").FeatureFlags>];
|
|
25
|
+
actions: import("@atlaskit/editor-common/analytics").EditorAnalyticsAPI;
|
|
26
|
+
}, import("@atlaskit/editor-plugin-analytics").AnalyticsPluginOptions>, import("@atlaskit/editor-common/types").NextEditorPluginFunctionOptionalConfigDefinition<"editorDisabled", {
|
|
27
|
+
sharedState: import("@atlaskit/editor-plugin-editor-disabled").EditorDisabledPluginState;
|
|
28
|
+
}, undefined>];
|
|
29
|
+
sharedState: import("./types").DatePluginSharedState;
|
|
30
|
+
commands: {
|
|
31
|
+
insertDate: import("./types").InsertDate;
|
|
32
|
+
deleteDate: import("@atlaskit/editor-common/types").EditorCommand;
|
|
33
|
+
};
|
|
34
|
+
}, import("./types").DatePluginConfig | undefined>, import("@atlaskit/editor-common/types").NextEditorPluginFunctionOptionalConfigDefinition<"analytics", {
|
|
35
|
+
pluginConfiguration: import("@atlaskit/editor-plugin-analytics").AnalyticsPluginOptions;
|
|
36
|
+
sharedState: {
|
|
37
|
+
createAnalyticsEvent: import("@atlaskit/analytics-next").CreateUIAnalyticsEvent | null;
|
|
38
|
+
attachAnalyticsEvent: import("@atlaskit/editor-plugin-analytics").CreateAttachPayloadIntoTransaction | null;
|
|
39
|
+
};
|
|
40
|
+
dependencies: [import("@atlaskit/editor-common/types").NextEditorPluginFunctionOptionalConfigDefinition<"featureFlags", {
|
|
41
|
+
pluginConfiguration: import("@atlaskit/editor-common/types").FeatureFlags;
|
|
42
|
+
sharedState: import("@atlaskit/editor-common/types").FeatureFlags;
|
|
43
|
+
}, import("@atlaskit/editor-common/types").FeatureFlags>];
|
|
44
|
+
actions: import("@atlaskit/editor-common/analytics").EditorAnalyticsAPI;
|
|
45
|
+
}, import("@atlaskit/editor-plugin-analytics").AnalyticsPluginOptions>, import("@atlaskit/editor-common/types").NextEditorPluginFunctionOptionalConfigDefinition<"editorDisabled", {
|
|
46
|
+
sharedState: import("@atlaskit/editor-plugin-editor-disabled").EditorDisabledPluginState;
|
|
47
|
+
}, undefined>]> | undefined;
|
|
48
|
+
}) => Command;
|
|
49
|
+
export declare const openDatePicker: () => Command;
|
package/dist/types/commands.d.ts
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type {
|
|
3
|
-
import type {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
1
|
+
import type { OptionalPlugin, PluginInjectionAPIWithDependencies } from '@atlaskit/editor-common/types';
|
|
2
|
+
import type { AnalyticsPlugin } from '@atlaskit/editor-plugin-analytics';
|
|
3
|
+
import type { DatePlugin, DeleteDate, InsertDate } from './types';
|
|
4
|
+
type DeleteDateCommand = (pluginInjectionApi: PluginInjectionAPIWithDependencies<[DatePlugin]> | undefined) => DeleteDate;
|
|
5
|
+
/** Delete the date and close the datepicker */
|
|
6
|
+
export declare const deleteDateCommand: DeleteDateCommand;
|
|
7
|
+
type InsertDateCommand = (pluginInjectionApi: PluginInjectionAPIWithDependencies<[
|
|
8
|
+
OptionalPlugin<AnalyticsPlugin>,
|
|
9
|
+
DatePlugin
|
|
10
|
+
]> | undefined) => InsertDate;
|
|
11
|
+
export declare const insertDateCommand: InsertDateCommand;
|
|
12
|
+
export {};
|
package/dist/types/index.d.ts
CHANGED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { PMPluginFactory } from '@atlaskit/editor-common/types';
|
|
2
|
+
import type { DatePluginState } from './types';
|
|
3
|
+
declare const getPluginState: (state: import("prosemirror-state").EditorState) => DatePluginState;
|
|
4
|
+
declare const createPlugin: PMPluginFactory;
|
|
5
|
+
export { getPluginState };
|
|
6
|
+
export default createPlugin;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export type DatePluginState = {
|
|
2
|
+
isQuickInsertAction?: boolean;
|
|
3
|
+
isNew: boolean;
|
|
4
|
+
showDatePickerAt: number | null;
|
|
5
|
+
isDateEmpty: boolean;
|
|
6
|
+
focusDateInput: boolean;
|
|
7
|
+
};
|
|
8
|
+
export type DatePluginMeta = {
|
|
9
|
+
isNew?: boolean;
|
|
10
|
+
showDatePickerAt?: number | null;
|
|
11
|
+
isDateEmpty?: boolean;
|
|
12
|
+
};
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { ReadonlyTransaction } from '@atlaskit/editor-prosemirror/state';
|
|
2
|
+
import type { DatePluginMeta, DatePluginState } from './types';
|
|
3
|
+
export declare function reducer(pluginState: DatePluginState, meta: DatePluginMeta): DatePluginState;
|
|
4
|
+
export declare function mapping(tr: ReadonlyTransaction, pluginState: DatePluginState): DatePluginState;
|
|
5
|
+
export declare function onSelectionChanged(tr: ReadonlyTransaction, pluginState: DatePluginState): DatePluginState;
|
package/dist/types/types.d.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import type { WeekDay } from '@atlaskit/calendar/types';
|
|
2
|
-
import type {
|
|
2
|
+
import type { INPUT_METHOD } from '@atlaskit/editor-common/analytics';
|
|
3
|
+
import type { EditorCommand, NextEditorPlugin, TOOLBAR_MENU_TYPE } from '@atlaskit/editor-common/types';
|
|
3
4
|
import type { analyticsPlugin } from '@atlaskit/editor-plugin-analytics';
|
|
4
5
|
import type { EditorDisabledPlugin } from '@atlaskit/editor-plugin-editor-disabled';
|
|
5
|
-
|
|
6
|
+
export type DateSegment = 'day' | 'month' | 'year';
|
|
6
7
|
export type DateType = {
|
|
7
8
|
year: number;
|
|
8
9
|
month: number;
|
|
@@ -16,6 +17,13 @@ export type DatePluginSharedState = {
|
|
|
16
17
|
isNew: boolean;
|
|
17
18
|
focusDateInput: boolean;
|
|
18
19
|
};
|
|
20
|
+
export type InsertDate = (props: {
|
|
21
|
+
date?: DateType;
|
|
22
|
+
inputMethod?: TOOLBAR_MENU_TYPE;
|
|
23
|
+
commitMethod?: INPUT_METHOD.PICKER | INPUT_METHOD.KEYBOARD;
|
|
24
|
+
enterPressed?: boolean;
|
|
25
|
+
}) => EditorCommand;
|
|
26
|
+
export type DeleteDate = EditorCommand;
|
|
19
27
|
export type DatePlugin = NextEditorPlugin<'date', {
|
|
20
28
|
pluginConfiguration: DatePluginConfig | undefined;
|
|
21
29
|
dependencies: [typeof analyticsPlugin, EditorDisabledPlugin];
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/** @jsx jsx */
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import type { WrappedComponentProps } from 'react-intl-next';
|
|
4
|
+
import type { DispatchAnalyticsEvent } from '@atlaskit/editor-common/analytics';
|
|
5
|
+
import type { DateType } from '../../types';
|
|
6
|
+
export interface InputProps {
|
|
7
|
+
/** Locale code string (eg. "en-AU") */
|
|
8
|
+
locale: string;
|
|
9
|
+
date: DateType;
|
|
10
|
+
dispatchAnalyticsEvent?: DispatchAnalyticsEvent;
|
|
11
|
+
onNewDate: (date: DateType) => void;
|
|
12
|
+
onSubmitDate: (date: DateType | null) => void;
|
|
13
|
+
onEmptySubmit: () => void;
|
|
14
|
+
/** Automatically focus the text field */
|
|
15
|
+
autoFocus?: boolean;
|
|
16
|
+
/** Automatically select all text in the field. Requires autoFocus to be true. */
|
|
17
|
+
autoSelectAll?: boolean;
|
|
18
|
+
}
|
|
19
|
+
export interface InputState {
|
|
20
|
+
inputText: string;
|
|
21
|
+
}
|
|
22
|
+
declare const _default: React.FC<import("react-intl-next").WithIntlProps<InputProps & WrappedComponentProps<"intl">>> & {
|
|
23
|
+
WrappedComponent: React.ComponentType<InputProps & WrappedComponentProps<"intl">>;
|
|
24
|
+
};
|
|
25
|
+
export default _default;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/** @jsx jsx */
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import type { WrappedComponentProps } from 'react-intl-next';
|
|
4
|
+
import type { WeekDay } from '@atlaskit/calendar/types';
|
|
5
|
+
import { INPUT_METHOD } from '@atlaskit/editor-common/analytics';
|
|
6
|
+
import type { DispatchAnalyticsEvent } from '@atlaskit/editor-common/analytics';
|
|
7
|
+
import type { DateType } from '../../types';
|
|
8
|
+
export interface Props {
|
|
9
|
+
element: HTMLElement | null;
|
|
10
|
+
closeDatePicker: () => void;
|
|
11
|
+
/** Whether the date is newly created, selcting and focusing the input */
|
|
12
|
+
isNew: boolean;
|
|
13
|
+
/** Whether to automatically focus the input */
|
|
14
|
+
autoFocus?: boolean;
|
|
15
|
+
onSelect: (date: DateType | null, commitMethod: INPUT_METHOD.PICKER | INPUT_METHOD.KEYBOARD) => void;
|
|
16
|
+
onDelete: () => void;
|
|
17
|
+
mountTo?: HTMLElement;
|
|
18
|
+
boundariesElement?: HTMLElement;
|
|
19
|
+
scrollableElement?: HTMLElement;
|
|
20
|
+
closeDatePickerWithAnalytics: ({ date }: {
|
|
21
|
+
date?: DateType;
|
|
22
|
+
}) => void;
|
|
23
|
+
onTextChanged: (date: DateType) => void;
|
|
24
|
+
dispatchAnalyticsEvent?: DispatchAnalyticsEvent;
|
|
25
|
+
weekStartDay?: WeekDay;
|
|
26
|
+
}
|
|
27
|
+
export interface State {
|
|
28
|
+
date: DateType;
|
|
29
|
+
selected: Array<string>;
|
|
30
|
+
setInputSelectionPos?: number;
|
|
31
|
+
latestValidDate: DateType;
|
|
32
|
+
}
|
|
33
|
+
declare const _default: React.FC<import("react-intl-next").WithIntlProps<Props & WrappedComponentProps<"intl">>> & {
|
|
34
|
+
WrappedComponent: React.ComponentType<Props & WrappedComponentProps<"intl">>;
|
|
35
|
+
};
|
|
36
|
+
export default _default;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { DateType } from '../types';
|
|
2
|
+
/**
|
|
3
|
+
* Attempt to parse a string representing a date in a particular locale to a date object
|
|
4
|
+
* @param dateString The string representing the date in the given locale, eg '02/12/2000'
|
|
5
|
+
* @param l10n The localisation provider created by createLocalizationProvider
|
|
6
|
+
* @returns Editor DateType when can parse, null when can't parse or invalid
|
|
7
|
+
*/
|
|
8
|
+
export declare function parseDateType(dateString: string, locale: string): DateType | null;
|
|
9
|
+
/**
|
|
10
|
+
* Convert an EditorDateType to a date string string formatted for a particular locale
|
|
11
|
+
* @param date The date object
|
|
12
|
+
* @param locale The locale code string (eg. "en-AU")
|
|
13
|
+
* @returns Date string, eg "25/5/20"
|
|
14
|
+
*/
|
|
15
|
+
export declare function formatDateType(date: DateType, locale: string): string;
|
|
16
|
+
/**
|
|
17
|
+
* Convert an Editor DateType to a JavaScript Date object
|
|
18
|
+
* @param date Editor DateType
|
|
19
|
+
* @returns JavaScript Date object
|
|
20
|
+
*/
|
|
21
|
+
export declare function dateTypeToDate(date: DateType): Date;
|
|
22
|
+
/**
|
|
23
|
+
* Convert a JavaScript Date to an editor DateType
|
|
24
|
+
* @param date JavaScript Date object
|
|
25
|
+
* @returns Editor DateType
|
|
26
|
+
*/
|
|
27
|
+
export declare function dateToDateType(date: Date): DateType;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { DateSegment, DateType } from '../types';
|
|
2
|
+
/**
|
|
3
|
+
* Inconclusively check if a date string is valid - a value of false means it is definitely
|
|
4
|
+
* invalid, a value of true means it might be valid.
|
|
5
|
+
* @param date Date string to be parsed
|
|
6
|
+
*/
|
|
7
|
+
export declare function isDatePossiblyValid(date: string): boolean;
|
|
8
|
+
/**
|
|
9
|
+
* Find the segment of a date a position refers to. Eg: pos 2 in 29/03/2020 is in
|
|
10
|
+
* the day segment.
|
|
11
|
+
* @param position Cursor position, with 0 referring to the left of the first char
|
|
12
|
+
* @param date The localised date string
|
|
13
|
+
* @param locale The language to interpret the date string in
|
|
14
|
+
*/
|
|
15
|
+
export declare function findDateSegmentByPosition(position: number, date: string, locale: string): DateSegment | undefined;
|
|
16
|
+
/**
|
|
17
|
+
* Generate a placeholder date string for a given locale
|
|
18
|
+
* eg: locale 'hu-HU' -> 'yyyy. mm. dd.'
|
|
19
|
+
* @param locale A locale string supported by Intl.DateTimeFormat
|
|
20
|
+
* @returns A placeholder string. d=1 or 2 digit day, dd=zero padded
|
|
21
|
+
* day, same for month but letter m, yyyy=year
|
|
22
|
+
*/
|
|
23
|
+
export declare function getLocaleDatePlaceholder(locale: string): string | undefined;
|
|
24
|
+
/**
|
|
25
|
+
* Adjust date segment up or down. Eg. If day is the active segment and adjustment is -1,
|
|
26
|
+
* reduce the day by one.
|
|
27
|
+
* @param date Valid datetype
|
|
28
|
+
* @param activeSegment which part of the date is selected/being adjusted
|
|
29
|
+
* @param adjustment how many units the segment is being adjusted (can be pos or neg, usually 1 or -1)
|
|
30
|
+
*/
|
|
31
|
+
export declare function adjustDate(date: DateType, activeSegment: DateSegment, adjustment: number): DateType;
|
|
32
|
+
export declare function isToday(date: DateType | undefined): boolean;
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import type { Command, CommandDispatch, ExtractInjectionAPI } from '@atlaskit/editor-common/types';
|
|
2
|
+
import type { EditorState, Transaction } from '@atlaskit/editor-prosemirror/state';
|
|
3
|
+
import type { DatePlugin, DateType } from './types';
|
|
4
|
+
export declare const createDate: (isQuickInsertAction?: boolean) => (insert: (node: Node | Object | string, opts?: {
|
|
5
|
+
selectInlineNode: boolean;
|
|
6
|
+
}) => Transaction, state: EditorState) => Transaction;
|
|
7
|
+
/** Focus input */
|
|
8
|
+
export declare const focusDateInput: () => (state: EditorState, dispatch: CommandDispatch | undefined) => boolean;
|
|
9
|
+
export declare const setDatePickerAt: (showDatePickerAt: number | null) => (state: EditorState, dispatch: (tr: Transaction) => void) => boolean;
|
|
10
|
+
export declare const closeDatePicker: () => Command;
|
|
11
|
+
export declare const closeDatePickerWithAnalytics: ({ date, pluginInjectionApi, }: {
|
|
12
|
+
date?: DateType | undefined;
|
|
13
|
+
pluginInjectionApi?: import("@atlaskit/editor-common/types").PublicPluginAPI<[
|
|
14
|
+
import("@atlaskit/editor-common/types").NextEditorPluginFunctionOptionalConfigDefinition<"date", {
|
|
15
|
+
pluginConfiguration: import("./types").DatePluginConfig | undefined;
|
|
16
|
+
dependencies: [
|
|
17
|
+
import("@atlaskit/editor-common/types").NextEditorPluginFunctionOptionalConfigDefinition<"analytics", {
|
|
18
|
+
pluginConfiguration: import("@atlaskit/editor-plugin-analytics").AnalyticsPluginOptions;
|
|
19
|
+
sharedState: {
|
|
20
|
+
createAnalyticsEvent: import("@atlaskit/analytics-next").CreateUIAnalyticsEvent | null;
|
|
21
|
+
attachAnalyticsEvent: import("@atlaskit/editor-plugin-analytics").CreateAttachPayloadIntoTransaction | null;
|
|
22
|
+
};
|
|
23
|
+
dependencies: [
|
|
24
|
+
import("@atlaskit/editor-common/types").NextEditorPluginFunctionOptionalConfigDefinition<"featureFlags", {
|
|
25
|
+
pluginConfiguration: import("@atlaskit/editor-common/types").FeatureFlags;
|
|
26
|
+
sharedState: import("@atlaskit/editor-common/types").FeatureFlags;
|
|
27
|
+
}, import("@atlaskit/editor-common/types").FeatureFlags>
|
|
28
|
+
];
|
|
29
|
+
actions: import("@atlaskit/editor-common/analytics").EditorAnalyticsAPI;
|
|
30
|
+
}, import("@atlaskit/editor-plugin-analytics").AnalyticsPluginOptions>,
|
|
31
|
+
import("@atlaskit/editor-common/types").NextEditorPluginFunctionOptionalConfigDefinition<"editorDisabled", {
|
|
32
|
+
sharedState: import("@atlaskit/editor-plugin-editor-disabled").EditorDisabledPluginState;
|
|
33
|
+
}, undefined>
|
|
34
|
+
];
|
|
35
|
+
sharedState: import("./types").DatePluginSharedState;
|
|
36
|
+
commands: {
|
|
37
|
+
insertDate: import("./types").InsertDate;
|
|
38
|
+
deleteDate: import("@atlaskit/editor-common/types").EditorCommand;
|
|
39
|
+
};
|
|
40
|
+
}, import("./types").DatePluginConfig | undefined>,
|
|
41
|
+
import("@atlaskit/editor-common/types").NextEditorPluginFunctionOptionalConfigDefinition<"analytics", {
|
|
42
|
+
pluginConfiguration: import("@atlaskit/editor-plugin-analytics").AnalyticsPluginOptions;
|
|
43
|
+
sharedState: {
|
|
44
|
+
createAnalyticsEvent: import("@atlaskit/analytics-next").CreateUIAnalyticsEvent | null;
|
|
45
|
+
attachAnalyticsEvent: import("@atlaskit/editor-plugin-analytics").CreateAttachPayloadIntoTransaction | null;
|
|
46
|
+
};
|
|
47
|
+
dependencies: [
|
|
48
|
+
import("@atlaskit/editor-common/types").NextEditorPluginFunctionOptionalConfigDefinition<"featureFlags", {
|
|
49
|
+
pluginConfiguration: import("@atlaskit/editor-common/types").FeatureFlags;
|
|
50
|
+
sharedState: import("@atlaskit/editor-common/types").FeatureFlags;
|
|
51
|
+
}, import("@atlaskit/editor-common/types").FeatureFlags>
|
|
52
|
+
];
|
|
53
|
+
actions: import("@atlaskit/editor-common/analytics").EditorAnalyticsAPI;
|
|
54
|
+
}, import("@atlaskit/editor-plugin-analytics").AnalyticsPluginOptions>,
|
|
55
|
+
import("@atlaskit/editor-common/types").NextEditorPluginFunctionOptionalConfigDefinition<"editorDisabled", {
|
|
56
|
+
sharedState: import("@atlaskit/editor-plugin-editor-disabled").EditorDisabledPluginState;
|
|
57
|
+
}, undefined>
|
|
58
|
+
]> | undefined;
|
|
59
|
+
}) => Command;
|
|
60
|
+
export declare const openDatePicker: () => Command;
|
|
@@ -1,10 +1,14 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type {
|
|
3
|
-
import type {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
1
|
+
import type { OptionalPlugin, PluginInjectionAPIWithDependencies } from '@atlaskit/editor-common/types';
|
|
2
|
+
import type { AnalyticsPlugin } from '@atlaskit/editor-plugin-analytics';
|
|
3
|
+
import type { DatePlugin, DeleteDate, InsertDate } from './types';
|
|
4
|
+
type DeleteDateCommand = (pluginInjectionApi: PluginInjectionAPIWithDependencies<[
|
|
5
|
+
DatePlugin
|
|
6
|
+
]> | undefined) => DeleteDate;
|
|
7
|
+
/** Delete the date and close the datepicker */
|
|
8
|
+
export declare const deleteDateCommand: DeleteDateCommand;
|
|
9
|
+
type InsertDateCommand = (pluginInjectionApi: PluginInjectionAPIWithDependencies<[
|
|
10
|
+
OptionalPlugin<AnalyticsPlugin>,
|
|
11
|
+
DatePlugin
|
|
12
|
+
]> | undefined) => InsertDate;
|
|
13
|
+
export declare const insertDateCommand: InsertDateCommand;
|
|
14
|
+
export {};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { PMPluginFactory } from '@atlaskit/editor-common/types';
|
|
2
|
+
import type { DatePluginState } from './types';
|
|
3
|
+
declare const getPluginState: (state: import("prosemirror-state").EditorState) => DatePluginState;
|
|
4
|
+
declare const createPlugin: PMPluginFactory;
|
|
5
|
+
export { getPluginState };
|
|
6
|
+
export default createPlugin;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export type DatePluginState = {
|
|
2
|
+
isQuickInsertAction?: boolean;
|
|
3
|
+
isNew: boolean;
|
|
4
|
+
showDatePickerAt: number | null;
|
|
5
|
+
isDateEmpty: boolean;
|
|
6
|
+
focusDateInput: boolean;
|
|
7
|
+
};
|
|
8
|
+
export type DatePluginMeta = {
|
|
9
|
+
isNew?: boolean;
|
|
10
|
+
showDatePickerAt?: number | null;
|
|
11
|
+
isDateEmpty?: boolean;
|
|
12
|
+
};
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { ReadonlyTransaction } from '@atlaskit/editor-prosemirror/state';
|
|
2
|
+
import type { DatePluginMeta, DatePluginState } from './types';
|
|
3
|
+
export declare function reducer(pluginState: DatePluginState, meta: DatePluginMeta): DatePluginState;
|
|
4
|
+
export declare function mapping(tr: ReadonlyTransaction, pluginState: DatePluginState): DatePluginState;
|
|
5
|
+
export declare function onSelectionChanged(tr: ReadonlyTransaction, pluginState: DatePluginState): DatePluginState;
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import type { WeekDay } from '@atlaskit/calendar/types';
|
|
2
|
-
import type {
|
|
2
|
+
import type { INPUT_METHOD } from '@atlaskit/editor-common/analytics';
|
|
3
|
+
import type { EditorCommand, NextEditorPlugin, TOOLBAR_MENU_TYPE } from '@atlaskit/editor-common/types';
|
|
3
4
|
import type { analyticsPlugin } from '@atlaskit/editor-plugin-analytics';
|
|
4
5
|
import type { EditorDisabledPlugin } from '@atlaskit/editor-plugin-editor-disabled';
|
|
5
|
-
|
|
6
|
+
export type DateSegment = 'day' | 'month' | 'year';
|
|
6
7
|
export type DateType = {
|
|
7
8
|
year: number;
|
|
8
9
|
month: number;
|
|
@@ -16,6 +17,13 @@ export type DatePluginSharedState = {
|
|
|
16
17
|
isNew: boolean;
|
|
17
18
|
focusDateInput: boolean;
|
|
18
19
|
};
|
|
20
|
+
export type InsertDate = (props: {
|
|
21
|
+
date?: DateType;
|
|
22
|
+
inputMethod?: TOOLBAR_MENU_TYPE;
|
|
23
|
+
commitMethod?: INPUT_METHOD.PICKER | INPUT_METHOD.KEYBOARD;
|
|
24
|
+
enterPressed?: boolean;
|
|
25
|
+
}) => EditorCommand;
|
|
26
|
+
export type DeleteDate = EditorCommand;
|
|
19
27
|
export type DatePlugin = NextEditorPlugin<'date', {
|
|
20
28
|
pluginConfiguration: DatePluginConfig | undefined;
|
|
21
29
|
dependencies: [
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/** @jsx jsx */
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import type { WrappedComponentProps } from 'react-intl-next';
|
|
4
|
+
import type { DispatchAnalyticsEvent } from '@atlaskit/editor-common/analytics';
|
|
5
|
+
import type { DateType } from '../../types';
|
|
6
|
+
export interface InputProps {
|
|
7
|
+
/** Locale code string (eg. "en-AU") */
|
|
8
|
+
locale: string;
|
|
9
|
+
date: DateType;
|
|
10
|
+
dispatchAnalyticsEvent?: DispatchAnalyticsEvent;
|
|
11
|
+
onNewDate: (date: DateType) => void;
|
|
12
|
+
onSubmitDate: (date: DateType | null) => void;
|
|
13
|
+
onEmptySubmit: () => void;
|
|
14
|
+
/** Automatically focus the text field */
|
|
15
|
+
autoFocus?: boolean;
|
|
16
|
+
/** Automatically select all text in the field. Requires autoFocus to be true. */
|
|
17
|
+
autoSelectAll?: boolean;
|
|
18
|
+
}
|
|
19
|
+
export interface InputState {
|
|
20
|
+
inputText: string;
|
|
21
|
+
}
|
|
22
|
+
declare const _default: React.FC<import("react-intl-next").WithIntlProps<InputProps & WrappedComponentProps<"intl">>> & {
|
|
23
|
+
WrappedComponent: React.ComponentType<InputProps & WrappedComponentProps<"intl">>;
|
|
24
|
+
};
|
|
25
|
+
export default _default;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/** @jsx jsx */
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import type { WrappedComponentProps } from 'react-intl-next';
|
|
4
|
+
import type { WeekDay } from '@atlaskit/calendar/types';
|
|
5
|
+
import { INPUT_METHOD } from '@atlaskit/editor-common/analytics';
|
|
6
|
+
import type { DispatchAnalyticsEvent } from '@atlaskit/editor-common/analytics';
|
|
7
|
+
import type { DateType } from '../../types';
|
|
8
|
+
export interface Props {
|
|
9
|
+
element: HTMLElement | null;
|
|
10
|
+
closeDatePicker: () => void;
|
|
11
|
+
/** Whether the date is newly created, selcting and focusing the input */
|
|
12
|
+
isNew: boolean;
|
|
13
|
+
/** Whether to automatically focus the input */
|
|
14
|
+
autoFocus?: boolean;
|
|
15
|
+
onSelect: (date: DateType | null, commitMethod: INPUT_METHOD.PICKER | INPUT_METHOD.KEYBOARD) => void;
|
|
16
|
+
onDelete: () => void;
|
|
17
|
+
mountTo?: HTMLElement;
|
|
18
|
+
boundariesElement?: HTMLElement;
|
|
19
|
+
scrollableElement?: HTMLElement;
|
|
20
|
+
closeDatePickerWithAnalytics: ({ date }: {
|
|
21
|
+
date?: DateType;
|
|
22
|
+
}) => void;
|
|
23
|
+
onTextChanged: (date: DateType) => void;
|
|
24
|
+
dispatchAnalyticsEvent?: DispatchAnalyticsEvent;
|
|
25
|
+
weekStartDay?: WeekDay;
|
|
26
|
+
}
|
|
27
|
+
export interface State {
|
|
28
|
+
date: DateType;
|
|
29
|
+
selected: Array<string>;
|
|
30
|
+
setInputSelectionPos?: number;
|
|
31
|
+
latestValidDate: DateType;
|
|
32
|
+
}
|
|
33
|
+
declare const _default: React.FC<import("react-intl-next").WithIntlProps<Props & WrappedComponentProps<"intl">>> & {
|
|
34
|
+
WrappedComponent: React.ComponentType<Props & WrappedComponentProps<"intl">>;
|
|
35
|
+
};
|
|
36
|
+
export default _default;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { DateType } from '../types';
|
|
2
|
+
/**
|
|
3
|
+
* Attempt to parse a string representing a date in a particular locale to a date object
|
|
4
|
+
* @param dateString The string representing the date in the given locale, eg '02/12/2000'
|
|
5
|
+
* @param l10n The localisation provider created by createLocalizationProvider
|
|
6
|
+
* @returns Editor DateType when can parse, null when can't parse or invalid
|
|
7
|
+
*/
|
|
8
|
+
export declare function parseDateType(dateString: string, locale: string): DateType | null;
|
|
9
|
+
/**
|
|
10
|
+
* Convert an EditorDateType to a date string string formatted for a particular locale
|
|
11
|
+
* @param date The date object
|
|
12
|
+
* @param locale The locale code string (eg. "en-AU")
|
|
13
|
+
* @returns Date string, eg "25/5/20"
|
|
14
|
+
*/
|
|
15
|
+
export declare function formatDateType(date: DateType, locale: string): string;
|
|
16
|
+
/**
|
|
17
|
+
* Convert an Editor DateType to a JavaScript Date object
|
|
18
|
+
* @param date Editor DateType
|
|
19
|
+
* @returns JavaScript Date object
|
|
20
|
+
*/
|
|
21
|
+
export declare function dateTypeToDate(date: DateType): Date;
|
|
22
|
+
/**
|
|
23
|
+
* Convert a JavaScript Date to an editor DateType
|
|
24
|
+
* @param date JavaScript Date object
|
|
25
|
+
* @returns Editor DateType
|
|
26
|
+
*/
|
|
27
|
+
export declare function dateToDateType(date: Date): DateType;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { DateSegment, DateType } from '../types';
|
|
2
|
+
/**
|
|
3
|
+
* Inconclusively check if a date string is valid - a value of false means it is definitely
|
|
4
|
+
* invalid, a value of true means it might be valid.
|
|
5
|
+
* @param date Date string to be parsed
|
|
6
|
+
*/
|
|
7
|
+
export declare function isDatePossiblyValid(date: string): boolean;
|
|
8
|
+
/**
|
|
9
|
+
* Find the segment of a date a position refers to. Eg: pos 2 in 29/03/2020 is in
|
|
10
|
+
* the day segment.
|
|
11
|
+
* @param position Cursor position, with 0 referring to the left of the first char
|
|
12
|
+
* @param date The localised date string
|
|
13
|
+
* @param locale The language to interpret the date string in
|
|
14
|
+
*/
|
|
15
|
+
export declare function findDateSegmentByPosition(position: number, date: string, locale: string): DateSegment | undefined;
|
|
16
|
+
/**
|
|
17
|
+
* Generate a placeholder date string for a given locale
|
|
18
|
+
* eg: locale 'hu-HU' -> 'yyyy. mm. dd.'
|
|
19
|
+
* @param locale A locale string supported by Intl.DateTimeFormat
|
|
20
|
+
* @returns A placeholder string. d=1 or 2 digit day, dd=zero padded
|
|
21
|
+
* day, same for month but letter m, yyyy=year
|
|
22
|
+
*/
|
|
23
|
+
export declare function getLocaleDatePlaceholder(locale: string): string | undefined;
|
|
24
|
+
/**
|
|
25
|
+
* Adjust date segment up or down. Eg. If day is the active segment and adjustment is -1,
|
|
26
|
+
* reduce the day by one.
|
|
27
|
+
* @param date Valid datetype
|
|
28
|
+
* @param activeSegment which part of the date is selected/being adjusted
|
|
29
|
+
* @param adjustment how many units the segment is being adjusted (can be pos or neg, usually 1 or -1)
|
|
30
|
+
*/
|
|
31
|
+
export declare function adjustDate(date: DateType, activeSegment: DateSegment, adjustment: number): DateType;
|
|
32
|
+
export declare function isToday(date: DateType | undefined): boolean;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atlaskit/editor-plugin-date",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "Date plugin for @atlaskit/editor-core",
|
|
5
5
|
"author": "Atlassian Pty Ltd",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -31,14 +31,39 @@
|
|
|
31
31
|
".": "./src/index.ts"
|
|
32
32
|
},
|
|
33
33
|
"dependencies": {
|
|
34
|
+
"@atlaskit/adf-schema": "^32.0.0",
|
|
34
35
|
"@atlaskit/calendar": "^13.3.0",
|
|
35
|
-
"@atlaskit/
|
|
36
|
+
"@atlaskit/date": "^0.10.0",
|
|
37
|
+
"@atlaskit/editor-common": "^76.12.0",
|
|
36
38
|
"@atlaskit/editor-plugin-analytics": "^0.2.0",
|
|
37
39
|
"@atlaskit/editor-plugin-editor-disabled": "^0.2.0",
|
|
38
|
-
"@
|
|
40
|
+
"@atlaskit/editor-prosemirror": "1.1.0",
|
|
41
|
+
"@atlaskit/editor-shared-styles": "^2.8.0",
|
|
42
|
+
"@atlaskit/form": "^8.11.0",
|
|
43
|
+
"@atlaskit/locale": "^2.5.0",
|
|
44
|
+
"@atlaskit/textfield": "5.6.8",
|
|
45
|
+
"@atlaskit/theme": "^12.6.0",
|
|
46
|
+
"@atlaskit/tokens": "^1.26.0",
|
|
47
|
+
"@babel/runtime": "^7.0.0",
|
|
48
|
+
"@emotion/react": "^11.7.1",
|
|
49
|
+
"date-fns": "^2.17.0",
|
|
50
|
+
"react-dom": "^16.8.0",
|
|
51
|
+
"react-intl-next": "npm:react-intl@^5.18.1",
|
|
52
|
+
"react-loadable": "^5.1.0"
|
|
39
53
|
},
|
|
40
54
|
"devDependencies": {
|
|
41
|
-
"@
|
|
55
|
+
"@atlaskit/editor-plugin-composition": "^0.1.0",
|
|
56
|
+
"@atlaskit/editor-plugin-content-insertion": "^0.1.0",
|
|
57
|
+
"@atlaskit/editor-plugin-decorations": "^0.2.0",
|
|
58
|
+
"@atlaskit/editor-plugin-feature-flags": "^1.0.0",
|
|
59
|
+
"@atlaskit/editor-plugin-guideline": "^0.5.0",
|
|
60
|
+
"@atlaskit/editor-plugin-quick-insert": "^0.2.0",
|
|
61
|
+
"@atlaskit/editor-plugin-selection": "^0.1.0",
|
|
62
|
+
"@atlaskit/editor-plugin-table": "^5.2.0",
|
|
63
|
+
"@atlaskit/editor-plugin-type-ahead": "^0.7.0",
|
|
64
|
+
"@atlaskit/editor-plugin-width": "^0.2.0",
|
|
65
|
+
"@atlassian/atlassian-frontend-prettier-config-1.0.0": "npm:@atlassian/atlassian-frontend-prettier-config@1.0.0",
|
|
66
|
+
"@testing-library/react": "^12.1.5"
|
|
42
67
|
},
|
|
43
68
|
"peerDependencies": {
|
|
44
69
|
"react": "^16.8.0"
|