@atlaskit/editor-plugin-metrics 3.1.1 → 3.2.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/CHANGELOG.md +21 -0
- package/dist/cjs/metricsPlugin.js +48 -5
- package/dist/cjs/pm-plugins/main.js +93 -39
- package/dist/cjs/pm-plugins/utils/check-tr-action-type.js +159 -0
- package/dist/es2019/metricsPlugin.js +45 -4
- package/dist/es2019/pm-plugins/main.js +94 -36
- package/dist/es2019/pm-plugins/utils/check-tr-action-type.js +152 -0
- package/dist/esm/metricsPlugin.js +48 -5
- package/dist/esm/pm-plugins/main.js +93 -39
- package/dist/esm/pm-plugins/utils/check-tr-action-type.js +152 -0
- package/dist/types/metricsPluginType.d.ts +12 -2
- package/dist/types/pm-plugins/main.d.ts +3 -0
- package/dist/types/pm-plugins/utils/check-tr-action-type.d.ts +18 -0
- package/dist/types/pm-plugins/utils/get-node-changes.d.ts +1 -1
- package/dist/types/pm-plugins/utils/is-non-text-undo.d.ts +1 -1
- package/dist/types-ts4.5/metricsPluginType.d.ts +13 -2
- package/dist/types-ts4.5/pm-plugins/main.d.ts +3 -0
- package/dist/types-ts4.5/pm-plugins/utils/check-tr-action-type.d.ts +18 -0
- package/dist/types-ts4.5/pm-plugins/utils/get-node-changes.d.ts +1 -1
- package/dist/types-ts4.5/pm-plugins/utils/is-non-text-undo.d.ts +1 -1
- package/package.json +4 -3
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
|
|
2
|
+
import { InsertTypeAheadStep, LinkMetaStep } from '@atlaskit/adf-schema/steps';
|
|
3
|
+
import { ReplaceAroundStep, ReplaceStep } from '@atlaskit/editor-prosemirror/transform';
|
|
4
|
+
export var ActionType = /*#__PURE__*/function (ActionType) {
|
|
5
|
+
ActionType["TEXT_INPUT"] = "textInput";
|
|
6
|
+
ActionType["EMPTY_LINE_ADDED_OR_DELETED"] = "emptyLineAddedOrDeleted";
|
|
7
|
+
ActionType["INSERTED_FROM_TYPE_AHEAD"] = "insertedFromTypeAhead";
|
|
8
|
+
ActionType["INSERTING_NEW_LIST_TYPE_NODE"] = "insertingNewListTypeNode";
|
|
9
|
+
ActionType["UPDATING_NEW_LIST_TYPE_ITEM"] = "updatingNewListItem";
|
|
10
|
+
ActionType["ADDING_LINK"] = "addingLink";
|
|
11
|
+
ActionType["UPDATING_STATUS"] = "updatingStatus";
|
|
12
|
+
return ActionType;
|
|
13
|
+
}({});
|
|
14
|
+
var isTextInput = function isTextInput(step) {
|
|
15
|
+
var _ref = step,
|
|
16
|
+
content = _ref.slice.content,
|
|
17
|
+
from = _ref.from,
|
|
18
|
+
to = _ref.to;
|
|
19
|
+
var node = content.firstChild;
|
|
20
|
+
var isAddingCharacter = from === to && content.childCount === 1 && !!node && !!node.text && node.text.length === 1;
|
|
21
|
+
var isDeletingCharacter = to - from === 1 && content.childCount === 0;
|
|
22
|
+
return isAddingCharacter || isDeletingCharacter;
|
|
23
|
+
};
|
|
24
|
+
var isEmptyLineAddedOrDeleted = function isEmptyLineAddedOrDeleted(step) {
|
|
25
|
+
var _ref2 = step,
|
|
26
|
+
content = _ref2.slice.content,
|
|
27
|
+
from = _ref2.from,
|
|
28
|
+
to = _ref2.to;
|
|
29
|
+
var isEmptyLineDeleted = to - from === 2 && content.size === 0;
|
|
30
|
+
if (isEmptyLineDeleted) {
|
|
31
|
+
return true;
|
|
32
|
+
}
|
|
33
|
+
var isEmptyLineAdded = false;
|
|
34
|
+
content.forEach(function (node) {
|
|
35
|
+
isEmptyLineAdded = node.type.name === 'paragraph' && node.content.size === 0;
|
|
36
|
+
});
|
|
37
|
+
return isEmptyLineAdded;
|
|
38
|
+
};
|
|
39
|
+
var isUpdatingListTypeNode = function isUpdatingListTypeNode(step) {
|
|
40
|
+
var slice = step.slice;
|
|
41
|
+
var childCount = slice.content.childCount;
|
|
42
|
+
if (childCount < 1) {
|
|
43
|
+
return false;
|
|
44
|
+
}
|
|
45
|
+
var isListTypeNode = false;
|
|
46
|
+
slice.content.forEach(function (node) {
|
|
47
|
+
isListTypeNode = ['decisionList', 'decisionItem', 'bulletList', 'listItem', 'orderedList', 'taskList', 'taskItem'].includes(node.type.name);
|
|
48
|
+
});
|
|
49
|
+
if (!isListTypeNode) {
|
|
50
|
+
return false;
|
|
51
|
+
}
|
|
52
|
+
return childCount === 1 ? ActionType.INSERTING_NEW_LIST_TYPE_NODE : ActionType.UPDATING_NEW_LIST_TYPE_ITEM;
|
|
53
|
+
};
|
|
54
|
+
var isUpdatingStatus = function isUpdatingStatus(step) {
|
|
55
|
+
var slice = step.slice;
|
|
56
|
+
var firstChild = slice.content.firstChild;
|
|
57
|
+
if (!firstChild) {
|
|
58
|
+
return undefined;
|
|
59
|
+
}
|
|
60
|
+
return firstChild.type.name === 'status' && firstChild.attrs.localId;
|
|
61
|
+
};
|
|
62
|
+
var isAddingLink = function isAddingLink(tr) {
|
|
63
|
+
var hasLinkStep = tr.steps.some(function (step) {
|
|
64
|
+
return step instanceof LinkMetaStep;
|
|
65
|
+
});
|
|
66
|
+
var hasReplaceStep = tr.steps.some(function (step) {
|
|
67
|
+
return step instanceof ReplaceStep;
|
|
68
|
+
});
|
|
69
|
+
return hasLinkStep && !hasReplaceStep;
|
|
70
|
+
};
|
|
71
|
+
var isTypeAheadRelatedTr = function isTypeAheadRelatedTr(tr) {
|
|
72
|
+
var _tr$getMeta;
|
|
73
|
+
if (((_tr$getMeta = tr.getMeta('typeAheadPlugin$')) === null || _tr$getMeta === void 0 ? void 0 : _tr$getMeta.action) === 'INSERT_RAW_QUERY') {
|
|
74
|
+
return 'INSERT_RAW_QUERY';
|
|
75
|
+
}
|
|
76
|
+
if (!tr.getMeta('appendedTransaction')) {
|
|
77
|
+
return false;
|
|
78
|
+
}
|
|
79
|
+
var insertTypeAheadStep = tr.steps.find(function (step) {
|
|
80
|
+
return step instanceof InsertTypeAheadStep;
|
|
81
|
+
});
|
|
82
|
+
var replaceStep = tr.steps.find(function (step) {
|
|
83
|
+
return step instanceof ReplaceStep;
|
|
84
|
+
});
|
|
85
|
+
if (!insertTypeAheadStep || !replaceStep) {
|
|
86
|
+
return false;
|
|
87
|
+
}
|
|
88
|
+
return insertTypeAheadStep instanceof InsertTypeAheadStep && insertTypeAheadStep.stage;
|
|
89
|
+
};
|
|
90
|
+
export var shouldSkipTr = function shouldSkipTr(tr) {
|
|
91
|
+
var resolvingLink = isAddingLink(tr);
|
|
92
|
+
if (resolvingLink) {
|
|
93
|
+
return true;
|
|
94
|
+
}
|
|
95
|
+
var typeAheadRelatedTr = isTypeAheadRelatedTr(tr);
|
|
96
|
+
if (typeAheadRelatedTr) {
|
|
97
|
+
return typeAheadRelatedTr !== 'INSERTING_ITEM';
|
|
98
|
+
} else {
|
|
99
|
+
return tr.getMeta('appendedTransaction');
|
|
100
|
+
}
|
|
101
|
+
};
|
|
102
|
+
export var checkTrActionType = function checkTrActionType(tr) {
|
|
103
|
+
if (tr.getMeta('input_rule_plugin_transaction')) {
|
|
104
|
+
return {
|
|
105
|
+
type: ActionType.INSERTING_NEW_LIST_TYPE_NODE
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
var stepsLength = tr.steps.length;
|
|
109
|
+
if (stepsLength <= 0) {
|
|
110
|
+
return undefined;
|
|
111
|
+
}
|
|
112
|
+
if (isAddingLink(tr)) {
|
|
113
|
+
return {
|
|
114
|
+
type: ActionType.ADDING_LINK
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
var _tr$steps = _slicedToArray(tr.steps, 1),
|
|
118
|
+
firstStep = _tr$steps[0];
|
|
119
|
+
var isReplaceStep = firstStep instanceof ReplaceStep;
|
|
120
|
+
var isReplaceAroundStep = firstStep instanceof ReplaceAroundStep;
|
|
121
|
+
if (!isReplaceStep && !isReplaceAroundStep) {
|
|
122
|
+
return undefined;
|
|
123
|
+
}
|
|
124
|
+
if (isReplaceStep) {
|
|
125
|
+
if (isTextInput(firstStep)) {
|
|
126
|
+
return {
|
|
127
|
+
type: ActionType.TEXT_INPUT
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
if (isEmptyLineAddedOrDeleted(firstStep)) {
|
|
131
|
+
return {
|
|
132
|
+
type: ActionType.EMPTY_LINE_ADDED_OR_DELETED
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
var statusId = isUpdatingStatus(firstStep);
|
|
136
|
+
if (statusId) {
|
|
137
|
+
return {
|
|
138
|
+
type: ActionType.UPDATING_STATUS,
|
|
139
|
+
extraData: {
|
|
140
|
+
statusId: statusId
|
|
141
|
+
}
|
|
142
|
+
};
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
var updatingListTypeNode = isUpdatingListTypeNode(firstStep);
|
|
146
|
+
if (updatingListTypeNode) {
|
|
147
|
+
return {
|
|
148
|
+
type: updatingListTypeNode
|
|
149
|
+
};
|
|
150
|
+
}
|
|
151
|
+
return undefined;
|
|
152
|
+
};
|
|
@@ -1,10 +1,20 @@
|
|
|
1
|
-
import type { EditorCommand, NextEditorPlugin } from '@atlaskit/editor-common/types';
|
|
1
|
+
import type { EditorCommand, NextEditorPlugin, OptionalPlugin } from '@atlaskit/editor-common/types';
|
|
2
2
|
import type { AnalyticsPlugin } from '@atlaskit/editor-plugin-analytics';
|
|
3
|
+
import type { BlockControlsPlugin } from '@atlaskit/editor-plugin-block-controls';
|
|
4
|
+
import type { Selection } from '@atlaskit/editor-prosemirror/state';
|
|
3
5
|
import type { MetricsState } from './pm-plugins/main';
|
|
6
|
+
type handleIntentToStartEditProps = {
|
|
7
|
+
newSelection?: Selection;
|
|
8
|
+
shouldStartTimer?: boolean;
|
|
9
|
+
shouldPersistActiveSession?: boolean;
|
|
10
|
+
};
|
|
4
11
|
export type MetricsPlugin = NextEditorPlugin<'metrics', {
|
|
5
|
-
dependencies: [AnalyticsPlugin];
|
|
12
|
+
dependencies: [AnalyticsPlugin, OptionalPlugin<BlockControlsPlugin>];
|
|
6
13
|
sharedState: MetricsState;
|
|
7
14
|
commands: {
|
|
15
|
+
startActiveSessionTimer: () => EditorCommand;
|
|
8
16
|
stopActiveSession: () => EditorCommand;
|
|
17
|
+
handleIntentToStartEdit: ({ newSelection, shouldStartTimer, shouldPersistActiveSession, }: handleIntentToStartEditProps) => EditorCommand;
|
|
9
18
|
};
|
|
10
19
|
}>;
|
|
20
|
+
export {};
|
|
@@ -3,6 +3,7 @@ import { type ExtractInjectionAPI } from '@atlaskit/editor-common/types';
|
|
|
3
3
|
import { Fragment } from '@atlaskit/editor-prosemirror/model';
|
|
4
4
|
import { PluginKey, Selection } from '@atlaskit/editor-prosemirror/state';
|
|
5
5
|
import { type MetricsPlugin } from '../metricsPluginType';
|
|
6
|
+
import { type TrActionType } from './utils/check-tr-action-type';
|
|
6
7
|
export declare const metricsKey: PluginKey<any>;
|
|
7
8
|
export type MetricsState = {
|
|
8
9
|
intentToStartEditTime?: number;
|
|
@@ -12,7 +13,9 @@ export type MetricsState = {
|
|
|
12
13
|
lastSelection?: Selection;
|
|
13
14
|
actionTypeCount: ActionByType;
|
|
14
15
|
timeOfLastTextInput?: number;
|
|
16
|
+
shouldPersistActiveSession?: boolean;
|
|
15
17
|
initialContent?: Fragment;
|
|
18
|
+
previousTrType?: TrActionType;
|
|
16
19
|
};
|
|
17
20
|
export type ActionByType = {
|
|
18
21
|
textInputCount: number;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { ReadonlyTransaction } from '@atlaskit/editor-prosemirror/state';
|
|
2
|
+
export declare enum ActionType {
|
|
3
|
+
TEXT_INPUT = "textInput",
|
|
4
|
+
EMPTY_LINE_ADDED_OR_DELETED = "emptyLineAddedOrDeleted",
|
|
5
|
+
INSERTED_FROM_TYPE_AHEAD = "insertedFromTypeAhead",
|
|
6
|
+
INSERTING_NEW_LIST_TYPE_NODE = "insertingNewListTypeNode",
|
|
7
|
+
UPDATING_NEW_LIST_TYPE_ITEM = "updatingNewListItem",
|
|
8
|
+
ADDING_LINK = "addingLink",
|
|
9
|
+
UPDATING_STATUS = "updatingStatus"
|
|
10
|
+
}
|
|
11
|
+
export declare const shouldSkipTr: (tr: ReadonlyTransaction) => boolean;
|
|
12
|
+
export type TrActionType = {
|
|
13
|
+
type: ActionType;
|
|
14
|
+
extraData?: {
|
|
15
|
+
statusId?: string;
|
|
16
|
+
};
|
|
17
|
+
} | undefined;
|
|
18
|
+
export declare const checkTrActionType: (tr: ReadonlyTransaction) => TrActionType;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Fragment } from '@atlaskit/editor-prosemirror/model';
|
|
2
|
-
import { MetricsState } from '../main';
|
|
2
|
+
import type { MetricsState } from '../main';
|
|
3
3
|
export declare const getNodeChanges: ({ currentContent, pluginState, }: {
|
|
4
4
|
currentContent: Fragment;
|
|
5
5
|
pluginState?: MetricsState | undefined;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { ReadonlyTransaction } from '@atlaskit/editor-prosemirror/state';
|
|
1
|
+
import type { ReadonlyTransaction } from '@atlaskit/editor-prosemirror/state';
|
|
2
2
|
export declare const isNonTextUndo: (tr: ReadonlyTransaction) => boolean;
|
|
@@ -1,12 +1,23 @@
|
|
|
1
|
-
import type { EditorCommand, NextEditorPlugin } from '@atlaskit/editor-common/types';
|
|
1
|
+
import type { EditorCommand, NextEditorPlugin, OptionalPlugin } from '@atlaskit/editor-common/types';
|
|
2
2
|
import type { AnalyticsPlugin } from '@atlaskit/editor-plugin-analytics';
|
|
3
|
+
import type { BlockControlsPlugin } from '@atlaskit/editor-plugin-block-controls';
|
|
4
|
+
import type { Selection } from '@atlaskit/editor-prosemirror/state';
|
|
3
5
|
import type { MetricsState } from './pm-plugins/main';
|
|
6
|
+
type handleIntentToStartEditProps = {
|
|
7
|
+
newSelection?: Selection;
|
|
8
|
+
shouldStartTimer?: boolean;
|
|
9
|
+
shouldPersistActiveSession?: boolean;
|
|
10
|
+
};
|
|
4
11
|
export type MetricsPlugin = NextEditorPlugin<'metrics', {
|
|
5
12
|
dependencies: [
|
|
6
|
-
AnalyticsPlugin
|
|
13
|
+
AnalyticsPlugin,
|
|
14
|
+
OptionalPlugin<BlockControlsPlugin>
|
|
7
15
|
];
|
|
8
16
|
sharedState: MetricsState;
|
|
9
17
|
commands: {
|
|
18
|
+
startActiveSessionTimer: () => EditorCommand;
|
|
10
19
|
stopActiveSession: () => EditorCommand;
|
|
20
|
+
handleIntentToStartEdit: ({ newSelection, shouldStartTimer, shouldPersistActiveSession, }: handleIntentToStartEditProps) => EditorCommand;
|
|
11
21
|
};
|
|
12
22
|
}>;
|
|
23
|
+
export {};
|
|
@@ -3,6 +3,7 @@ import { type ExtractInjectionAPI } from '@atlaskit/editor-common/types';
|
|
|
3
3
|
import { Fragment } from '@atlaskit/editor-prosemirror/model';
|
|
4
4
|
import { PluginKey, Selection } from '@atlaskit/editor-prosemirror/state';
|
|
5
5
|
import { type MetricsPlugin } from '../metricsPluginType';
|
|
6
|
+
import { type TrActionType } from './utils/check-tr-action-type';
|
|
6
7
|
export declare const metricsKey: PluginKey<any>;
|
|
7
8
|
export type MetricsState = {
|
|
8
9
|
intentToStartEditTime?: number;
|
|
@@ -12,7 +13,9 @@ export type MetricsState = {
|
|
|
12
13
|
lastSelection?: Selection;
|
|
13
14
|
actionTypeCount: ActionByType;
|
|
14
15
|
timeOfLastTextInput?: number;
|
|
16
|
+
shouldPersistActiveSession?: boolean;
|
|
15
17
|
initialContent?: Fragment;
|
|
18
|
+
previousTrType?: TrActionType;
|
|
16
19
|
};
|
|
17
20
|
export type ActionByType = {
|
|
18
21
|
textInputCount: number;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { ReadonlyTransaction } from '@atlaskit/editor-prosemirror/state';
|
|
2
|
+
export declare enum ActionType {
|
|
3
|
+
TEXT_INPUT = "textInput",
|
|
4
|
+
EMPTY_LINE_ADDED_OR_DELETED = "emptyLineAddedOrDeleted",
|
|
5
|
+
INSERTED_FROM_TYPE_AHEAD = "insertedFromTypeAhead",
|
|
6
|
+
INSERTING_NEW_LIST_TYPE_NODE = "insertingNewListTypeNode",
|
|
7
|
+
UPDATING_NEW_LIST_TYPE_ITEM = "updatingNewListItem",
|
|
8
|
+
ADDING_LINK = "addingLink",
|
|
9
|
+
UPDATING_STATUS = "updatingStatus"
|
|
10
|
+
}
|
|
11
|
+
export declare const shouldSkipTr: (tr: ReadonlyTransaction) => boolean;
|
|
12
|
+
export type TrActionType = {
|
|
13
|
+
type: ActionType;
|
|
14
|
+
extraData?: {
|
|
15
|
+
statusId?: string;
|
|
16
|
+
};
|
|
17
|
+
} | undefined;
|
|
18
|
+
export declare const checkTrActionType: (tr: ReadonlyTransaction) => TrActionType;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Fragment } from '@atlaskit/editor-prosemirror/model';
|
|
2
|
-
import { MetricsState } from '../main';
|
|
2
|
+
import type { MetricsState } from '../main';
|
|
3
3
|
export declare const getNodeChanges: ({ currentContent, pluginState, }: {
|
|
4
4
|
currentContent: Fragment;
|
|
5
5
|
pluginState?: MetricsState | undefined;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { ReadonlyTransaction } from '@atlaskit/editor-prosemirror/state';
|
|
1
|
+
import type { ReadonlyTransaction } from '@atlaskit/editor-prosemirror/state';
|
|
2
2
|
export declare const isNonTextUndo: (tr: ReadonlyTransaction) => boolean;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atlaskit/editor-plugin-metrics",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.2.1",
|
|
4
4
|
"description": "Metrics plugin for @atlaskit/editor-core",
|
|
5
5
|
"author": "Atlassian Pty Ltd",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -25,10 +25,11 @@
|
|
|
25
25
|
},
|
|
26
26
|
"dependencies": {
|
|
27
27
|
"@atlaskit/adf-schema": "^47.2.1",
|
|
28
|
-
"@atlaskit/editor-common": "^99.
|
|
28
|
+
"@atlaskit/editor-common": "^99.19.0",
|
|
29
29
|
"@atlaskit/editor-plugin-analytics": "^1.12.0",
|
|
30
|
+
"@atlaskit/editor-plugin-block-controls": "^2.27.0",
|
|
30
31
|
"@atlaskit/editor-prosemirror": "7.0.0",
|
|
31
|
-
"@atlaskit/platform-feature-flags": "^1.
|
|
32
|
+
"@atlaskit/platform-feature-flags": "^1.1.0",
|
|
32
33
|
"@babel/runtime": "^7.0.0",
|
|
33
34
|
"bind-event-listener": "^3.0.0"
|
|
34
35
|
},
|