@titaui/pc 1.10.49 → 1.10.50

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.
@@ -0,0 +1,126 @@
1
+ "use strict";
2
+
3
+ function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
4
+
5
+ Object.defineProperty(exports, "__esModule", {
6
+ value: true
7
+ });
8
+ exports["default"] = exports.PlaceholderPlugin = exports.PlaceholderController = void 0;
9
+
10
+ var _controller = _interopRequireDefault(require("../../../models/controller"));
11
+
12
+ var _prosemirrorState = require("prosemirror-state");
13
+
14
+ var _prosemirrorView = require("prosemirror-view");
15
+
16
+ var _plugin = _interopRequireDefault(require("../../../models/plugin"));
17
+
18
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
19
+
20
+ function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
21
+
22
+ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
23
+
24
+ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
25
+
26
+ function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }
27
+
28
+ function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
29
+
30
+ function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
31
+
32
+ function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); }
33
+
34
+ function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
35
+
36
+ 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; } }
37
+
38
+ function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
39
+
40
+ var PLUGIN_NAME = 'placeholder';
41
+
42
+ var createDecoration = function createDecoration(state) {
43
+ var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '请输入';
44
+ var firstChildType = state.doc.child(0).type;
45
+
46
+ if (state.doc.textContent || firstChildType.name !== 'paragraph' && firstChildType.name !== 'heading' || state.doc.childCount > 1) {
47
+ return _prosemirrorView.DecorationSet.empty;
48
+ }
49
+
50
+ var placeholderDecoration = document.createElement('span');
51
+ var placeholderText = options;
52
+ placeholderDecoration.className = 'tita-rich-editor-placeholder';
53
+ var placeholderNode = document.createElement('span');
54
+ placeholderNode.textContent = placeholderText;
55
+ placeholderDecoration.appendChild(placeholderNode);
56
+ return _prosemirrorView.DecorationSet.create(state.doc, [_prosemirrorView.Decoration.widget(1, placeholderDecoration, {
57
+ side: 1,
58
+ key: 'placeholder'
59
+ })]);
60
+ };
61
+
62
+ var placeHolderPlugin = function placeHolderPlugin(dispatch, options) {
63
+ var plugin = new _prosemirrorState.Plugin({
64
+ state: {
65
+ init: function init(conf, state) {
66
+ return createDecoration(state, options);
67
+ },
68
+ apply: function apply(tr, pluginState, oldState, newState) {
69
+ if (!tr.docChanged) return pluginState.map(tr.mapping, tr.doc);
70
+ return createDecoration(newState, options);
71
+ }
72
+ },
73
+ props: {
74
+ decorations: function decorations(state) {
75
+ return plugin.getState(state);
76
+ }
77
+ }
78
+ });
79
+ return plugin;
80
+ };
81
+
82
+ var PlaceholderController = /*#__PURE__*/function (_BaseController) {
83
+ _inherits(PlaceholderController, _BaseController);
84
+
85
+ var _super = _createSuper(PlaceholderController);
86
+
87
+ function PlaceholderController() {
88
+ var _this;
89
+
90
+ _classCallCheck(this, PlaceholderController);
91
+
92
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
93
+ args[_key] = arguments[_key];
94
+ }
95
+
96
+ return _possibleConstructorReturn(_this, (_this = _super.call.apply(_super, [this].concat(args)), _this.pmPlugins = [placeHolderPlugin], _assertThisInitialized(_this)));
97
+ }
98
+
99
+ return _createClass(PlaceholderController);
100
+ }(_controller["default"]);
101
+
102
+ exports.PlaceholderController = PlaceholderController;
103
+
104
+ var PlaceholderPlugin = /*#__PURE__*/function (_BasePlugin) {
105
+ _inherits(PlaceholderPlugin, _BasePlugin);
106
+
107
+ var _super2 = _createSuper(PlaceholderPlugin);
108
+
109
+ function PlaceholderPlugin() {
110
+ var _this2;
111
+
112
+ _classCallCheck(this, PlaceholderPlugin);
113
+
114
+ for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
115
+ args[_key2] = arguments[_key2];
116
+ }
117
+
118
+ return _possibleConstructorReturn(_this2, (_this2 = _super2.call.apply(_super2, [this].concat(args)), _this2.name = PLUGIN_NAME, _this2.controller = PlaceholderController, _assertThisInitialized(_this2)));
119
+ }
120
+
121
+ return _createClass(PlaceholderPlugin);
122
+ }(_plugin["default"]);
123
+
124
+ exports.PlaceholderPlugin = PlaceholderPlugin;
125
+ var _default = PlaceholderPlugin;
126
+ exports["default"] = _default;
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.placeholderStyles = exports.placeHolderClassName = void 0;
7
+
8
+ var _styledComponents = require("styled-components");
9
+
10
+ var _colors = require("@atlaskit/theme/colors");
11
+
12
+ var _templateObject;
13
+
14
+ function _taggedTemplateLiteral(strings, raw) { if (!raw) { raw = strings.slice(0); } return Object.freeze(Object.defineProperties(strings, { raw: { value: Object.freeze(raw) } })); }
15
+
16
+ var placeHolderClassName = 'placeholder-decoration';
17
+ exports.placeHolderClassName = placeHolderClassName;
18
+ var placeholderStyles = (0, _styledComponents.css)(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n .ProseMirror .", " {\n position: relative;\n color: ", ";\n width: 100%;\n\n pointer-events: none;\n display: block;\n user-select: none;\n\n > span {\n position: absolute;\n pointer-events: none;\n }\n\n &.align-end > span {\n right: 0;\n }\n\n &.align-center > span {\n left: 0;\n }\n }\n"])), placeHolderClassName, _colors.N200);
19
+ exports.placeholderStyles = placeholderStyles;
@@ -8,8 +8,8 @@ var FontColor;
8
8
  exports.FontColor = FontColor;
9
9
 
10
10
  (function (FontColor) {
11
- FontColor["default"] = "#3F4755";
12
- FontColor["black1"] = "#141C28";
11
+ FontColor["default"] = "#141C28";
12
+ FontColor["black1"] = "#3F4755";
13
13
  FontColor["black2"] = "#6F7886";
14
14
  FontColor["black3"] = "#A4ACB9";
15
15
  FontColor["red1"] = "#F02673";
@@ -220,14 +220,7 @@ function ColorSelectorPop(_ref2) {
220
220
  (0, _commond.setColor)(editor, editor.state.schema.marks[_index2.BACKGROUND_COLOR_SCHEMA_NAME], activeBackground);
221
221
  editor.view.focus();
222
222
  }, [activeColor, activeBackground]);
223
- return /*#__PURE__*/_react["default"].createElement("div", {
224
- className: preCls + '__icon',
225
- style: {
226
- backgroundColor: activeBackground || _consts.BackgroundColor["default"],
227
- color: activeColor || _consts.FontColor["default"]
228
- },
229
- onClick: handleClickMenu
230
- }, /*#__PURE__*/_react["default"].createElement(_popup["default"], {
223
+ return /*#__PURE__*/_react["default"].createElement(_popup["default"], {
231
224
  action: ["hover"],
232
225
  popupPlacement: "top",
233
226
  popup: /*#__PURE__*/_react["default"].createElement(ColorSelector, {
@@ -237,6 +230,13 @@ function ColorSelectorPop(_ref2) {
237
230
  background: activeBackground,
238
231
  onClickItem: handleClickItem
239
232
  })
233
+ }, /*#__PURE__*/_react["default"].createElement("div", {
234
+ className: preCls + '__icon',
235
+ style: {
236
+ backgroundColor: activeBackground || _consts.BackgroundColor["default"],
237
+ color: activeColor || _consts.FontColor["default"]
238
+ },
239
+ onClick: handleClickMenu
240
240
  }, /*#__PURE__*/_react["default"].createElement("span", {
241
241
  className: config.icon
242
242
  })));
@@ -26,6 +26,10 @@
26
26
  justify-content: flex-end;
27
27
  }
28
28
 
29
+ .tita-rich-editor-link__input .form-field-input__border {
30
+ padding: 3px 12px;
31
+ }
32
+
29
33
  .tita-rich-editor-link__input:first-child {
30
34
  margin-bottom: 16px;
31
35
  }
@@ -53,6 +57,7 @@
53
57
  box-shadow: 0px 4px 12px 0px rgba(127, 145, 180, 0.2);
54
58
  border-radius: 8px;
55
59
  border: 1px solid #f0f2f5;
60
+ color: #3f4755;
56
61
  }
57
62
 
58
63
  .tita-rich-editor-toolbar__text {
@@ -36,6 +36,7 @@ function applyPlugins() {
36
36
  var plugins = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
37
37
  var defaultSchema = arguments.length > 1 ? arguments[1] : undefined;
38
38
  var dispatcher = arguments.length > 2 ? arguments[2] : undefined;
39
+ var config = arguments.length > 3 ? arguments[3] : undefined;
39
40
  var nodes = defaultSchema.nodes;
40
41
  var marks = defaultSchema.marks || {};
41
42
  var nativePlugins = [];
@@ -48,9 +49,9 @@ function applyPlugins() {
48
49
  }))) : schemas.push(new p.schema());
49
50
  }
50
51
 
51
- dealPlugin(p, nativePlugins, controllers, dispatcher);
52
+ dealPlugin(p, nativePlugins, controllers, dispatcher, config);
52
53
  });
53
- dealPlugin(new _core.CorePlugin(), nativePlugins, controllers, dispatcher);
54
+ dealPlugin(new _core.CorePlugin(), nativePlugins, controllers, dispatcher, config);
54
55
  schemas.sort(function (s1, s2) {
55
56
  return s2.priority - s1.priority;
56
57
  }).forEach(function (s) {
@@ -69,13 +70,15 @@ function applyPlugins() {
69
70
  }
70
71
 
71
72
  function dealPlugin(plugin, nativePlugins, controllers, dispatcher) {
73
+ var config = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : {};
74
+
72
75
  if (plugin.controller) {
73
76
  var pController = new plugin.controller();
74
77
  controllers.push(pController);
75
78
 
76
79
  if (pController.pmPlugins) {
77
80
  nativePlugins.push.apply(nativePlugins, _toConsumableArray(pController.pmPlugins.map(function (pm) {
78
- return typeof pm == 'function' ? pm((0, _event.createDispatch)(dispatcher)) : pm;
81
+ return typeof pm == 'function' ? pm((0, _event.createDispatch)(dispatcher), config[plugin.name]) : pm;
79
82
  })));
80
83
  }
81
84
 
@@ -19,7 +19,7 @@
19
19
  font-weight: 500;
20
20
  color: #141c28;
21
21
  line-height: 38px;
22
- padding: 36px 0 20px;
22
+ padding: 26px 0 10px;
23
23
  }
24
24
 
25
25
  .tita-rich-editor h2 {
@@ -27,23 +27,31 @@
27
27
  font-weight: 500;
28
28
  color: #141c28;
29
29
  line-height: 32px;
30
- padding: 20px 0 8px;
30
+ padding: 22px 0 8px;
31
31
  }
32
32
 
33
33
  .tita-rich-editor h3 {
34
34
  font-size: 20px;
35
35
  font-weight: 500;
36
- color: #3f4755;
36
+ color: #141c28;
37
37
  line-height: 30px;
38
- padding: 18px 0 8px;
38
+ padding: 20px 0 8px;
39
39
  }
40
40
 
41
41
  .tita-rich-editor p {
42
42
  font-size: 16px;
43
43
  font-weight: 400;
44
- color: #3f4755;
44
+ color: #141c28;
45
45
  line-height: 26px;
46
- padding: 6px 0;
46
+ padding: 3px 0;
47
+ }
48
+
49
+ .tita-rich-editor a {
50
+ color: #2879ff;
51
+ }
52
+
53
+ .tita-rich-editor a:hover {
54
+ color: #5c8eff;
47
55
  }
48
56
 
49
57
  .tita-rich-editor ol,
@@ -128,8 +136,20 @@
128
136
 
129
137
  .tita-rich-editor blockquote {
130
138
  position: relative;
139
+ margin: 3px 0;
131
140
  padding-left: 22px;
132
- margin: 0;
141
+ }
142
+
143
+ .tita-rich-editor blockquote p {
144
+ font-size: 16px !important;
145
+ }
146
+
147
+ .tita-rich-editor blockquote p:first-child {
148
+ padding-top: 0;
149
+ }
150
+
151
+ .tita-rich-editor blockquote p:last-child {
152
+ padding-bottom: 0;
133
153
  }
134
154
 
135
155
  .tita-rich-editor blockquote::before {
@@ -142,3 +162,17 @@
142
162
  background-color: #2879ff;
143
163
  border-radius: 2px;
144
164
  }
165
+
166
+ .tita-rich-editor-placeholder {
167
+ color: #bfc7d5;
168
+ position: relative;
169
+ width: 100%;
170
+ pointer-events: none;
171
+ display: block;
172
+ user-select: none;
173
+ }
174
+
175
+ .tita-rich-editor-placeholder > span {
176
+ position: absolute;
177
+ pointer-events: none;
178
+ }
@@ -31,6 +31,8 @@ require("./index.css");
31
31
 
32
32
  var _classnames = _interopRequireDefault(require("classnames"));
33
33
 
34
+ var _placeholder = _interopRequireDefault(require("../../plugins/extension/placeholder"));
35
+
34
36
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
35
37
 
36
38
  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); }
@@ -40,7 +42,7 @@ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj &&
40
42
  function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
41
43
 
42
44
  var preCls = 'tita-rich-editor';
43
- var defaultPlugins = [new _plugins.HeadingPlugin(), new _plugins.StrongPlugin(), new _plugins.ColorPlugin(), new _plugins.UnderLinePlugin(), new _plugins.DeleteLinePlugin(), new _plugins.ListPlugin(), new _plugins.AlignmentPlugin(), new _plugins.BlockquotePlugin(), new _plugins.LinkPlugin()];
45
+ var defaultPlugins = [new _plugins.HeadingPlugin(), new _plugins.StrongPlugin(), new _plugins.ColorPlugin(), new _plugins.UnderLinePlugin(), new _plugins.DeleteLinePlugin(), new _plugins.ListPlugin(), new _plugins.AlignmentPlugin(), new _plugins.BlockquotePlugin(), new _plugins.LinkPlugin(), new _placeholder["default"]()];
44
46
 
45
47
  function RichEditor(_ref, ref) {
46
48
  var _ref$plugins = _ref.plugins,
@@ -49,14 +51,17 @@ function RichEditor(_ref, ref) {
49
51
  _ref$editable = _ref.editable,
50
52
  _editable = _ref$editable === void 0 ? true : _ref$editable,
51
53
  defaultState = _ref.defaultState,
52
- onChange = _ref.onChange;
54
+ onChange = _ref.onChange,
55
+ placeholder = _ref.placeholder;
53
56
 
54
57
  var container = (0, _react.useRef)();
55
58
  var dataRef = (0, _react.useRef)({});
56
59
  (0, _react.useEffect)(function () {
57
60
  var dispatcher = new _event.EventDispatcher();
58
61
 
59
- var _applyPlugins = (0, _util.applyPlugins)(plugins, _schema["default"], dispatcher),
62
+ var _applyPlugins = (0, _util.applyPlugins)(plugins, _schema["default"], dispatcher, {
63
+ placeholder: placeholder
64
+ }),
60
65
  nativePlugins = _applyPlugins.nativePlugins,
61
66
  nodes = _applyPlugins.nodes,
62
67
  marks = _applyPlugins.marks,
@@ -139,7 +144,7 @@ function RichEditor(_ref, ref) {
139
144
  backgroundColor: "#FFF"
140
145
  },
141
146
  spellCheck: false,
142
- onClick: handleClick
147
+ onMouseUp: handleClick
143
148
  });
144
149
  }
145
150
 
@@ -3,12 +3,15 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
+ exports.bracketTyped = bracketTyped;
6
7
  exports.findFarthestParentNode = void 0;
7
8
  exports.getNodesCount = getNodesCount;
8
9
  exports.getStepRange = void 0;
10
+ exports.hasDocAsParent = hasDocAsParent;
9
11
  exports.hasVisibleContent = hasVisibleContent;
10
12
  exports.isEmptyDocument = isEmptyDocument;
11
13
  exports.isEmptyParagraph = isEmptyParagraph;
14
+ exports.isInEmptyLine = isInEmptyLine;
12
15
  exports.isNodeEmpty = isNodeEmpty;
13
16
  exports.isSelectionEndOfParagraph = void 0;
14
17
  exports.nodesBetweenChanged = nodesBetweenChanged;
@@ -157,4 +160,52 @@ function getNodesCount(node) {
157
160
  count[node.type.name] = (count[node.type.name] || 0) + 1;
158
161
  });
159
162
  return count;
163
+ } // Checks to see if the parent node is the document, ie not contained within another entity
164
+
165
+
166
+ function hasDocAsParent($anchor) {
167
+ return $anchor.depth === 1;
168
+ }
169
+
170
+ function isInEmptyLine(state) {
171
+ var selection = state.selection;
172
+ var _ref = selection,
173
+ $cursor = _ref.$cursor,
174
+ $anchor = _ref.$anchor;
175
+
176
+ if (!$cursor) {
177
+ return false;
178
+ }
179
+
180
+ var node = $cursor.node();
181
+
182
+ if (!node) {
183
+ return false;
184
+ }
185
+
186
+ return isEmptyParagraph(node) && hasDocAsParent($anchor);
187
+ }
188
+
189
+ function bracketTyped(state) {
190
+ var selection = state.selection;
191
+ var _ref2 = selection,
192
+ $cursor = _ref2.$cursor,
193
+ $anchor = _ref2.$anchor;
194
+
195
+ if (!$cursor) {
196
+ return false;
197
+ }
198
+
199
+ var node = $cursor.nodeBefore;
200
+
201
+ if (!node) {
202
+ return false;
203
+ }
204
+
205
+ if (node.type.name === 'text' && node.text === '{') {
206
+ var paragraphNode = $anchor.node();
207
+ return paragraphNode.marks.length === 0 && hasDocAsParent($anchor);
208
+ }
209
+
210
+ return false;
160
211
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@titaui/pc",
3
- "version": "1.10.49",
3
+ "version": "1.10.50",
4
4
  "nameCN": "",
5
5
  "description": "",
6
6
  "main": "lib/index.js",