@atlaskit/editor-plugin-save-on-enter 0.1.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/.eslintrc.js ADDED
@@ -0,0 +1,14 @@
1
+ module.exports = {
2
+ rules: {
3
+ '@typescript-eslint/no-duplicate-imports': 'error',
4
+ '@typescript-eslint/no-explicit-any': 'error',
5
+ },
6
+ overrides: [
7
+ {
8
+ files: ['**/__tests__/**/*.{js,ts,tsx}', '**/examples/**/*.{js,ts,tsx}'],
9
+ rules: {
10
+ '@typescript-eslint/no-explicit-any': 'off',
11
+ },
12
+ },
13
+ ],
14
+ };
package/CHANGELOG.md ADDED
@@ -0,0 +1 @@
1
+ # @atlaskit/editor-plugin-save-on-enter
package/LICENSE.md ADDED
@@ -0,0 +1,13 @@
1
+ Copyright 2023 Atlassian Pty Ltd
2
+
3
+ Licensed under the Apache License, Version 2.0 (the "License");
4
+ you may not use this file except in compliance with the License.
5
+ You may obtain a copy of the License at
6
+
7
+ http://www.apache.org/licenses/LICENSE-2.0
8
+
9
+ Unless required by applicable law or agreed to in writing, software
10
+ distributed under the License is distributed on an "AS IS" BASIS,
11
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ See the License for the specific language governing permissions and
13
+ limitations under the License.
package/README.md ADDED
@@ -0,0 +1,30 @@
1
+ # Editor plugin Save-on-enter
2
+
3
+ Save-on-enter plugin for @atlaskit/editor-core
4
+
5
+ **Note:** This component is designed for internal Atlassian development.
6
+ External contributors will be able to use this component but will not be able to submit issues.
7
+
8
+ ## Install
9
+ ---
10
+ - **Install** - *yarn add @atlaskit/editor-plugin-save-on-enter*
11
+ - **npm** - [@atlaskit/editor-plugin-save-on-enter](https://www.npmjs.com/package/@atlaskit/editor-plugin-save-on-enter)
12
+ - **Source** - [Bitbucket](https://bitbucket.org/atlassian/atlassian-frontend/src/master/packages/editor/editor-plugin-save-on-enter)
13
+ - **Bundle** - [unpkg.com](https://unpkg.com/@atlaskit/editor-plugin-save-on-enter/dist/)
14
+
15
+ ## Usage
16
+ ---
17
+ **Internal use only**
18
+
19
+ @atlaskit/editor-plugin-save-on-enter is intended for internal use by the @atlaskit/editor-core and as a plugin dependency of the Editor within your product.
20
+
21
+ Direct use of this component is not supported.
22
+
23
+ Please see [Atlaskit - Editor plugin Save-on-enter](https://atlaskit.atlassian.com/packages/editor/editor-plugin-save-on-enter) for documentation and examples for this package.
24
+
25
+ ## Support
26
+ ---
27
+ For internal Atlassian, visit the slack channel [#help-editor](https://atlassian.slack.com/archives/CFG3PSQ9E) for support or visit [go/editor-help](https://go/editor-help) to submit a bug.
28
+ ## License
29
+ ---
30
+ Please see [Atlassian Frontend - License](https://developer.atlassian.com/cloud/framework/atlassian-frontend/#license) for more licensing information.
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ Object.defineProperty(exports, "saveOnEnterPlugin", {
7
+ enumerable: true,
8
+ get: function get() {
9
+ return _plugin.saveOnEnterPlugin;
10
+ }
11
+ });
12
+ var _plugin = require("./plugin");
@@ -0,0 +1,69 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.createPlugin = createPlugin;
7
+ exports.saveOnEnterPlugin = void 0;
8
+ var _analytics = require("@atlaskit/editor-common/analytics");
9
+ var _utils = require("@atlaskit/editor-common/utils");
10
+ var _keymap = require("@atlaskit/editor-prosemirror/keymap");
11
+ function createPlugin(eventDispatch, onSave) {
12
+ if (!onSave) {
13
+ return;
14
+ }
15
+ return (0, _keymap.keymap)({
16
+ Enter: function Enter(state, _dispatch, editorView) {
17
+ if (editorView && canSaveOnEnter(editorView)) {
18
+ eventDispatch(_utils.analyticsEventKey, analyticsPayload(state));
19
+ onSave(editorView);
20
+ return true;
21
+ }
22
+ return false;
23
+ }
24
+ });
25
+ }
26
+ function canSaveOnEnter(editorView) {
27
+ var _ref = editorView.state.selection,
28
+ $cursor = _ref.$cursor;
29
+ var _editorView$state$sch = editorView.state.schema.nodes,
30
+ decisionItem = _editorView$state$sch.decisionItem,
31
+ paragraph = _editorView$state$sch.paragraph,
32
+ taskItem = _editorView$state$sch.taskItem;
33
+ return !$cursor || $cursor.parent.type === paragraph && $cursor.depth === 1 || $cursor.parent.type === decisionItem && !isEmptyAtCursor($cursor) || $cursor.parent.type === taskItem && !isEmptyAtCursor($cursor);
34
+ }
35
+ function isEmptyAtCursor($cursor) {
36
+ var content = $cursor.parent.content;
37
+ return !(content && content.size);
38
+ }
39
+ var analyticsPayload = function analyticsPayload(state) {
40
+ return {
41
+ payload: {
42
+ action: _analytics.ACTION.STOPPED,
43
+ actionSubject: _analytics.ACTION_SUBJECT.EDITOR,
44
+ actionSubjectId: _analytics.ACTION_SUBJECT_ID.SAVE,
45
+ attributes: {
46
+ inputMethod: _analytics.INPUT_METHOD.SHORTCUT,
47
+ documentSize: state.doc.nodeSize
48
+ // TODO add individual node counts - tables, headings, lists, mediaSingles, mediaGroups, mediaCards, panels, extensions, decisions, action, codeBlocks
49
+ },
50
+
51
+ eventType: _analytics.EVENT_TYPE.UI
52
+ }
53
+ };
54
+ };
55
+ var saveOnEnterPlugin = exports.saveOnEnterPlugin = function saveOnEnterPlugin(_ref2) {
56
+ var onSave = _ref2.config;
57
+ return {
58
+ name: 'saveOnEnter',
59
+ pmPlugins: function pmPlugins() {
60
+ return [{
61
+ name: 'saveOnEnter',
62
+ plugin: function plugin(_ref3) {
63
+ var dispatch = _ref3.dispatch;
64
+ return createPlugin(dispatch, onSave);
65
+ }
66
+ }];
67
+ }
68
+ };
69
+ };
@@ -0,0 +1 @@
1
+ export { saveOnEnterPlugin } from './plugin';
@@ -0,0 +1,62 @@
1
+ import { ACTION, ACTION_SUBJECT, ACTION_SUBJECT_ID, EVENT_TYPE, INPUT_METHOD } from '@atlaskit/editor-common/analytics';
2
+ import { analyticsEventKey } from '@atlaskit/editor-common/utils';
3
+ import { keymap } from '@atlaskit/editor-prosemirror/keymap';
4
+ export function createPlugin(eventDispatch, onSave) {
5
+ if (!onSave) {
6
+ return;
7
+ }
8
+ return keymap({
9
+ Enter(state, _dispatch, editorView) {
10
+ if (editorView && canSaveOnEnter(editorView)) {
11
+ eventDispatch(analyticsEventKey, analyticsPayload(state));
12
+ onSave(editorView);
13
+ return true;
14
+ }
15
+ return false;
16
+ }
17
+ });
18
+ }
19
+ function canSaveOnEnter(editorView) {
20
+ const {
21
+ $cursor
22
+ } = editorView.state.selection;
23
+ const {
24
+ decisionItem,
25
+ paragraph,
26
+ taskItem
27
+ } = editorView.state.schema.nodes;
28
+ return !$cursor || $cursor.parent.type === paragraph && $cursor.depth === 1 || $cursor.parent.type === decisionItem && !isEmptyAtCursor($cursor) || $cursor.parent.type === taskItem && !isEmptyAtCursor($cursor);
29
+ }
30
+ function isEmptyAtCursor($cursor) {
31
+ const {
32
+ content
33
+ } = $cursor.parent;
34
+ return !(content && content.size);
35
+ }
36
+ const analyticsPayload = state => ({
37
+ payload: {
38
+ action: ACTION.STOPPED,
39
+ actionSubject: ACTION_SUBJECT.EDITOR,
40
+ actionSubjectId: ACTION_SUBJECT_ID.SAVE,
41
+ attributes: {
42
+ inputMethod: INPUT_METHOD.SHORTCUT,
43
+ documentSize: state.doc.nodeSize
44
+ // TODO add individual node counts - tables, headings, lists, mediaSingles, mediaGroups, mediaCards, panels, extensions, decisions, action, codeBlocks
45
+ },
46
+
47
+ eventType: EVENT_TYPE.UI
48
+ }
49
+ });
50
+ export const saveOnEnterPlugin = ({
51
+ config: onSave
52
+ }) => ({
53
+ name: 'saveOnEnter',
54
+ pmPlugins() {
55
+ return [{
56
+ name: 'saveOnEnter',
57
+ plugin: ({
58
+ dispatch
59
+ }) => createPlugin(dispatch, onSave)
60
+ }];
61
+ }
62
+ });
@@ -0,0 +1 @@
1
+ export { saveOnEnterPlugin } from './plugin';
@@ -0,0 +1,62 @@
1
+ import { ACTION, ACTION_SUBJECT, ACTION_SUBJECT_ID, EVENT_TYPE, INPUT_METHOD } from '@atlaskit/editor-common/analytics';
2
+ import { analyticsEventKey } from '@atlaskit/editor-common/utils';
3
+ import { keymap } from '@atlaskit/editor-prosemirror/keymap';
4
+ export function createPlugin(eventDispatch, onSave) {
5
+ if (!onSave) {
6
+ return;
7
+ }
8
+ return keymap({
9
+ Enter: function Enter(state, _dispatch, editorView) {
10
+ if (editorView && canSaveOnEnter(editorView)) {
11
+ eventDispatch(analyticsEventKey, analyticsPayload(state));
12
+ onSave(editorView);
13
+ return true;
14
+ }
15
+ return false;
16
+ }
17
+ });
18
+ }
19
+ function canSaveOnEnter(editorView) {
20
+ var _ref = editorView.state.selection,
21
+ $cursor = _ref.$cursor;
22
+ var _editorView$state$sch = editorView.state.schema.nodes,
23
+ decisionItem = _editorView$state$sch.decisionItem,
24
+ paragraph = _editorView$state$sch.paragraph,
25
+ taskItem = _editorView$state$sch.taskItem;
26
+ return !$cursor || $cursor.parent.type === paragraph && $cursor.depth === 1 || $cursor.parent.type === decisionItem && !isEmptyAtCursor($cursor) || $cursor.parent.type === taskItem && !isEmptyAtCursor($cursor);
27
+ }
28
+ function isEmptyAtCursor($cursor) {
29
+ var content = $cursor.parent.content;
30
+ return !(content && content.size);
31
+ }
32
+ var analyticsPayload = function analyticsPayload(state) {
33
+ return {
34
+ payload: {
35
+ action: ACTION.STOPPED,
36
+ actionSubject: ACTION_SUBJECT.EDITOR,
37
+ actionSubjectId: ACTION_SUBJECT_ID.SAVE,
38
+ attributes: {
39
+ inputMethod: INPUT_METHOD.SHORTCUT,
40
+ documentSize: state.doc.nodeSize
41
+ // TODO add individual node counts - tables, headings, lists, mediaSingles, mediaGroups, mediaCards, panels, extensions, decisions, action, codeBlocks
42
+ },
43
+
44
+ eventType: EVENT_TYPE.UI
45
+ }
46
+ };
47
+ };
48
+ export var saveOnEnterPlugin = function saveOnEnterPlugin(_ref2) {
49
+ var onSave = _ref2.config;
50
+ return {
51
+ name: 'saveOnEnter',
52
+ pmPlugins: function pmPlugins() {
53
+ return [{
54
+ name: 'saveOnEnter',
55
+ plugin: function plugin(_ref3) {
56
+ var dispatch = _ref3.dispatch;
57
+ return createPlugin(dispatch, onSave);
58
+ }
59
+ }];
60
+ }
61
+ };
62
+ };
@@ -0,0 +1,2 @@
1
+ export { saveOnEnterPlugin } from './plugin';
2
+ export type { SaveOnEnterPlugin } from './plugin';
@@ -0,0 +1,11 @@
1
+ import type { Dispatch } from '@atlaskit/editor-common/event-dispatcher';
2
+ import type { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
3
+ import type { NextEditorPlugin } from '@atlaskit/editor-common/types';
4
+ import type { EditorView } from '@atlaskit/editor-prosemirror/view';
5
+ export declare function createPlugin(eventDispatch: Dispatch, onSave?: (editorView: EditorView) => void): SafePlugin | undefined;
6
+ type Config = (editorView: EditorView) => void;
7
+ export type SaveOnEnterPlugin = NextEditorPlugin<'saveOnEnter', {
8
+ pluginConfiguration: Config | undefined;
9
+ }>;
10
+ export declare const saveOnEnterPlugin: SaveOnEnterPlugin;
11
+ export {};
@@ -0,0 +1,2 @@
1
+ export { saveOnEnterPlugin } from './plugin';
2
+ export type { SaveOnEnterPlugin } from './plugin';
@@ -0,0 +1,11 @@
1
+ import type { Dispatch } from '@atlaskit/editor-common/event-dispatcher';
2
+ import type { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
3
+ import type { NextEditorPlugin } from '@atlaskit/editor-common/types';
4
+ import type { EditorView } from '@atlaskit/editor-prosemirror/view';
5
+ export declare function createPlugin(eventDispatch: Dispatch, onSave?: (editorView: EditorView) => void): SafePlugin | undefined;
6
+ type Config = (editorView: EditorView) => void;
7
+ export type SaveOnEnterPlugin = NextEditorPlugin<'saveOnEnter', {
8
+ pluginConfiguration: Config | undefined;
9
+ }>;
10
+ export declare const saveOnEnterPlugin: SaveOnEnterPlugin;
11
+ export {};
package/package.json ADDED
@@ -0,0 +1,92 @@
1
+ {
2
+ "name": "@atlaskit/editor-plugin-save-on-enter",
3
+ "version": "0.1.0",
4
+ "description": "Save-on-enter plugin for @atlaskit/editor-core",
5
+ "author": "Atlassian Pty Ltd",
6
+ "license": "Apache-2.0",
7
+ "publishConfig": {
8
+ "registry": "https://registry.npmjs.org/"
9
+ },
10
+ "atlassian": {
11
+ "team": "Editor: Lego",
12
+ "inPublicMirror": false,
13
+ "releaseModel": "continuous",
14
+ "website": {
15
+ "name": "EditorPluginSaveOnEnter",
16
+ "category": "Components"
17
+ }
18
+ },
19
+ "repository": "https://bitbucket.org/atlassian/atlassian-frontend",
20
+ "main": "dist/cjs/index.js",
21
+ "module": "dist/esm/index.js",
22
+ "module:es2019": "dist/es2019/index.js",
23
+ "types": "dist/types/index.d.ts",
24
+ "typesVersions": {
25
+ ">=4.5 <4.9": {
26
+ "*": [
27
+ "dist/types-ts4.5/*",
28
+ "dist/types-ts4.5/index.d.ts"
29
+ ]
30
+ }
31
+ },
32
+ "sideEffects": false,
33
+ "atlaskit:src": "src/index.ts",
34
+ "af:exports": {
35
+ ".": "./src/index.ts"
36
+ },
37
+ "dependencies": {
38
+ "@atlaskit/editor-common": "^76.5.0",
39
+ "@atlaskit/editor-prosemirror": "1.1.0",
40
+ "@babel/runtime": "^7.0.0"
41
+ },
42
+ "peerDependencies": {
43
+ "react": "^16.8.0"
44
+ },
45
+ "devDependencies": {
46
+ "@af/visual-regression": "*",
47
+ "@atlaskit/ssr": "*",
48
+ "@atlaskit/visual-regression": "*",
49
+ "@atlaskit/webdriver-runner": "*",
50
+ "@atlassian/atlassian-frontend-prettier-config-1.0.0": "npm:@atlassian/atlassian-frontend-prettier-config@1.0.0",
51
+ "@testing-library/react": "^12.1.5",
52
+ "react-dom": "^16.8.0",
53
+ "typescript": "~4.9.5",
54
+ "wait-for-expect": "^1.2.0"
55
+ },
56
+ "techstack": {
57
+ "@atlassian/frontend": {
58
+ "import-structure": [
59
+ "atlassian-conventions"
60
+ ],
61
+ "circular-dependencies": [
62
+ "file-and-folder-level"
63
+ ]
64
+ },
65
+ "@repo/internal": {
66
+ "dom-events": "use-bind-event-listener",
67
+ "analytics": [
68
+ "analytics-next"
69
+ ],
70
+ "design-tokens": [
71
+ "color"
72
+ ],
73
+ "theming": [
74
+ "react-context"
75
+ ],
76
+ "ui-components": [
77
+ "lite-mode"
78
+ ],
79
+ "deprecation": [
80
+ "no-deprecated-imports"
81
+ ],
82
+ "styling": [
83
+ "static",
84
+ "emotion"
85
+ ],
86
+ "imports": [
87
+ "import-no-extraneous-disable-for-examples-and-docs"
88
+ ]
89
+ }
90
+ },
91
+ "prettier": "@atlassian/atlassian-frontend-prettier-config-1.0.0"
92
+ }
package/report.api.md ADDED
@@ -0,0 +1,50 @@
1
+ <!-- API Report Version: 2.3 -->
2
+
3
+ ## API Report File for "@atlaskit/editor-plugin-save-on-enter"
4
+
5
+ > Do not edit this file. This report is auto-generated using [API Extractor](https://api-extractor.com/).
6
+ > [Learn more about API reports](https://hello.atlassian.net/wiki/spaces/UR/pages/1825484529/Package+API+Reports)
7
+
8
+ ### Table of contents
9
+
10
+ - [Main Entry Types](#main-entry-types)
11
+ - [Peer Dependencies](#peer-dependencies)
12
+
13
+ ### Main Entry Types
14
+
15
+ <!--SECTION START: Main Entry Types-->
16
+
17
+ ```ts
18
+ import type { EditorView } from '@atlaskit/editor-prosemirror/view';
19
+ import type { NextEditorPlugin } from '@atlaskit/editor-common/types';
20
+
21
+ // @public (undocumented)
22
+ type Config = (editorView: EditorView) => void;
23
+
24
+ // @public (undocumented)
25
+ export type SaveOnEnterPlugin = NextEditorPlugin<
26
+ 'saveOnEnter',
27
+ {
28
+ pluginConfiguration: Config | undefined;
29
+ }
30
+ >;
31
+
32
+ // @public (undocumented)
33
+ export const saveOnEnterPlugin: SaveOnEnterPlugin;
34
+
35
+ // (No @packageDocumentation comment for this package)
36
+ ```
37
+
38
+ <!--SECTION END: Main Entry Types-->
39
+
40
+ ### Peer Dependencies
41
+
42
+ <!--SECTION START: Peer Dependencies-->
43
+
44
+ ```json
45
+ {
46
+ "react": "^16.8.0"
47
+ }
48
+ ```
49
+
50
+ <!--SECTION END: Peer Dependencies-->
@@ -0,0 +1,23 @@
1
+ ## API Report File for "@atlaskit/editor-plugin-save-on-enter"
2
+
3
+ > Do not edit this file. It is a report generated by [API Extractor](https://api-extractor.com/).
4
+
5
+ ```ts
6
+
7
+ import type { EditorView } from '@atlaskit/editor-prosemirror/view';
8
+ import type { NextEditorPlugin } from '@atlaskit/editor-common/types';
9
+
10
+ // @public (undocumented)
11
+ type Config = (editorView: EditorView) => void;
12
+
13
+ // @public (undocumented)
14
+ export type SaveOnEnterPlugin = NextEditorPlugin<'saveOnEnter', {
15
+ pluginConfiguration: Config | undefined;
16
+ }>;
17
+
18
+ // @public (undocumented)
19
+ export const saveOnEnterPlugin: SaveOnEnterPlugin;
20
+
21
+ // (No @packageDocumentation comment for this package)
22
+
23
+ ```