@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
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.default = void 0;
|
|
8
|
+
Object.defineProperty(exports, "getNearestNonTextNode", {
|
|
9
|
+
enumerable: true,
|
|
10
|
+
get: function get() {
|
|
11
|
+
return _utils.getNearestNonTextNode;
|
|
12
|
+
}
|
|
13
|
+
});
|
|
14
|
+
Object.defineProperty(exports, "getOffsetParent", {
|
|
15
|
+
enumerable: true,
|
|
16
|
+
get: function get() {
|
|
17
|
+
return _utils.getOffsetParent;
|
|
18
|
+
}
|
|
19
|
+
});
|
|
20
|
+
Object.defineProperty(exports, "handlePositionCalculatedWith", {
|
|
21
|
+
enumerable: true,
|
|
22
|
+
get: function get() {
|
|
23
|
+
return _utils.handlePositionCalculatedWith;
|
|
24
|
+
}
|
|
25
|
+
});
|
|
26
|
+
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
|
|
27
|
+
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
|
|
28
|
+
var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
|
|
29
|
+
var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn"));
|
|
30
|
+
var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));
|
|
31
|
+
var _react = require("react");
|
|
32
|
+
var _react2 = require("@emotion/react");
|
|
33
|
+
var _ui = require("@atlaskit/editor-common/ui");
|
|
34
|
+
var _styles = require("./styles");
|
|
35
|
+
var _utils = require("./utils");
|
|
36
|
+
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); }; }
|
|
37
|
+
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; } } /* eslint-disable @atlaskit/design-system/prefer-primitives */ /** @jsx jsx */
|
|
38
|
+
// eslint-disable-next-line @repo/internal/react/no-class-components
|
|
39
|
+
var FloatingToolbar = exports.default = /*#__PURE__*/function (_PureComponent) {
|
|
40
|
+
(0, _inherits2.default)(FloatingToolbar, _PureComponent);
|
|
41
|
+
var _super = _createSuper(FloatingToolbar);
|
|
42
|
+
function FloatingToolbar() {
|
|
43
|
+
(0, _classCallCheck2.default)(this, FloatingToolbar);
|
|
44
|
+
return _super.apply(this, arguments);
|
|
45
|
+
}
|
|
46
|
+
(0, _createClass2.default)(FloatingToolbar, [{
|
|
47
|
+
key: "render",
|
|
48
|
+
value: function render() {
|
|
49
|
+
var _this$props = this.props,
|
|
50
|
+
children = _this$props.children,
|
|
51
|
+
target = _this$props.target,
|
|
52
|
+
offset = _this$props.offset,
|
|
53
|
+
fitWidth = _this$props.fitWidth,
|
|
54
|
+
_this$props$fitHeight = _this$props.fitHeight,
|
|
55
|
+
fitHeight = _this$props$fitHeight === void 0 ? 40 : _this$props$fitHeight,
|
|
56
|
+
onPositionCalculated = _this$props.onPositionCalculated,
|
|
57
|
+
popupsMountPoint = _this$props.popupsMountPoint,
|
|
58
|
+
popupsBoundariesElement = _this$props.popupsBoundariesElement,
|
|
59
|
+
className = _this$props.className,
|
|
60
|
+
absoluteOffset = _this$props.absoluteOffset,
|
|
61
|
+
alignX = _this$props.alignX,
|
|
62
|
+
alignY = _this$props.alignY,
|
|
63
|
+
zIndex = _this$props.zIndex;
|
|
64
|
+
if (!target) {
|
|
65
|
+
return null;
|
|
66
|
+
}
|
|
67
|
+
return (0, _react2.jsx)(_ui.Popup, {
|
|
68
|
+
absoluteOffset: absoluteOffset,
|
|
69
|
+
alignX: alignX,
|
|
70
|
+
alignY: alignY,
|
|
71
|
+
target: target,
|
|
72
|
+
zIndex: zIndex,
|
|
73
|
+
mountTo: popupsMountPoint,
|
|
74
|
+
boundariesElement: popupsBoundariesElement,
|
|
75
|
+
offset: offset,
|
|
76
|
+
fitWidth: fitWidth,
|
|
77
|
+
fitHeight: fitHeight,
|
|
78
|
+
onPositionCalculated: onPositionCalculated
|
|
79
|
+
}, (0, _react2.jsx)("div", {
|
|
80
|
+
// eslint-disable-next-line @atlaskit/design-system/consistent-css-prop-usage
|
|
81
|
+
css: (0, _styles.container)(fitHeight),
|
|
82
|
+
"data-testid": "popup-container",
|
|
83
|
+
className: className
|
|
84
|
+
}, children));
|
|
85
|
+
}
|
|
86
|
+
}]);
|
|
87
|
+
return FloatingToolbar;
|
|
88
|
+
}(_react.PureComponent);
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.container = void 0;
|
|
8
|
+
var _taggedTemplateLiteral2 = _interopRequireDefault(require("@babel/runtime/helpers/taggedTemplateLiteral"));
|
|
9
|
+
var _react = require("@emotion/react");
|
|
10
|
+
var _colors = require("@atlaskit/theme/colors");
|
|
11
|
+
var _constants = require("@atlaskit/theme/constants");
|
|
12
|
+
var _templateObject, _templateObject2;
|
|
13
|
+
var container = exports.container = function container(height) {
|
|
14
|
+
return (0, _react.css)(_templateObject || (_templateObject = (0, _taggedTemplateLiteral2.default)(["\n border-radius: ", "px;\n box-shadow: ", ";\n display: flex;\n align-items: center;\n box-sizing: border-box;\n padding: ", " ", ";\n background-color: ", ";\n ", ";\n"])), (0, _constants.borderRadius)(), "var(--ds-shadow-overlay, ".concat("0 12px 24px -6px ".concat(_colors.N50A, ", 0 0 1px ").concat(_colors.N60A), ")"), "var(--ds-space-050, 4px)", "var(--ds-space-100, 8px)", "var(--ds-background-input, ".concat(_colors.N0, ")"), height ? (0, _react.css)(_templateObject2 || (_templateObject2 = (0, _taggedTemplateLiteral2.default)(["\n height: ", "px;\n "])), height) : '');
|
|
15
|
+
};
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.handlePositionCalculatedWith = exports.getOffsetParent = exports.getNearestNonTextNode = void 0;
|
|
7
|
+
var getCursorHeightFrom = function getCursorHeightFrom(node) {
|
|
8
|
+
return parseFloat(window.getComputedStyle(node, undefined).lineHeight || '');
|
|
9
|
+
};
|
|
10
|
+
var getOffsetParent = exports.getOffsetParent = function getOffsetParent(editorViewDom, popupsMountPoint) {
|
|
11
|
+
return popupsMountPoint ? popupsMountPoint.offsetParent : editorViewDom.offsetParent;
|
|
12
|
+
};
|
|
13
|
+
var getNearestNonTextNode = exports.getNearestNonTextNode = function getNearestNonTextNode(node) {
|
|
14
|
+
return node.nodeType === Node.TEXT_NODE ? node.parentNode : node;
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* We need to translate the co-ordinates because `coordsAtPos` returns co-ordinates
|
|
19
|
+
* relative to `window`. And, also need to adjust the cursor container height.
|
|
20
|
+
* (0, 0)
|
|
21
|
+
* +--------------------- [window] ---------------------+
|
|
22
|
+
* | (left, top) +-------- [Offset Parent] --------+ |
|
|
23
|
+
* | {coordsAtPos} | [Cursor] <- cursorHeight | |
|
|
24
|
+
* | | [FloatingToolbar] | |
|
|
25
|
+
*/
|
|
26
|
+
var convertFixedCoordinatesToAbsolutePositioning = function convertFixedCoordinatesToAbsolutePositioning(coordinates, offsetParent, cursorHeight) {
|
|
27
|
+
var _coordinates$left, _coordinates$right, _coordinates$top, _coordinates$top2;
|
|
28
|
+
var _offsetParent$getBoun = offsetParent.getBoundingClientRect(),
|
|
29
|
+
offsetParentLeft = _offsetParent$getBoun.left,
|
|
30
|
+
offsetParentTop = _offsetParent$getBoun.top,
|
|
31
|
+
offsetParentHeight = _offsetParent$getBoun.height;
|
|
32
|
+
return {
|
|
33
|
+
left: ((_coordinates$left = coordinates.left) !== null && _coordinates$left !== void 0 ? _coordinates$left : 0) - offsetParentLeft,
|
|
34
|
+
right: ((_coordinates$right = coordinates.right) !== null && _coordinates$right !== void 0 ? _coordinates$right : 0) - offsetParentLeft,
|
|
35
|
+
top: ((_coordinates$top = coordinates.top) !== null && _coordinates$top !== void 0 ? _coordinates$top : 0) - (offsetParentTop - cursorHeight) + offsetParent.scrollTop,
|
|
36
|
+
bottom: offsetParentHeight - (((_coordinates$top2 = coordinates.top) !== null && _coordinates$top2 !== void 0 ? _coordinates$top2 : 0) - (offsetParentTop - cursorHeight) - offsetParent.scrollTop)
|
|
37
|
+
};
|
|
38
|
+
};
|
|
39
|
+
var handlePositionCalculatedWith = exports.handlePositionCalculatedWith = function handlePositionCalculatedWith(offsetParent, node, getCurrentFixedCoordinates) {
|
|
40
|
+
return function (position) {
|
|
41
|
+
if (!offsetParent) {
|
|
42
|
+
return position;
|
|
43
|
+
}
|
|
44
|
+
var target = getNearestNonTextNode(node);
|
|
45
|
+
var cursorHeight = getCursorHeightFrom(target);
|
|
46
|
+
var fixedCoordinates = getCurrentFixedCoordinates();
|
|
47
|
+
var absoluteCoordinates = convertFixedCoordinatesToAbsolutePositioning(fixedCoordinates, offsetParent, cursorHeight);
|
|
48
|
+
return {
|
|
49
|
+
left: position.left ? absoluteCoordinates.left : undefined,
|
|
50
|
+
right: position.right ? absoluteCoordinates.right : undefined,
|
|
51
|
+
top: position.top ? absoluteCoordinates.top : undefined,
|
|
52
|
+
bottom: position.bottom ? absoluteCoordinates.bottom : undefined
|
|
53
|
+
};
|
|
54
|
+
};
|
|
55
|
+
};
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
var _typeof = require("@babel/runtime/helpers/typeof");
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports.messages = exports.default = void 0;
|
|
9
|
+
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
|
|
10
|
+
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
|
|
11
|
+
var _assertThisInitialized2 = _interopRequireDefault(require("@babel/runtime/helpers/assertThisInitialized"));
|
|
12
|
+
var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
|
|
13
|
+
var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn"));
|
|
14
|
+
var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));
|
|
15
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
16
|
+
var _react = _interopRequireDefault(require("react"));
|
|
17
|
+
var _reactIntlNext = require("react-intl-next");
|
|
18
|
+
var _ui = require("@atlaskit/editor-common/ui");
|
|
19
|
+
var _FloatingToolbar = _interopRequireWildcard(require("../FloatingToolbar"));
|
|
20
|
+
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
21
|
+
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
22
|
+
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); }; }
|
|
23
|
+
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; } }
|
|
24
|
+
var messages = exports.messages = (0, _reactIntlNext.defineMessages)({
|
|
25
|
+
placeholderTextPlaceholder: {
|
|
26
|
+
id: 'fabric.editor.placeholderTextPlaceholder',
|
|
27
|
+
defaultMessage: 'Add placeholder text',
|
|
28
|
+
description: ''
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
// eslint-disable-next-line @repo/internal/react/no-class-components
|
|
32
|
+
var PlaceholderFloatingToolbar = /*#__PURE__*/function (_React$Component) {
|
|
33
|
+
(0, _inherits2.default)(PlaceholderFloatingToolbar, _React$Component);
|
|
34
|
+
var _super = _createSuper(PlaceholderFloatingToolbar);
|
|
35
|
+
function PlaceholderFloatingToolbar() {
|
|
36
|
+
var _this;
|
|
37
|
+
(0, _classCallCheck2.default)(this, PlaceholderFloatingToolbar);
|
|
38
|
+
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
39
|
+
args[_key] = arguments[_key];
|
|
40
|
+
}
|
|
41
|
+
_this = _super.call.apply(_super, [this].concat(args));
|
|
42
|
+
(0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "handleSubmit", function (value) {
|
|
43
|
+
if (value) {
|
|
44
|
+
_this.props.insertPlaceholder(value);
|
|
45
|
+
_this.props.setFocusInEditor();
|
|
46
|
+
} else {
|
|
47
|
+
_this.props.hidePlaceholderFloatingToolbar();
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
(0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "handleBlur", function () {
|
|
51
|
+
_this.props.hidePlaceholderFloatingToolbar();
|
|
52
|
+
});
|
|
53
|
+
return _this;
|
|
54
|
+
}
|
|
55
|
+
(0, _createClass2.default)(PlaceholderFloatingToolbar, [{
|
|
56
|
+
key: "render",
|
|
57
|
+
value: function render() {
|
|
58
|
+
var _this$props = this.props,
|
|
59
|
+
getNodeFromPos = _this$props.getNodeFromPos,
|
|
60
|
+
showInsertPanelAt = _this$props.showInsertPanelAt,
|
|
61
|
+
editorViewDOM = _this$props.editorViewDOM,
|
|
62
|
+
popupsMountPoint = _this$props.popupsMountPoint,
|
|
63
|
+
getFixedCoordinatesFromPos = _this$props.getFixedCoordinatesFromPos,
|
|
64
|
+
popupsBoundariesElement = _this$props.popupsBoundariesElement,
|
|
65
|
+
formatMessage = _this$props.intl.formatMessage;
|
|
66
|
+
var target = getNodeFromPos(showInsertPanelAt);
|
|
67
|
+
var offsetParent = (0, _FloatingToolbar.getOffsetParent)(editorViewDOM, popupsMountPoint);
|
|
68
|
+
var getFixedCoordinates = function getFixedCoordinates() {
|
|
69
|
+
return getFixedCoordinatesFromPos(showInsertPanelAt);
|
|
70
|
+
};
|
|
71
|
+
var handlePositionCalculated = (0, _FloatingToolbar.handlePositionCalculatedWith)(offsetParent, target, getFixedCoordinates);
|
|
72
|
+
return /*#__PURE__*/_react.default.createElement(_FloatingToolbar.default, {
|
|
73
|
+
target: (0, _FloatingToolbar.getNearestNonTextNode)(target),
|
|
74
|
+
onPositionCalculated: handlePositionCalculated,
|
|
75
|
+
popupsMountPoint: popupsMountPoint,
|
|
76
|
+
popupsBoundariesElement: popupsBoundariesElement,
|
|
77
|
+
fitHeight: 32,
|
|
78
|
+
offset: [0, 12]
|
|
79
|
+
}, /*#__PURE__*/_react.default.createElement(_ui.PanelTextInput, {
|
|
80
|
+
placeholder: formatMessage(messages.placeholderTextPlaceholder),
|
|
81
|
+
onSubmit: this.handleSubmit,
|
|
82
|
+
onBlur: this.handleBlur,
|
|
83
|
+
autoFocus: true,
|
|
84
|
+
width: 300
|
|
85
|
+
}));
|
|
86
|
+
}
|
|
87
|
+
}]);
|
|
88
|
+
return PlaceholderFloatingToolbar;
|
|
89
|
+
}(_react.default.Component);
|
|
90
|
+
var _default = exports.default = (0, _reactIntlNext.injectIntl)(PlaceholderFloatingToolbar);
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { pluginKey } from './plugin-key';
|
|
2
|
+
export const showPlaceholderFloatingToolbar = (state, dispatch) => {
|
|
3
|
+
const tr = state.tr;
|
|
4
|
+
if (!state.selection.empty) {
|
|
5
|
+
tr.deleteSelection();
|
|
6
|
+
}
|
|
7
|
+
tr.setMeta(pluginKey, {
|
|
8
|
+
showInsertPanelAt: tr.selection.anchor
|
|
9
|
+
});
|
|
10
|
+
tr.scrollIntoView();
|
|
11
|
+
dispatch(tr);
|
|
12
|
+
return true;
|
|
13
|
+
};
|
|
14
|
+
export const insertPlaceholderTextAtSelection = value => (state, dispatch) => {
|
|
15
|
+
dispatch(state.tr.replaceSelectionWith(state.schema.nodes.placeholder.createChecked({
|
|
16
|
+
text: value
|
|
17
|
+
})).setMeta(pluginKey, {
|
|
18
|
+
showInsertPanelAt: null
|
|
19
|
+
}).scrollIntoView());
|
|
20
|
+
return true;
|
|
21
|
+
};
|
|
22
|
+
export const hidePlaceholderFloatingToolbar = (state, dispatch) => {
|
|
23
|
+
dispatch(state.tr.setMeta(pluginKey, {
|
|
24
|
+
showInsertPanelAt: null
|
|
25
|
+
}));
|
|
26
|
+
return true;
|
|
27
|
+
};
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
2
|
+
import { Slice } from '@atlaskit/editor-prosemirror/model';
|
|
3
|
+
import { Selection, TextSelection } from '@atlaskit/editor-prosemirror/state';
|
|
4
|
+
import { Decoration, DecorationSet } from '@atlaskit/editor-prosemirror/view';
|
|
5
|
+
export class FakeTextCursorBookmark {
|
|
6
|
+
constructor(pos) {
|
|
7
|
+
_defineProperty(this, "pos", undefined);
|
|
8
|
+
_defineProperty(this, "visible", false);
|
|
9
|
+
this.pos = pos;
|
|
10
|
+
}
|
|
11
|
+
map(mapping) {
|
|
12
|
+
return new FakeTextCursorBookmark(mapping.map(this.pos));
|
|
13
|
+
}
|
|
14
|
+
resolve(doc) {
|
|
15
|
+
const $pos = doc.resolve(this.pos);
|
|
16
|
+
return Selection.near($pos);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
export class FakeTextCursorSelection extends Selection {
|
|
20
|
+
constructor($pos) {
|
|
21
|
+
super($pos, $pos);
|
|
22
|
+
}
|
|
23
|
+
map(doc, mapping) {
|
|
24
|
+
const $pos = doc.resolve(mapping.map(this.$head.pos));
|
|
25
|
+
return new FakeTextCursorSelection($pos);
|
|
26
|
+
}
|
|
27
|
+
static content() {
|
|
28
|
+
return Slice.empty;
|
|
29
|
+
}
|
|
30
|
+
eq(other) {
|
|
31
|
+
return other instanceof FakeTextCursorSelection && other.head === this.head;
|
|
32
|
+
}
|
|
33
|
+
toJSON() {
|
|
34
|
+
return {
|
|
35
|
+
type: 'Cursor',
|
|
36
|
+
pos: this.head
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
static fromJSON(doc, json) {
|
|
40
|
+
return new FakeTextCursorSelection(doc.resolve(json.pos));
|
|
41
|
+
}
|
|
42
|
+
getBookmark() {
|
|
43
|
+
return new FakeTextCursorBookmark(this.anchor);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
Selection.jsonID('fake-text-cursor', FakeTextCursorSelection);
|
|
47
|
+
export const addFakeTextCursor = (state, dispatch) => {
|
|
48
|
+
const {
|
|
49
|
+
selection
|
|
50
|
+
} = state;
|
|
51
|
+
if (selection.empty) {
|
|
52
|
+
const {
|
|
53
|
+
selection: {
|
|
54
|
+
$from
|
|
55
|
+
}
|
|
56
|
+
} = state;
|
|
57
|
+
dispatch(state.tr.setSelection(new FakeTextCursorSelection($from)));
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
export const removeFakeTextCursor = (state, dispatch) => {
|
|
61
|
+
if (state.selection instanceof FakeTextCursorSelection) {
|
|
62
|
+
const {
|
|
63
|
+
$from
|
|
64
|
+
} = state.selection;
|
|
65
|
+
dispatch(state.tr.setSelection(new TextSelection($from)));
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
export const drawFakeTextCursor = state => {
|
|
69
|
+
if (!(state.selection instanceof FakeTextCursorSelection)) {
|
|
70
|
+
return null;
|
|
71
|
+
}
|
|
72
|
+
const node = document.createElement('div');
|
|
73
|
+
node.className = 'ProseMirror-fake-text-cursor';
|
|
74
|
+
return DecorationSet.create(state.doc, [Decoration.widget(state.selection.head, node, {
|
|
75
|
+
key: 'Cursor'
|
|
76
|
+
})]);
|
|
77
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default as placeholderTextPlugin } from './plugin';
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { browser, ZERO_WIDTH_SPACE } from '@atlaskit/editor-common/utils';
|
|
2
|
+
import { Selection } from '@atlaskit/editor-prosemirror/state';
|
|
3
|
+
const serializePlaceholderNode = node => {
|
|
4
|
+
const element = document.createElement('span');
|
|
5
|
+
element.classList.add('pm-placeholder');
|
|
6
|
+
|
|
7
|
+
// the inline node api test suite requires the following class name
|
|
8
|
+
element.classList.add('placeholderView-content-wrap');
|
|
9
|
+
element.innerText = ZERO_WIDTH_SPACE;
|
|
10
|
+
const elementChildren = document.createElement('span');
|
|
11
|
+
elementChildren.classList.add('pm-placeholder__text');
|
|
12
|
+
elementChildren.dataset.placeholder = node.attrs.text;
|
|
13
|
+
elementChildren.setAttribute('contenteditable', 'false');
|
|
14
|
+
element.appendChild(elementChildren);
|
|
15
|
+
if (browser.safari) {
|
|
16
|
+
element.appendChild(document.createTextNode(ZERO_WIDTH_SPACE));
|
|
17
|
+
} else {
|
|
18
|
+
element.appendChild(document.createElement('wbr'));
|
|
19
|
+
}
|
|
20
|
+
return element;
|
|
21
|
+
};
|
|
22
|
+
export class PlaceholderTextNodeView {
|
|
23
|
+
constructor(node, view, getPos) {
|
|
24
|
+
this.node = node;
|
|
25
|
+
this.view = view;
|
|
26
|
+
this.getPos = getPos;
|
|
27
|
+
this.dom = serializePlaceholderNode(this.node);
|
|
28
|
+
this.getPos = getPos;
|
|
29
|
+
}
|
|
30
|
+
stopEvent(e) {
|
|
31
|
+
if (e.type === 'mousedown' && typeof this.getPos === 'function') {
|
|
32
|
+
e.preventDefault();
|
|
33
|
+
const {
|
|
34
|
+
view
|
|
35
|
+
} = this;
|
|
36
|
+
const startNodePosition = this.getPos();
|
|
37
|
+
if (typeof startNodePosition !== 'number') {
|
|
38
|
+
return false;
|
|
39
|
+
}
|
|
40
|
+
const tr = view.state.tr;
|
|
41
|
+
tr.setSelection(Selection.near(tr.doc.resolve(startNodePosition)));
|
|
42
|
+
view.dispatch(tr);
|
|
43
|
+
return true;
|
|
44
|
+
}
|
|
45
|
+
return false;
|
|
46
|
+
}
|
|
47
|
+
ignoreMutation(record) {
|
|
48
|
+
if (typeof this.getPos !== 'function' || record.type !== 'selection') {
|
|
49
|
+
return true;
|
|
50
|
+
}
|
|
51
|
+
const {
|
|
52
|
+
view,
|
|
53
|
+
node
|
|
54
|
+
} = this;
|
|
55
|
+
const placeholderStartPosition = this.getPos();
|
|
56
|
+
if (typeof placeholderStartPosition !== 'number') {
|
|
57
|
+
return false;
|
|
58
|
+
}
|
|
59
|
+
const placeholderEndPosition = placeholderStartPosition + node.nodeSize;
|
|
60
|
+
const selection = view.state.selection;
|
|
61
|
+
|
|
62
|
+
// when the selection is set right after the placeholder.
|
|
63
|
+
// we should let ProseMirror deal with this edge-case
|
|
64
|
+
if (selection.from === placeholderEndPosition) {
|
|
65
|
+
return false;
|
|
66
|
+
}
|
|
67
|
+
const isSelectionAtPlaceholder = selection.from === placeholderStartPosition;
|
|
68
|
+
const isSelectionAfterlaceholder = selection.from > placeholderEndPosition;
|
|
69
|
+
if (isSelectionAtPlaceholder || isSelectionAfterlaceholder) {
|
|
70
|
+
const tr = view.state.tr;
|
|
71
|
+
tr.setSelection(Selection.near(tr.doc.resolve(placeholderEndPosition)));
|
|
72
|
+
view.dispatch(tr);
|
|
73
|
+
return true;
|
|
74
|
+
}
|
|
75
|
+
return true;
|
|
76
|
+
}
|
|
77
|
+
}
|