@atlaskit/editor-plugin-placeholder-text 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 +14 -0
- package/CHANGELOG.md +1 -0
- package/LICENSE.md +13 -0
- package/README.md +30 -0
- package/dist/cjs/actions.js +35 -0
- package/dist/cjs/fake-text-cursor/cursor.js +107 -0
- package/dist/cjs/index.js +13 -0
- package/dist/cjs/placeholder-text-nodeview.js +89 -0
- package/dist/cjs/plugin-key.js +8 -0
- package/dist/cjs/plugin.js +270 -0
- package/dist/cjs/selection-utils.js +14 -0
- package/dist/cjs/styles.js +13 -0
- package/dist/cjs/types.js +5 -0
- package/dist/cjs/ui/FloatingToolbar/index.js +88 -0
- package/dist/cjs/ui/FloatingToolbar/styles.js +15 -0
- package/dist/cjs/ui/FloatingToolbar/utils.js +55 -0
- package/dist/cjs/ui/PlaceholderFloatingToolbar/index.js +90 -0
- package/dist/es2019/actions.js +27 -0
- package/dist/es2019/fake-text-cursor/cursor.js +77 -0
- package/dist/es2019/index.js +1 -0
- package/dist/es2019/placeholder-text-nodeview.js +77 -0
- package/dist/es2019/plugin-key.js +2 -0
- package/dist/es2019/plugin.js +250 -0
- package/dist/es2019/selection-utils.js +8 -0
- package/dist/es2019/styles.js +52 -0
- package/dist/es2019/types.js +1 -0
- package/dist/es2019/ui/FloatingToolbar/index.js +49 -0
- package/dist/es2019/ui/FloatingToolbar/styles.js +15 -0
- package/dist/es2019/ui/FloatingToolbar/utils.js +42 -0
- package/dist/es2019/ui/PlaceholderFloatingToolbar/index.js +61 -0
- package/dist/esm/actions.js +29 -0
- package/dist/esm/fake-text-cursor/cursor.js +100 -0
- package/dist/esm/index.js +1 -0
- package/dist/esm/placeholder-text-nodeview.js +82 -0
- package/dist/esm/plugin-key.js +2 -0
- package/dist/esm/plugin.js +262 -0
- package/dist/esm/selection-utils.js +8 -0
- package/dist/esm/styles.js +6 -0
- package/dist/esm/types.js +1 -0
- package/dist/esm/ui/FloatingToolbar/index.js +67 -0
- package/dist/esm/ui/FloatingToolbar/styles.js +8 -0
- package/dist/esm/ui/FloatingToolbar/utils.js +49 -0
- package/dist/esm/ui/PlaceholderFloatingToolbar/index.js +80 -0
- package/dist/types/actions.d.ts +4 -0
- package/dist/types/fake-text-cursor/cursor.d.ts +30 -0
- package/dist/types/index.d.ts +2 -0
- package/dist/types/placeholder-text-nodeview.d.ts +17 -0
- package/dist/types/plugin-key.d.ts +3 -0
- package/dist/types/plugin.d.ts +7 -0
- package/dist/types/selection-utils.d.ts +2 -0
- package/dist/types/styles.d.ts +1 -0
- package/dist/types/types.d.ts +22 -0
- package/dist/types/ui/FloatingToolbar/index.d.ts +28 -0
- package/dist/types/ui/FloatingToolbar/styles.d.ts +1 -0
- package/dist/types/ui/FloatingToolbar/utils.d.ts +18 -0
- package/dist/types/ui/PlaceholderFloatingToolbar/index.d.ts +25 -0
- package/dist/types-ts4.5/actions.d.ts +4 -0
- package/dist/types-ts4.5/fake-text-cursor/cursor.d.ts +30 -0
- package/dist/types-ts4.5/index.d.ts +2 -0
- package/dist/types-ts4.5/placeholder-text-nodeview.d.ts +17 -0
- package/dist/types-ts4.5/plugin-key.d.ts +3 -0
- package/dist/types-ts4.5/plugin.d.ts +7 -0
- package/dist/types-ts4.5/selection-utils.d.ts +2 -0
- package/dist/types-ts4.5/styles.d.ts +1 -0
- package/dist/types-ts4.5/types.d.ts +22 -0
- package/dist/types-ts4.5/ui/FloatingToolbar/index.d.ts +28 -0
- package/dist/types-ts4.5/ui/FloatingToolbar/styles.d.ts +1 -0
- package/dist/types-ts4.5/ui/FloatingToolbar/utils.d.ts +18 -0
- package/dist/types-ts4.5/ui/PlaceholderFloatingToolbar/index.d.ts +25 -0
- package/package.json +100 -0
- package/report.api.md +80 -0
- package/styles/package.json +15 -0
- package/tmp/api-report-tmp.d.ts +49 -0
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-placeholder-text
|
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 placeholder-text
|
|
2
|
+
|
|
3
|
+
Placeholder text 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-placeholder-text*
|
|
11
|
+
- **npm** - [@atlaskit/editor-plugin-placeholder-text](https://www.npmjs.com/package/@atlaskit/editor-plugin-placeholder-text)
|
|
12
|
+
- **Source** - [Bitbucket](https://bitbucket.org/atlassian/atlassian-frontend/src/master/packages/editor/editor-plugin-placeholder-text)
|
|
13
|
+
- **Bundle** - [unpkg.com](https://unpkg.com/@atlaskit/editor-plugin-placeholder-text/dist/)
|
|
14
|
+
|
|
15
|
+
## Usage
|
|
16
|
+
---
|
|
17
|
+
**Internal use only**
|
|
18
|
+
|
|
19
|
+
@atlaskit/editor-plugin-placeholder-text 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 placeholder text](https://atlaskit.atlassian.com/packages/editor/editor-plugin-placeholder-text) 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,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.showPlaceholderFloatingToolbar = exports.insertPlaceholderTextAtSelection = exports.hidePlaceholderFloatingToolbar = void 0;
|
|
7
|
+
var _pluginKey = require("./plugin-key");
|
|
8
|
+
var showPlaceholderFloatingToolbar = exports.showPlaceholderFloatingToolbar = function showPlaceholderFloatingToolbar(state, dispatch) {
|
|
9
|
+
var tr = state.tr;
|
|
10
|
+
if (!state.selection.empty) {
|
|
11
|
+
tr.deleteSelection();
|
|
12
|
+
}
|
|
13
|
+
tr.setMeta(_pluginKey.pluginKey, {
|
|
14
|
+
showInsertPanelAt: tr.selection.anchor
|
|
15
|
+
});
|
|
16
|
+
tr.scrollIntoView();
|
|
17
|
+
dispatch(tr);
|
|
18
|
+
return true;
|
|
19
|
+
};
|
|
20
|
+
var insertPlaceholderTextAtSelection = exports.insertPlaceholderTextAtSelection = function insertPlaceholderTextAtSelection(value) {
|
|
21
|
+
return function (state, dispatch) {
|
|
22
|
+
dispatch(state.tr.replaceSelectionWith(state.schema.nodes.placeholder.createChecked({
|
|
23
|
+
text: value
|
|
24
|
+
})).setMeta(_pluginKey.pluginKey, {
|
|
25
|
+
showInsertPanelAt: null
|
|
26
|
+
}).scrollIntoView());
|
|
27
|
+
return true;
|
|
28
|
+
};
|
|
29
|
+
};
|
|
30
|
+
var hidePlaceholderFloatingToolbar = exports.hidePlaceholderFloatingToolbar = function hidePlaceholderFloatingToolbar(state, dispatch) {
|
|
31
|
+
dispatch(state.tr.setMeta(_pluginKey.pluginKey, {
|
|
32
|
+
showInsertPanelAt: null
|
|
33
|
+
}));
|
|
34
|
+
return true;
|
|
35
|
+
};
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.removeFakeTextCursor = exports.drawFakeTextCursor = exports.addFakeTextCursor = exports.FakeTextCursorSelection = exports.FakeTextCursorBookmark = void 0;
|
|
8
|
+
var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
|
|
9
|
+
var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn"));
|
|
10
|
+
var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));
|
|
11
|
+
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
|
|
12
|
+
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
|
|
13
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
14
|
+
var _model = require("@atlaskit/editor-prosemirror/model");
|
|
15
|
+
var _state = require("@atlaskit/editor-prosemirror/state");
|
|
16
|
+
var _view = require("@atlaskit/editor-prosemirror/view");
|
|
17
|
+
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = (0, _getPrototypeOf2.default)(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = (0, _getPrototypeOf2.default)(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return (0, _possibleConstructorReturn2.default)(this, result); }; }
|
|
18
|
+
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
|
|
19
|
+
var FakeTextCursorBookmark = exports.FakeTextCursorBookmark = /*#__PURE__*/function () {
|
|
20
|
+
function FakeTextCursorBookmark(pos) {
|
|
21
|
+
(0, _classCallCheck2.default)(this, FakeTextCursorBookmark);
|
|
22
|
+
(0, _defineProperty2.default)(this, "pos", undefined);
|
|
23
|
+
(0, _defineProperty2.default)(this, "visible", false);
|
|
24
|
+
this.pos = pos;
|
|
25
|
+
}
|
|
26
|
+
(0, _createClass2.default)(FakeTextCursorBookmark, [{
|
|
27
|
+
key: "map",
|
|
28
|
+
value: function map(mapping) {
|
|
29
|
+
return new FakeTextCursorBookmark(mapping.map(this.pos));
|
|
30
|
+
}
|
|
31
|
+
}, {
|
|
32
|
+
key: "resolve",
|
|
33
|
+
value: function resolve(doc) {
|
|
34
|
+
var $pos = doc.resolve(this.pos);
|
|
35
|
+
return _state.Selection.near($pos);
|
|
36
|
+
}
|
|
37
|
+
}]);
|
|
38
|
+
return FakeTextCursorBookmark;
|
|
39
|
+
}();
|
|
40
|
+
var FakeTextCursorSelection = exports.FakeTextCursorSelection = /*#__PURE__*/function (_Selection) {
|
|
41
|
+
(0, _inherits2.default)(FakeTextCursorSelection, _Selection);
|
|
42
|
+
var _super = _createSuper(FakeTextCursorSelection);
|
|
43
|
+
function FakeTextCursorSelection($pos) {
|
|
44
|
+
(0, _classCallCheck2.default)(this, FakeTextCursorSelection);
|
|
45
|
+
return _super.call(this, $pos, $pos);
|
|
46
|
+
}
|
|
47
|
+
(0, _createClass2.default)(FakeTextCursorSelection, [{
|
|
48
|
+
key: "map",
|
|
49
|
+
value: function map(doc, mapping) {
|
|
50
|
+
var $pos = doc.resolve(mapping.map(this.$head.pos));
|
|
51
|
+
return new FakeTextCursorSelection($pos);
|
|
52
|
+
}
|
|
53
|
+
}, {
|
|
54
|
+
key: "eq",
|
|
55
|
+
value: function eq(other) {
|
|
56
|
+
return other instanceof FakeTextCursorSelection && other.head === this.head;
|
|
57
|
+
}
|
|
58
|
+
}, {
|
|
59
|
+
key: "toJSON",
|
|
60
|
+
value: function toJSON() {
|
|
61
|
+
return {
|
|
62
|
+
type: 'Cursor',
|
|
63
|
+
pos: this.head
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
}, {
|
|
67
|
+
key: "getBookmark",
|
|
68
|
+
value: function getBookmark() {
|
|
69
|
+
return new FakeTextCursorBookmark(this.anchor);
|
|
70
|
+
}
|
|
71
|
+
}], [{
|
|
72
|
+
key: "content",
|
|
73
|
+
value: function content() {
|
|
74
|
+
return _model.Slice.empty;
|
|
75
|
+
}
|
|
76
|
+
}, {
|
|
77
|
+
key: "fromJSON",
|
|
78
|
+
value: function fromJSON(doc, json) {
|
|
79
|
+
return new FakeTextCursorSelection(doc.resolve(json.pos));
|
|
80
|
+
}
|
|
81
|
+
}]);
|
|
82
|
+
return FakeTextCursorSelection;
|
|
83
|
+
}(_state.Selection);
|
|
84
|
+
_state.Selection.jsonID('fake-text-cursor', FakeTextCursorSelection);
|
|
85
|
+
var addFakeTextCursor = exports.addFakeTextCursor = function addFakeTextCursor(state, dispatch) {
|
|
86
|
+
var selection = state.selection;
|
|
87
|
+
if (selection.empty) {
|
|
88
|
+
var $from = state.selection.$from;
|
|
89
|
+
dispatch(state.tr.setSelection(new FakeTextCursorSelection($from)));
|
|
90
|
+
}
|
|
91
|
+
};
|
|
92
|
+
var removeFakeTextCursor = exports.removeFakeTextCursor = function removeFakeTextCursor(state, dispatch) {
|
|
93
|
+
if (state.selection instanceof FakeTextCursorSelection) {
|
|
94
|
+
var $from = state.selection.$from;
|
|
95
|
+
dispatch(state.tr.setSelection(new _state.TextSelection($from)));
|
|
96
|
+
}
|
|
97
|
+
};
|
|
98
|
+
var drawFakeTextCursor = exports.drawFakeTextCursor = function drawFakeTextCursor(state) {
|
|
99
|
+
if (!(state.selection instanceof FakeTextCursorSelection)) {
|
|
100
|
+
return null;
|
|
101
|
+
}
|
|
102
|
+
var node = document.createElement('div');
|
|
103
|
+
node.className = 'ProseMirror-fake-text-cursor';
|
|
104
|
+
return _view.DecorationSet.create(state.doc, [_view.Decoration.widget(state.selection.head, node, {
|
|
105
|
+
key: 'Cursor'
|
|
106
|
+
})]);
|
|
107
|
+
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
Object.defineProperty(exports, "placeholderTextPlugin", {
|
|
8
|
+
enumerable: true,
|
|
9
|
+
get: function get() {
|
|
10
|
+
return _plugin.default;
|
|
11
|
+
}
|
|
12
|
+
});
|
|
13
|
+
var _plugin = _interopRequireDefault(require("./plugin"));
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.PlaceholderTextNodeView = void 0;
|
|
8
|
+
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
|
|
9
|
+
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
|
|
10
|
+
var _utils = require("@atlaskit/editor-common/utils");
|
|
11
|
+
var _state = require("@atlaskit/editor-prosemirror/state");
|
|
12
|
+
var serializePlaceholderNode = function serializePlaceholderNode(node) {
|
|
13
|
+
var element = document.createElement('span');
|
|
14
|
+
element.classList.add('pm-placeholder');
|
|
15
|
+
|
|
16
|
+
// the inline node api test suite requires the following class name
|
|
17
|
+
element.classList.add('placeholderView-content-wrap');
|
|
18
|
+
element.innerText = _utils.ZERO_WIDTH_SPACE;
|
|
19
|
+
var elementChildren = document.createElement('span');
|
|
20
|
+
elementChildren.classList.add('pm-placeholder__text');
|
|
21
|
+
elementChildren.dataset.placeholder = node.attrs.text;
|
|
22
|
+
elementChildren.setAttribute('contenteditable', 'false');
|
|
23
|
+
element.appendChild(elementChildren);
|
|
24
|
+
if (_utils.browser.safari) {
|
|
25
|
+
element.appendChild(document.createTextNode(_utils.ZERO_WIDTH_SPACE));
|
|
26
|
+
} else {
|
|
27
|
+
element.appendChild(document.createElement('wbr'));
|
|
28
|
+
}
|
|
29
|
+
return element;
|
|
30
|
+
};
|
|
31
|
+
var PlaceholderTextNodeView = exports.PlaceholderTextNodeView = /*#__PURE__*/function () {
|
|
32
|
+
function PlaceholderTextNodeView(node, view, getPos) {
|
|
33
|
+
(0, _classCallCheck2.default)(this, PlaceholderTextNodeView);
|
|
34
|
+
this.node = node;
|
|
35
|
+
this.view = view;
|
|
36
|
+
this.getPos = getPos;
|
|
37
|
+
this.dom = serializePlaceholderNode(this.node);
|
|
38
|
+
this.getPos = getPos;
|
|
39
|
+
}
|
|
40
|
+
(0, _createClass2.default)(PlaceholderTextNodeView, [{
|
|
41
|
+
key: "stopEvent",
|
|
42
|
+
value: function stopEvent(e) {
|
|
43
|
+
if (e.type === 'mousedown' && typeof this.getPos === 'function') {
|
|
44
|
+
e.preventDefault();
|
|
45
|
+
var _view = this.view;
|
|
46
|
+
var startNodePosition = this.getPos();
|
|
47
|
+
if (typeof startNodePosition !== 'number') {
|
|
48
|
+
return false;
|
|
49
|
+
}
|
|
50
|
+
var tr = _view.state.tr;
|
|
51
|
+
tr.setSelection(_state.Selection.near(tr.doc.resolve(startNodePosition)));
|
|
52
|
+
_view.dispatch(tr);
|
|
53
|
+
return true;
|
|
54
|
+
}
|
|
55
|
+
return false;
|
|
56
|
+
}
|
|
57
|
+
}, {
|
|
58
|
+
key: "ignoreMutation",
|
|
59
|
+
value: function ignoreMutation(record) {
|
|
60
|
+
if (typeof this.getPos !== 'function' || record.type !== 'selection') {
|
|
61
|
+
return true;
|
|
62
|
+
}
|
|
63
|
+
var view = this.view,
|
|
64
|
+
node = this.node;
|
|
65
|
+
var placeholderStartPosition = this.getPos();
|
|
66
|
+
if (typeof placeholderStartPosition !== 'number') {
|
|
67
|
+
return false;
|
|
68
|
+
}
|
|
69
|
+
var placeholderEndPosition = placeholderStartPosition + node.nodeSize;
|
|
70
|
+
var selection = view.state.selection;
|
|
71
|
+
|
|
72
|
+
// when the selection is set right after the placeholder.
|
|
73
|
+
// we should let ProseMirror deal with this edge-case
|
|
74
|
+
if (selection.from === placeholderEndPosition) {
|
|
75
|
+
return false;
|
|
76
|
+
}
|
|
77
|
+
var isSelectionAtPlaceholder = selection.from === placeholderStartPosition;
|
|
78
|
+
var isSelectionAfterlaceholder = selection.from > placeholderEndPosition;
|
|
79
|
+
if (isSelectionAtPlaceholder || isSelectionAfterlaceholder) {
|
|
80
|
+
var tr = view.state.tr;
|
|
81
|
+
tr.setSelection(_state.Selection.near(tr.doc.resolve(placeholderEndPosition)));
|
|
82
|
+
view.dispatch(tr);
|
|
83
|
+
return true;
|
|
84
|
+
}
|
|
85
|
+
return true;
|
|
86
|
+
}
|
|
87
|
+
}]);
|
|
88
|
+
return PlaceholderTextNodeView;
|
|
89
|
+
}();
|
|
@@ -0,0 +1,270 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.createPlugin = createPlugin;
|
|
8
|
+
exports.default = void 0;
|
|
9
|
+
var _react = _interopRequireDefault(require("react"));
|
|
10
|
+
var _adfSchema = require("@atlaskit/adf-schema");
|
|
11
|
+
var _analytics = require("@atlaskit/editor-common/analytics");
|
|
12
|
+
var _hooks = require("@atlaskit/editor-common/hooks");
|
|
13
|
+
var _messages = require("@atlaskit/editor-common/messages");
|
|
14
|
+
var _safePlugin = require("@atlaskit/editor-common/safe-plugin");
|
|
15
|
+
var _utils = require("@atlaskit/editor-common/utils");
|
|
16
|
+
var _state = require("@atlaskit/editor-prosemirror/state");
|
|
17
|
+
var _text = _interopRequireDefault(require("@atlaskit/icon/glyph/media-services/text"));
|
|
18
|
+
var _actions = require("./actions");
|
|
19
|
+
var _cursor = require("./fake-text-cursor/cursor");
|
|
20
|
+
var _placeholderTextNodeview = require("./placeholder-text-nodeview");
|
|
21
|
+
var _pluginKey = require("./plugin-key");
|
|
22
|
+
var _selectionUtils = require("./selection-utils");
|
|
23
|
+
var _PlaceholderFloatingToolbar = _interopRequireDefault(require("./ui/PlaceholderFloatingToolbar"));
|
|
24
|
+
var getOpenTypeAhead = function getOpenTypeAhead(trigger, api) {
|
|
25
|
+
var _api$typeAhead, _api$typeAhead2;
|
|
26
|
+
var typeAheadHandler = api === null || api === void 0 || (_api$typeAhead = api.typeAhead) === null || _api$typeAhead === void 0 || (_api$typeAhead = _api$typeAhead.actions) === null || _api$typeAhead === void 0 ? void 0 : _api$typeAhead.findHandlerByTrigger(trigger);
|
|
27
|
+
if (!typeAheadHandler || !typeAheadHandler.id) {
|
|
28
|
+
return null;
|
|
29
|
+
}
|
|
30
|
+
return api === null || api === void 0 || (_api$typeAhead2 = api.typeAhead) === null || _api$typeAhead2 === void 0 || (_api$typeAhead2 = _api$typeAhead2.actions) === null || _api$typeAhead2 === void 0 ? void 0 : _api$typeAhead2.openAtTransaction({
|
|
31
|
+
triggerHandler: typeAheadHandler,
|
|
32
|
+
inputMethod: _analytics.INPUT_METHOD.KEYBOARD
|
|
33
|
+
});
|
|
34
|
+
};
|
|
35
|
+
function createPlugin(dispatch, options, api) {
|
|
36
|
+
var allowInserting = !!options.allowInserting;
|
|
37
|
+
return new _safePlugin.SafePlugin({
|
|
38
|
+
key: _pluginKey.pluginKey,
|
|
39
|
+
state: {
|
|
40
|
+
init: function init() {
|
|
41
|
+
return {
|
|
42
|
+
showInsertPanelAt: null,
|
|
43
|
+
allowInserting: allowInserting
|
|
44
|
+
};
|
|
45
|
+
},
|
|
46
|
+
apply: function apply(tr, state) {
|
|
47
|
+
var meta = tr.getMeta(_pluginKey.pluginKey);
|
|
48
|
+
if (meta && meta.showInsertPanelAt !== undefined) {
|
|
49
|
+
var newState = {
|
|
50
|
+
showInsertPanelAt: meta.showInsertPanelAt,
|
|
51
|
+
allowInserting: allowInserting
|
|
52
|
+
};
|
|
53
|
+
dispatch(_pluginKey.pluginKey, newState);
|
|
54
|
+
return newState;
|
|
55
|
+
} else if (state.showInsertPanelAt) {
|
|
56
|
+
var _newState = {
|
|
57
|
+
showInsertPanelAt: tr.mapping.map(state.showInsertPanelAt),
|
|
58
|
+
allowInserting: allowInserting
|
|
59
|
+
};
|
|
60
|
+
dispatch(_pluginKey.pluginKey, _newState);
|
|
61
|
+
return _newState;
|
|
62
|
+
}
|
|
63
|
+
return state;
|
|
64
|
+
}
|
|
65
|
+
},
|
|
66
|
+
appendTransaction: function appendTransaction(transactions, oldState, newState) {
|
|
67
|
+
if (transactions.some(function (txn) {
|
|
68
|
+
return txn.docChanged;
|
|
69
|
+
})) {
|
|
70
|
+
var didPlaceholderExistBeforeTxn = oldState.selection.$head.nodeAfter === newState.selection.$head.nodeAfter;
|
|
71
|
+
var adjacentNode = newState.selection.$head.nodeAfter;
|
|
72
|
+
var adjacentNodePos = newState.selection.$head.pos;
|
|
73
|
+
var placeholderNodeType = newState.schema.nodes.placeholder;
|
|
74
|
+
if (adjacentNode && adjacentNode.type === placeholderNodeType && didPlaceholderExistBeforeTxn) {
|
|
75
|
+
var _$newHead$nodeBefore;
|
|
76
|
+
var $newHead = newState.selection.$head;
|
|
77
|
+
var $oldHead = oldState.selection.$head;
|
|
78
|
+
// Check that cursor has moved forward in the document **and** that there is content before the cursor
|
|
79
|
+
var cursorMoved = $oldHead.pos < $newHead.pos;
|
|
80
|
+
var nodeBeforeHasContent = !(0, _utils.isNodeEmpty)($newHead.nodeBefore);
|
|
81
|
+
var nodeBeforeIsInline = (_$newHead$nodeBefore = $newHead.nodeBefore) === null || _$newHead$nodeBefore === void 0 ? void 0 : _$newHead$nodeBefore.type.isInline;
|
|
82
|
+
if (cursorMoved && (nodeBeforeHasContent || nodeBeforeIsInline)) {
|
|
83
|
+
var _NodeSelection$create = _state.NodeSelection.create(newState.doc, adjacentNodePos),
|
|
84
|
+
$from = _NodeSelection$create.$from,
|
|
85
|
+
$to = _NodeSelection$create.$to;
|
|
86
|
+
return newState.tr.deleteRange($from.pos, $to.pos);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
// Handle Fake Text Cursor for Floating Toolbar
|
|
92
|
+
if (!_pluginKey.pluginKey.getState(oldState).showInsertPanelAt && _pluginKey.pluginKey.getState(newState).showInsertPanelAt) {
|
|
93
|
+
return newState.tr.setSelection(new _cursor.FakeTextCursorSelection(newState.selection.$from));
|
|
94
|
+
}
|
|
95
|
+
if (_pluginKey.pluginKey.getState(oldState).showInsertPanelAt && !_pluginKey.pluginKey.getState(newState).showInsertPanelAt) {
|
|
96
|
+
if (newState.selection instanceof _cursor.FakeTextCursorSelection) {
|
|
97
|
+
return newState.tr.setSelection(new _state.TextSelection(newState.selection.$from));
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
return;
|
|
101
|
+
},
|
|
102
|
+
props: {
|
|
103
|
+
decorations: _cursor.drawFakeTextCursor,
|
|
104
|
+
handleDOMEvents: {
|
|
105
|
+
beforeinput: function beforeinput(view, event) {
|
|
106
|
+
var state = view.state;
|
|
107
|
+
if (event instanceof InputEvent && !event.isComposing && event.inputType === 'insertText' && (0, _selectionUtils.isSelectionAtPlaceholder)(view.state.selection)) {
|
|
108
|
+
event.stopPropagation();
|
|
109
|
+
event.preventDefault();
|
|
110
|
+
var startNodePosition = state.selection.from;
|
|
111
|
+
var content = event.data || '';
|
|
112
|
+
var tr = view.state.tr;
|
|
113
|
+
tr.delete(startNodePosition, startNodePosition + 1);
|
|
114
|
+
var openTypeAhead = getOpenTypeAhead(content, api);
|
|
115
|
+
if (openTypeAhead) {
|
|
116
|
+
openTypeAhead(tr);
|
|
117
|
+
} else {
|
|
118
|
+
tr.insertText(content);
|
|
119
|
+
}
|
|
120
|
+
view.dispatch(tr);
|
|
121
|
+
return true;
|
|
122
|
+
}
|
|
123
|
+
return false;
|
|
124
|
+
}
|
|
125
|
+
},
|
|
126
|
+
nodeViews: {
|
|
127
|
+
placeholder: function placeholder(node, view, getPos) {
|
|
128
|
+
return new _placeholderTextNodeview.PlaceholderTextNodeView(node, view, getPos);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
function ContentComponent(_ref) {
|
|
135
|
+
var editorView = _ref.editorView,
|
|
136
|
+
dependencyApi = _ref.dependencyApi,
|
|
137
|
+
popupsMountPoint = _ref.popupsMountPoint,
|
|
138
|
+
popupsBoundariesElement = _ref.popupsBoundariesElement;
|
|
139
|
+
var _useSharedPluginState = (0, _hooks.useSharedPluginState)(dependencyApi, ['placeholderText']),
|
|
140
|
+
placeholderTextState = _useSharedPluginState.placeholderTextState;
|
|
141
|
+
var insertPlaceholderText = function insertPlaceholderText(value) {
|
|
142
|
+
return (0, _actions.insertPlaceholderTextAtSelection)(value)(editorView.state, editorView.dispatch);
|
|
143
|
+
};
|
|
144
|
+
var hidePlaceholderToolbar = function hidePlaceholderToolbar() {
|
|
145
|
+
return (0, _actions.hidePlaceholderFloatingToolbar)(editorView.state, editorView.dispatch);
|
|
146
|
+
};
|
|
147
|
+
var getNodeFromPos = function getNodeFromPos(pos) {
|
|
148
|
+
return editorView.domAtPos(pos).node;
|
|
149
|
+
};
|
|
150
|
+
var getFixedCoordinatesFromPos = function getFixedCoordinatesFromPos(pos) {
|
|
151
|
+
return editorView.coordsAtPos(pos);
|
|
152
|
+
};
|
|
153
|
+
var setFocusInEditor = function setFocusInEditor() {
|
|
154
|
+
return editorView.focus();
|
|
155
|
+
};
|
|
156
|
+
if (placeholderTextState !== null && placeholderTextState !== void 0 && placeholderTextState.showInsertPanelAt) {
|
|
157
|
+
return /*#__PURE__*/_react.default.createElement(_PlaceholderFloatingToolbar.default, {
|
|
158
|
+
editorViewDOM: editorView.dom,
|
|
159
|
+
popupsMountPoint: popupsMountPoint,
|
|
160
|
+
popupsBoundariesElement: popupsBoundariesElement,
|
|
161
|
+
getFixedCoordinatesFromPos: getFixedCoordinatesFromPos,
|
|
162
|
+
getNodeFromPos: getNodeFromPos,
|
|
163
|
+
hidePlaceholderFloatingToolbar: hidePlaceholderToolbar,
|
|
164
|
+
showInsertPanelAt: placeholderTextState.showInsertPanelAt,
|
|
165
|
+
insertPlaceholder: insertPlaceholderText,
|
|
166
|
+
setFocusInEditor: setFocusInEditor
|
|
167
|
+
});
|
|
168
|
+
}
|
|
169
|
+
return null;
|
|
170
|
+
}
|
|
171
|
+
var basePlaceholderTextPlugin = function basePlaceholderTextPlugin(_ref2) {
|
|
172
|
+
var api = _ref2.api,
|
|
173
|
+
options = _ref2.config;
|
|
174
|
+
return {
|
|
175
|
+
name: 'placeholderText',
|
|
176
|
+
nodes: function nodes() {
|
|
177
|
+
return [{
|
|
178
|
+
name: 'placeholder',
|
|
179
|
+
node: _adfSchema.placeholder
|
|
180
|
+
}];
|
|
181
|
+
},
|
|
182
|
+
pmPlugins: function pmPlugins() {
|
|
183
|
+
return [{
|
|
184
|
+
name: 'placeholderText',
|
|
185
|
+
plugin: function plugin(_ref3) {
|
|
186
|
+
var dispatch = _ref3.dispatch;
|
|
187
|
+
return createPlugin(dispatch, options, api);
|
|
188
|
+
}
|
|
189
|
+
}];
|
|
190
|
+
},
|
|
191
|
+
actions: {
|
|
192
|
+
showPlaceholderFloatingToolbar: _actions.showPlaceholderFloatingToolbar
|
|
193
|
+
},
|
|
194
|
+
getSharedState: function getSharedState(editorState) {
|
|
195
|
+
if (!editorState) {
|
|
196
|
+
return undefined;
|
|
197
|
+
}
|
|
198
|
+
var _ref4 = _pluginKey.pluginKey.getState(editorState) || {
|
|
199
|
+
showInsertPanelAt: null
|
|
200
|
+
},
|
|
201
|
+
showInsertPanelAt = _ref4.showInsertPanelAt,
|
|
202
|
+
allowInserting = _ref4.allowInserting;
|
|
203
|
+
return {
|
|
204
|
+
showInsertPanelAt: showInsertPanelAt,
|
|
205
|
+
allowInserting: !!allowInserting
|
|
206
|
+
};
|
|
207
|
+
},
|
|
208
|
+
contentComponent: function contentComponent(_ref5) {
|
|
209
|
+
var editorView = _ref5.editorView,
|
|
210
|
+
popupsMountPoint = _ref5.popupsMountPoint,
|
|
211
|
+
popupsBoundariesElement = _ref5.popupsBoundariesElement;
|
|
212
|
+
return /*#__PURE__*/_react.default.createElement(ContentComponent, {
|
|
213
|
+
editorView: editorView,
|
|
214
|
+
popupsMountPoint: popupsMountPoint,
|
|
215
|
+
popupsBoundariesElement: popupsBoundariesElement,
|
|
216
|
+
dependencyApi: api
|
|
217
|
+
});
|
|
218
|
+
}
|
|
219
|
+
};
|
|
220
|
+
};
|
|
221
|
+
var decorateWithPluginOptions = function decorateWithPluginOptions(plugin, options, api) {
|
|
222
|
+
if (!options.allowInserting) {
|
|
223
|
+
return plugin;
|
|
224
|
+
}
|
|
225
|
+
plugin.pluginsOptions = {
|
|
226
|
+
quickInsert: function quickInsert(_ref6) {
|
|
227
|
+
var formatMessage = _ref6.formatMessage;
|
|
228
|
+
return [{
|
|
229
|
+
id: 'placeholderText',
|
|
230
|
+
title: formatMessage(_messages.toolbarInsertBlockMessages.placeholderText),
|
|
231
|
+
description: formatMessage(_messages.toolbarInsertBlockMessages.placeholderTextDescription),
|
|
232
|
+
priority: 1400,
|
|
233
|
+
keywords: ['placeholder'],
|
|
234
|
+
icon: function icon() {
|
|
235
|
+
return /*#__PURE__*/_react.default.createElement(_text.default, {
|
|
236
|
+
label: ""
|
|
237
|
+
});
|
|
238
|
+
},
|
|
239
|
+
action: function action(insert, state) {
|
|
240
|
+
var _api$analytics;
|
|
241
|
+
var tr = state.tr;
|
|
242
|
+
tr.setMeta(_pluginKey.pluginKey, {
|
|
243
|
+
showInsertPanelAt: tr.selection.anchor
|
|
244
|
+
});
|
|
245
|
+
api === null || api === void 0 || (_api$analytics = api.analytics) === null || _api$analytics === void 0 || _api$analytics.actions.attachAnalyticsEvent({
|
|
246
|
+
action: _analytics.ACTION.INSERTED,
|
|
247
|
+
actionSubject: _analytics.ACTION_SUBJECT.DOCUMENT,
|
|
248
|
+
actionSubjectId: _analytics.ACTION_SUBJECT_ID.PLACEHOLDER_TEXT,
|
|
249
|
+
attributes: {
|
|
250
|
+
inputMethod: _analytics.INPUT_METHOD.QUICK_INSERT
|
|
251
|
+
},
|
|
252
|
+
eventType: _analytics.EVENT_TYPE.TRACK
|
|
253
|
+
})(tr);
|
|
254
|
+
return tr;
|
|
255
|
+
}
|
|
256
|
+
}];
|
|
257
|
+
}
|
|
258
|
+
};
|
|
259
|
+
return plugin;
|
|
260
|
+
};
|
|
261
|
+
var placeholderTextPlugin = function placeholderTextPlugin(_ref7) {
|
|
262
|
+
var _ref7$config = _ref7.config,
|
|
263
|
+
options = _ref7$config === void 0 ? {} : _ref7$config,
|
|
264
|
+
api = _ref7.api;
|
|
265
|
+
return decorateWithPluginOptions(basePlaceholderTextPlugin({
|
|
266
|
+
config: options,
|
|
267
|
+
api: api
|
|
268
|
+
}), options, api);
|
|
269
|
+
};
|
|
270
|
+
var _default = exports.default = placeholderTextPlugin;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.isSelectionAtPlaceholder = void 0;
|
|
7
|
+
var _state = require("@atlaskit/editor-prosemirror/state");
|
|
8
|
+
var isSelectionAtPlaceholder = exports.isSelectionAtPlaceholder = function isSelectionAtPlaceholder(selection) {
|
|
9
|
+
if (!(selection instanceof _state.TextSelection) || !selection.$cursor) {
|
|
10
|
+
return false;
|
|
11
|
+
}
|
|
12
|
+
var node = selection.$cursor.doc.nodeAt(selection.$cursor.pos);
|
|
13
|
+
return (node === null || node === void 0 ? void 0 : node.type.name) === 'placeholder';
|
|
14
|
+
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.placeholderTextStyles = void 0;
|
|
8
|
+
var _taggedTemplateLiteral2 = _interopRequireDefault(require("@babel/runtime/helpers/taggedTemplateLiteral"));
|
|
9
|
+
var _react = require("@emotion/react");
|
|
10
|
+
var _editorSharedStyles = require("@atlaskit/editor-shared-styles");
|
|
11
|
+
var _colors = require("@atlaskit/theme/colors");
|
|
12
|
+
var _templateObject;
|
|
13
|
+
var placeholderTextStyles = exports.placeholderTextStyles = (0, _react.css)(_templateObject || (_templateObject = (0, _taggedTemplateLiteral2.default)(["\n .ProseMirror span[data-placeholder] {\n color: ", ";\n display: inline;\n }\n\n .ProseMirror span.pm-placeholder {\n display: inline;\n color: ", ";\n }\n .ProseMirror span.pm-placeholder__text {\n display: inline;\n color: ", ";\n }\n\n .ProseMirror span.pm-placeholder.", " {\n ", "\n }\n\n .ProseMirror span.pm-placeholder__text[data-placeholder]::after {\n color: ", ";\n cursor: text;\n content: attr(data-placeholder);\n display: inline;\n }\n\n .ProseMirror {\n .ProseMirror-fake-text-cursor {\n display: inline;\n pointer-events: none;\n position: relative;\n }\n\n .ProseMirror-fake-text-cursor::after {\n content: '';\n display: inline;\n top: 0;\n position: absolute;\n border-right: 1px solid ", ";\n }\n\n .ProseMirror-fake-text-selection {\n display: inline;\n pointer-events: none;\n position: relative;\n background-color: ", ";\n }\n }\n"])), "var(--ds-text-subtlest, ".concat(_colors.N200, ")"), "var(--ds-text-subtlest, ".concat(_colors.N200, ")"), "var(--ds-text-subtlest, ".concat(_colors.N200, ")"), _editorSharedStyles.akEditorSelectedNodeClassName, (0, _editorSharedStyles.getSelectionStyles)([_editorSharedStyles.SelectionStyle.Background]), "var(--ds-text-subtlest, ".concat(_colors.N200, ")"), "var(--ds-border, rgba(0, 0, 0, 0.4))", "var(--ds-background-selected, ".concat(_colors.B75, ")"));
|