@titaui/pc 1.10.44 → 1.10.45

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.
Files changed (104) hide show
  1. package/lib/components/rich-editor/basic/schema.js +47 -0
  2. package/lib/components/rich-editor/consts/events.js +12 -0
  3. package/lib/components/rich-editor/enums.js +42 -0
  4. package/lib/components/rich-editor/index.js +58 -0
  5. package/lib/components/rich-editor/keymap.js +119 -0
  6. package/lib/components/rich-editor/keymaps/index.js +241 -0
  7. package/lib/components/rich-editor/models/controller.js +18 -0
  8. package/lib/components/rich-editor/models/editor.js +47 -0
  9. package/lib/components/rich-editor/models/plugin.js +20 -0
  10. package/lib/components/rich-editor/models/schema.js +121 -0
  11. package/lib/components/rich-editor/plugins/block/block-quote/commond.js +27 -0
  12. package/lib/components/rich-editor/plugins/block/block-quote/index.js +126 -0
  13. package/lib/components/rich-editor/plugins/block/heading/commonds.js +31 -0
  14. package/lib/components/rich-editor/plugins/block/heading/index.js +188 -0
  15. package/lib/components/rich-editor/plugins/block/index.js +57 -0
  16. package/lib/components/rich-editor/plugins/block/lists/actions/conversions.js +172 -0
  17. package/lib/components/rich-editor/plugins/block/lists/actions/indent-list-items-selected.js +163 -0
  18. package/lib/components/rich-editor/plugins/block/lists/actions/indent-list.js +59 -0
  19. package/lib/components/rich-editor/plugins/block/lists/actions/join-list-items-forward.js +74 -0
  20. package/lib/components/rich-editor/plugins/block/lists/actions/join-list-items-scenarios/index.js +45 -0
  21. package/lib/components/rich-editor/plugins/block/lists/actions/join-list-items-scenarios/join-list-item-with-paragraph.js +104 -0
  22. package/lib/components/rich-editor/plugins/block/lists/actions/join-list-items-scenarios/join-list-item-with-parent-nested-list.js +92 -0
  23. package/lib/components/rich-editor/plugins/block/lists/actions/join-list-items-scenarios/join-nested-list-with-parent-list-item.js +89 -0
  24. package/lib/components/rich-editor/plugins/block/lists/actions/join-list-items-scenarios/join-paragraph-with-list.js +48 -0
  25. package/lib/components/rich-editor/plugins/block/lists/actions/join-list-items-scenarios/join-sibling-list-items.js +61 -0
  26. package/lib/components/rich-editor/plugins/block/lists/actions/merge-lists.js +34 -0
  27. package/lib/components/rich-editor/plugins/block/lists/actions/outdent-list-items-selected.js +289 -0
  28. package/lib/components/rich-editor/plugins/block/lists/actions/wrap-and-join-lists.js +180 -0
  29. package/lib/components/rich-editor/plugins/block/lists/baseCommand.js +328 -0
  30. package/lib/components/rich-editor/plugins/block/lists/commond/indent-list.js +60 -0
  31. package/lib/components/rich-editor/plugins/block/lists/commond/index.js +396 -0
  32. package/lib/components/rich-editor/plugins/block/lists/commond/join-list-item-forward.js +45 -0
  33. package/lib/components/rich-editor/plugins/block/lists/commond/listBackspace.js +302 -0
  34. package/lib/components/rich-editor/plugins/block/lists/commond/outdent-list.js +43 -0
  35. package/lib/components/rich-editor/plugins/block/lists/index.js +222 -0
  36. package/lib/components/rich-editor/plugins/block/lists/messages.js +38 -0
  37. package/lib/components/rich-editor/plugins/block/lists/pm-plugins/input-rule.js +152 -0
  38. package/lib/components/rich-editor/plugins/block/lists/pm-plugins/keymap.js +33 -0
  39. package/lib/components/rich-editor/plugins/block/lists/pm-plugins/main.js +94 -0
  40. package/lib/components/rich-editor/plugins/block/lists/styles.js +15 -0
  41. package/lib/components/rich-editor/plugins/block/lists/transforms.js +347 -0
  42. package/lib/components/rich-editor/plugins/block/lists/utils/analytics.js +48 -0
  43. package/lib/components/rich-editor/plugins/block/lists/utils/find.js +126 -0
  44. package/lib/components/rich-editor/plugins/block/lists/utils/indentation.js +87 -0
  45. package/lib/components/rich-editor/plugins/block/lists/utils/node.js +144 -0
  46. package/lib/components/rich-editor/plugins/block/lists/utils/replace-content.js +31 -0
  47. package/lib/components/rich-editor/plugins/block/lists/utils/selection.js +201 -0
  48. package/lib/components/rich-editor/plugins/block/lists/utils.js +52 -0
  49. package/lib/components/rich-editor/plugins/block/paragraph/index.js +91 -0
  50. package/lib/components/rich-editor/plugins/core/index.js +90 -0
  51. package/lib/components/rich-editor/plugins/core/pm-plugins/focus-handler.js +67 -0
  52. package/lib/components/rich-editor/plugins/core/pm-plugins/keymap.js +29 -0
  53. package/lib/components/rich-editor/plugins/core/pm-plugins/reactNodeView.js +80 -0
  54. package/lib/components/rich-editor/plugins/extension/alignment/commond.js +24 -0
  55. package/lib/components/rich-editor/plugins/extension/alignment/index.js +111 -0
  56. package/lib/components/rich-editor/plugins/extension/alignment/utils.js +19 -0
  57. package/lib/components/rich-editor/plugins/extension/index.js +18 -0
  58. package/lib/components/rich-editor/plugins/index.js +44 -0
  59. package/lib/components/rich-editor/plugins/inline/color/commond.js +128 -0
  60. package/lib/components/rich-editor/plugins/inline/color/consts.js +43 -0
  61. package/lib/components/rich-editor/plugins/inline/color/index.css +61 -0
  62. package/lib/components/rich-editor/plugins/inline/color/index.js +209 -0
  63. package/lib/components/rich-editor/plugins/inline/color/selector.js +250 -0
  64. package/lib/components/rich-editor/plugins/inline/delete-line/index.js +147 -0
  65. package/lib/components/rich-editor/plugins/inline/em/index.js +93 -0
  66. package/lib/components/rich-editor/plugins/inline/index.js +83 -0
  67. package/lib/components/rich-editor/plugins/inline/link/commands.js +256 -0
  68. package/lib/components/rich-editor/plugins/inline/link/index.js +149 -0
  69. package/lib/components/rich-editor/plugins/inline/link/pm-plugins/fake-cursor-for-toolbar.js +77 -0
  70. package/lib/components/rich-editor/plugins/inline/link/pm-plugins/main.js +293 -0
  71. package/lib/components/rich-editor/plugins/inline/link/ui/index.css +79 -0
  72. package/lib/components/rich-editor/plugins/inline/link/ui/linkEditor.js +148 -0
  73. package/lib/components/rich-editor/plugins/inline/link/ui/linkToolbar.js +88 -0
  74. package/lib/components/rich-editor/plugins/inline/link/ui/toolbarBtn.js +117 -0
  75. package/lib/components/rich-editor/plugins/inline/link/utils.js +33 -0
  76. package/lib/components/rich-editor/plugins/inline/strong/index.js +137 -0
  77. package/lib/components/rich-editor/plugins/inline/under-line/index.js +145 -0
  78. package/lib/components/rich-editor/plugins/util.js +281 -0
  79. package/lib/components/rich-editor/react/reactNodeView.js +383 -0
  80. package/lib/components/rich-editor/react/uiProvider.js +185 -0
  81. package/lib/components/rich-editor/schemas/basic.js +309 -0
  82. package/lib/components/rich-editor/schemas/index.js +19 -0
  83. package/lib/components/rich-editor/schemas/list.js +342 -0
  84. package/lib/components/rich-editor/types/commond.js +5 -0
  85. package/lib/components/rich-editor/types/index.js +18 -0
  86. package/lib/components/rich-editor/ui/Popup/index.js +247 -0
  87. package/lib/components/rich-editor/ui/Popup/utils.js +399 -0
  88. package/lib/components/rich-editor/ui/editor/index.css +144 -0
  89. package/lib/components/rich-editor/ui/editor/index.js +143 -0
  90. package/lib/components/rich-editor/ui/normal-toolbar/index.css +29 -0
  91. package/lib/components/rich-editor/ui/normal-toolbar/index.js +109 -0
  92. package/lib/components/rich-editor/utils/browser.js +35 -0
  93. package/lib/components/rich-editor/utils/commands.js +266 -0
  94. package/lib/components/rich-editor/utils/document.js +160 -0
  95. package/lib/components/rich-editor/utils/event.js +79 -0
  96. package/lib/components/rich-editor/utils/helpers.js +16 -0
  97. package/lib/components/rich-editor/utils/mark.js +168 -0
  98. package/lib/components/rich-editor/utils/slice.js +85 -0
  99. package/lib/components/rich-editor/utils/toolbar.js +228 -0
  100. package/lib/components/upload/index.js +4 -2
  101. package/lib/components/upload/util.js +2 -0
  102. package/lib/index.js +8 -0
  103. package/package.json +20 -2
  104. package/yarn-error.log +22184 -0
@@ -0,0 +1,149 @@
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.LinkSchema = exports.LinkPlugin = exports.LinkController = void 0;
9
+
10
+ var _plugin = _interopRequireDefault(require("../../../models/plugin"));
11
+
12
+ var _schema = require("../../../models/schema");
13
+
14
+ var _controller = _interopRequireDefault(require("../../../models/controller"));
15
+
16
+ var _toolbarBtn = _interopRequireDefault(require("./ui/toolbarBtn"));
17
+
18
+ var _main = _interopRequireWildcard(require("./pm-plugins/main"));
19
+
20
+ var _fakeCursorForToolbar = _interopRequireDefault(require("./pm-plugins/fake-cursor-for-toolbar"));
21
+
22
+ 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); }
23
+
24
+ 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; }
25
+
26
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
27
+
28
+ 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); } }
29
+
30
+ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
31
+
32
+ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
33
+
34
+ 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); }
35
+
36
+ function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
37
+
38
+ 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); }; }
39
+
40
+ 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); }
41
+
42
+ function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
43
+
44
+ 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; } }
45
+
46
+ function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
47
+
48
+ var PLUGIN_NAME = 'link';
49
+
50
+ var LinkSchema = /*#__PURE__*/function (_InlineSchema) {
51
+ _inherits(LinkSchema, _InlineSchema);
52
+
53
+ var _super = _createSuper(LinkSchema);
54
+
55
+ function LinkSchema() {
56
+ var _this;
57
+
58
+ _classCallCheck(this, LinkSchema);
59
+
60
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
61
+ args[_key] = arguments[_key];
62
+ }
63
+
64
+ return _possibleConstructorReturn(_this, (_this = _super.call.apply(_super, [this].concat(args)), _this.name = PLUGIN_NAME, _this.priority = 100, _this.inclusive = false, _this.group = 'link', _this.attrs = {
65
+ href: {
66
+ "default": ''
67
+ }
68
+ }, _this.parseDOM = [{
69
+ tag: 'a[href]',
70
+ priority: 100,
71
+ getAttrs: function getAttrs(dom) {
72
+ if (!dom.textContent && !dom.getAttribute('text')) {
73
+ return false;
74
+ } // solve the problem of copying itself
75
+
76
+
77
+ return {
78
+ href: dom.getAttribute('href')
79
+ };
80
+ }
81
+ }], _this.toDOM = function (node) {
82
+ return ['a', {
83
+ href: node.attrs.href
84
+ }, 0];
85
+ }, _assertThisInitialized(_this)));
86
+ }
87
+
88
+ return _createClass(LinkSchema);
89
+ }(_schema.InlineSchema);
90
+
91
+ exports.LinkSchema = LinkSchema;
92
+
93
+ var LinkController = /*#__PURE__*/function (_BaseController) {
94
+ _inherits(LinkController, _BaseController);
95
+
96
+ var _super2 = _createSuper(LinkController);
97
+
98
+ function LinkController() {
99
+ var _this2;
100
+
101
+ _classCallCheck(this, LinkController);
102
+
103
+ for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
104
+ args[_key2] = arguments[_key2];
105
+ }
106
+
107
+ return _possibleConstructorReturn(_this2, (_this2 = _super2.call.apply(_super2, [this].concat(args)), _this2.toolbar = {
108
+ title: '链接',
109
+ icon: 'tu-icon-text-link',
110
+ handler: function handler(editor) {
111
+ // toggleMark(editor.state.schema.marks[PLUGIN_NAME])(editor.state,editor.view.dispatch)
112
+ editor.view.focus();
113
+ },
114
+ renderMenu: _toolbarBtn["default"],
115
+ active: function active(state) {
116
+ return _main.stateKey.getState(state).activeLinkMark;
117
+ },
118
+ disabled: function disabled(state) {
119
+ return !_main.stateKey.getState(state).canInsertLink;
120
+ }
121
+ }, _this2.pmPlugins = [_main["default"], _fakeCursorForToolbar["default"]], _assertThisInitialized(_this2)));
122
+ }
123
+
124
+ return _createClass(LinkController);
125
+ }(_controller["default"]);
126
+
127
+ exports.LinkController = LinkController;
128
+
129
+ var LinkPlugin = /*#__PURE__*/function (_BasePlugin) {
130
+ _inherits(LinkPlugin, _BasePlugin);
131
+
132
+ var _super3 = _createSuper(LinkPlugin);
133
+
134
+ function LinkPlugin() {
135
+ var _this3;
136
+
137
+ _classCallCheck(this, LinkPlugin);
138
+
139
+ for (var _len3 = arguments.length, args = new Array(_len3), _key3 = 0; _key3 < _len3; _key3++) {
140
+ args[_key3] = arguments[_key3];
141
+ }
142
+
143
+ return _possibleConstructorReturn(_this3, (_this3 = _super3.call.apply(_super3, [this].concat(args)), _this3.name = PLUGIN_NAME, _this3.schema = LinkSchema, _this3.controller = LinkController, _assertThisInitialized(_this3)));
144
+ }
145
+
146
+ return _createClass(LinkPlugin);
147
+ }(_plugin["default"]);
148
+
149
+ exports.LinkPlugin = LinkPlugin;
@@ -0,0 +1,77 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports["default"] = void 0;
7
+
8
+ var _prosemirrorState = require("prosemirror-state");
9
+
10
+ var _prosemirrorView = require("prosemirror-view");
11
+
12
+ var _main = require("./main");
13
+
14
+ var createTextCursor = function createTextCursor(pos) {
15
+ var node = document.createElement('div');
16
+ node.className = 'ProseMirror-fake-text-cursor';
17
+ return _prosemirrorView.Decoration.widget(pos, node, {
18
+ key: 'hyperlink-text-cursor'
19
+ });
20
+ };
21
+
22
+ var createTextSelection = function createTextSelection(from, to) {
23
+ return _prosemirrorView.Decoration.inline(from, to, {
24
+ "class": 'ProseMirror-fake-text-selection'
25
+ });
26
+ };
27
+
28
+ var getInsertLinkToolbarState = function getInsertLinkToolbarState(editorState) {
29
+ var state = _main.stateKey.getState(editorState);
30
+
31
+ if (state && state.activeLinkMark) {
32
+ if (state.activeLinkMark.type === _main.InsertStatus.INSERT_LINK_TOOLBAR) {
33
+ return state.activeLinkMark;
34
+ }
35
+ }
36
+
37
+ return undefined;
38
+ };
39
+
40
+ var fakeCursorToolbarPlugin = new _prosemirrorState.Plugin({
41
+ state: {
42
+ init: function init() {
43
+ return _prosemirrorView.DecorationSet.empty;
44
+ },
45
+ apply: function apply(tr, pluginState, oldState, newState) {
46
+ var oldInsertToolbarState = getInsertLinkToolbarState(oldState);
47
+ var insertToolbarState = getInsertLinkToolbarState(newState); // Map DecorationSet if it still refers to the same position in the document
48
+
49
+ if (oldInsertToolbarState && insertToolbarState) {
50
+ var from = insertToolbarState.from,
51
+ to = insertToolbarState.to;
52
+ var oldFrom = tr.mapping.map(oldInsertToolbarState.from);
53
+ var oldTo = tr.mapping.map(oldInsertToolbarState.to);
54
+
55
+ if (oldFrom === from && oldTo === to) {
56
+ return pluginState.map(tr.mapping, tr.doc);
57
+ }
58
+ } // Update DecorationSet if new insert toolbar, or if we have moved to a different position in the doc
59
+
60
+
61
+ if (insertToolbarState) {
62
+ var _from = insertToolbarState.from,
63
+ _to = insertToolbarState.to;
64
+ return _prosemirrorView.DecorationSet.create(tr.doc, [_from === _to ? createTextCursor(_from) : createTextSelection(_from, _to)]);
65
+ }
66
+
67
+ return _prosemirrorView.DecorationSet.empty;
68
+ }
69
+ },
70
+ props: {
71
+ decorations: function decorations(state) {
72
+ return fakeCursorToolbarPlugin.getState(state);
73
+ }
74
+ }
75
+ });
76
+ var _default = fakeCursorToolbarPlugin;
77
+ exports["default"] = _default;
@@ -0,0 +1,293 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.stateKey = exports.plugin = exports["default"] = exports.canLinkBeCreatedInRange = exports.LinkAction = exports.InsertStatus = void 0;
7
+
8
+ var _prosemirrorState = require("prosemirror-state");
9
+
10
+ var _helpers = require("../../../../utils/helpers");
11
+
12
+ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
13
+
14
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
15
+
16
+ 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; }
17
+
18
+ var LinkAction;
19
+ exports.LinkAction = LinkAction;
20
+
21
+ (function (LinkAction) {
22
+ LinkAction["SHOW_INSERT_TOOLBAR"] = "SHOW_INSERT_TOOLBAR";
23
+ LinkAction["HIDE_TOOLBAR"] = "HIDE_TOOLBAR";
24
+ LinkAction["SELECTION_CHANGE"] = "SELECTION_CHANGE";
25
+ LinkAction["INSERT_LINK_TOOLBAR"] = "INSERT";
26
+ LinkAction["EDIT_INSERTED_TOOLBAR"] = "EDIT_INSERTED_TOOLBAR";
27
+ })(LinkAction || (exports.LinkAction = LinkAction = {}));
28
+
29
+ var InsertStatus;
30
+ exports.InsertStatus = InsertStatus;
31
+
32
+ (function (InsertStatus) {
33
+ InsertStatus["EDIT_LINK_TOOLBAR"] = "EDIT";
34
+ InsertStatus["INSERT_LINK_TOOLBAR"] = "INSERT";
35
+ InsertStatus["EDIT_INSERTED_TOOLBAR"] = "EDIT_INSERTED";
36
+ })(InsertStatus || (exports.InsertStatus = InsertStatus = {}));
37
+
38
+ var canLinkBeCreatedInRange = function canLinkBeCreatedInRange(from, to) {
39
+ return function (state) {
40
+ if (!state.doc.rangeHasMark(from, to, state.schema.marks.link)) {
41
+ var $from = state.doc.resolve(from);
42
+ var $to = state.doc.resolve(to);
43
+ var link = state.schema.marks.link;
44
+
45
+ if ($from.parent === $to.parent && $from.parent.isTextblock) {
46
+ if ($from.parent.type.allowsMarkType(link)) {
47
+ var allowed = true;
48
+ state.doc.nodesBetween(from, to, function (node) {
49
+ allowed = allowed && !node.marks.some(function (m) {
50
+ return m.type.excludes(link);
51
+ });
52
+ return allowed;
53
+ });
54
+ return allowed;
55
+ }
56
+ }
57
+ }
58
+
59
+ return false;
60
+ };
61
+ };
62
+
63
+ exports.canLinkBeCreatedInRange = canLinkBeCreatedInRange;
64
+
65
+ var isSelectionInsideLink = function isSelectionInsideLink(state) {
66
+ return !!state.doc.type.schema.marks.link.isInSet(state.selection.$from.marks());
67
+ };
68
+
69
+ var isSelectionAroundLink = function isSelectionAroundLink(state) {
70
+ var _state$selection = state.selection,
71
+ $from = _state$selection.$from,
72
+ $to = _state$selection.$to;
73
+ var node = $from.nodeAfter;
74
+ return !!node && $from.textOffset === 0 && $to.pos - $from.pos === node.nodeSize && !!state.doc.type.schema.marks.link.isInSet(node.marks);
75
+ };
76
+
77
+ var mapTransactionToState = function mapTransactionToState(state, tr) {
78
+ if (!state) {
79
+ return undefined;
80
+ } else if (state.type === InsertStatus.EDIT_LINK_TOOLBAR || state.type === InsertStatus.EDIT_INSERTED_TOOLBAR) {
81
+ var _tr$mapping$mapResult = tr.mapping.mapResult(state.pos, 1),
82
+ pos = _tr$mapping$mapResult.pos,
83
+ deleted = _tr$mapping$mapResult.deleted;
84
+
85
+ var node = tr.doc.nodeAt(pos); // If the position was not deleted & it is still a link
86
+
87
+ if (!deleted && !!node.type.schema.marks.link.isInSet(node.marks)) {
88
+ if (node === state.node && pos === state.pos) {
89
+ return state;
90
+ }
91
+
92
+ return _objectSpread(_objectSpread({}, state), {}, {
93
+ pos: pos,
94
+ node: node
95
+ });
96
+ } // If the position has been deleted, then require a navigation to show the toolbar again
97
+
98
+
99
+ return;
100
+ } else if (state.type === InsertStatus.INSERT_LINK_TOOLBAR) {
101
+ return _objectSpread(_objectSpread({}, state), {}, {
102
+ from: tr.mapping.map(state.from),
103
+ to: tr.mapping.map(state.to)
104
+ });
105
+ }
106
+
107
+ return;
108
+ };
109
+
110
+ var toState = function toState(state, action, editorState) {
111
+ // Show insert or edit toolbar
112
+ if (!state) {
113
+ switch (action) {
114
+ case LinkAction.SHOW_INSERT_TOOLBAR:
115
+ {
116
+ var _editorState$selectio = editorState.selection,
117
+ from = _editorState$selectio.from,
118
+ to = _editorState$selectio.to;
119
+
120
+ if (canLinkBeCreatedInRange(from, to)(editorState)) {
121
+ return {
122
+ type: InsertStatus.INSERT_LINK_TOOLBAR,
123
+ from: from,
124
+ to: to
125
+ };
126
+ }
127
+
128
+ return undefined;
129
+ }
130
+
131
+ case LinkAction.SELECTION_CHANGE:
132
+ // If the user has moved their cursor, see if they're in a link
133
+ var link = getActiveLinkMark(editorState);
134
+
135
+ if (link) {
136
+ return _objectSpread(_objectSpread({}, link), {}, {
137
+ type: InsertStatus.EDIT_LINK_TOOLBAR
138
+ });
139
+ }
140
+
141
+ return undefined;
142
+
143
+ default:
144
+ return undefined;
145
+ }
146
+ } // Update toolbar state if selection changes, or if toolbar is hidden
147
+
148
+
149
+ if (state.type === InsertStatus.EDIT_LINK_TOOLBAR) {
150
+ switch (action) {
151
+ case LinkAction.EDIT_INSERTED_TOOLBAR:
152
+ {
153
+ var _link2 = getActiveLinkMark(editorState);
154
+
155
+ if (_link2) {
156
+ if (_link2.pos === state.pos && _link2.node === state.node) {
157
+ return _objectSpread(_objectSpread({}, state), {}, {
158
+ type: InsertStatus.EDIT_INSERTED_TOOLBAR
159
+ });
160
+ }
161
+
162
+ return _objectSpread(_objectSpread({}, _link2), {}, {
163
+ type: InsertStatus.EDIT_INSERTED_TOOLBAR
164
+ });
165
+ }
166
+
167
+ return undefined;
168
+ }
169
+
170
+ case LinkAction.SELECTION_CHANGE:
171
+ var _link = getActiveLinkMark(editorState);
172
+
173
+ if (_link) {
174
+ if (_link.pos === state.pos && _link.node === state.node) {
175
+ // Make sure we return the same object, if it's the same link
176
+ return state;
177
+ }
178
+
179
+ return _objectSpread(_objectSpread({}, _link), {}, {
180
+ type: InsertStatus.EDIT_LINK_TOOLBAR
181
+ });
182
+ }
183
+
184
+ return undefined;
185
+
186
+ case LinkAction.HIDE_TOOLBAR:
187
+ return undefined;
188
+
189
+ default:
190
+ return state;
191
+ }
192
+ } // Remove toolbar if user changes selection or toolbar is hidden
193
+
194
+
195
+ if (state.type === InsertStatus.INSERT_LINK_TOOLBAR) {
196
+ switch (action) {
197
+ case LinkAction.SELECTION_CHANGE:
198
+ case LinkAction.HIDE_TOOLBAR:
199
+ return undefined;
200
+
201
+ default:
202
+ return state;
203
+ }
204
+ }
205
+
206
+ return;
207
+ };
208
+
209
+ var getActiveLinkMark = function getActiveLinkMark(state) {
210
+ var $from = state.selection.$from;
211
+
212
+ if (isSelectionInsideLink(state) || isSelectionAroundLink(state)) {
213
+ var pos = $from.pos - $from.textOffset;
214
+ var node = state.doc.nodeAt(pos);
215
+ return node && node.isText ? {
216
+ node: node,
217
+ pos: pos
218
+ } : undefined;
219
+ }
220
+
221
+ return undefined;
222
+ };
223
+
224
+ var getActiveText = function getActiveText(selection) {
225
+ var currentSlice = selection.content();
226
+
227
+ if (currentSlice.size === 0) {
228
+ return;
229
+ }
230
+
231
+ if (currentSlice.content.childCount === 1 && currentSlice.content.firstChild && selection instanceof _prosemirrorState.TextSelection) {
232
+ return currentSlice.content.firstChild.textContent;
233
+ }
234
+
235
+ return;
236
+ };
237
+
238
+ var stateKey = new _prosemirrorState.PluginKey('hyperlinkPlugin');
239
+ exports.stateKey = stateKey;
240
+
241
+ var plugin = function plugin(dispatch) {
242
+ return new _prosemirrorState.Plugin({
243
+ state: {
244
+ init: function init(_, state) {
245
+ var canInsertLink = canLinkBeCreatedInRange(state.selection.from, state.selection.to)(state);
246
+ return {
247
+ activeText: getActiveText(state.selection),
248
+ canInsertLink: canInsertLink,
249
+ activeLinkMark: toState(undefined, LinkAction.SELECTION_CHANGE, state)
250
+ };
251
+ },
252
+ apply: function apply(tr, pluginState, _oldState, newState) {
253
+ var state = pluginState;
254
+ var action = tr.getMeta(stateKey) && tr.getMeta(stateKey).type;
255
+
256
+ if (tr.docChanged) {
257
+ state = {
258
+ activeText: state.activeText,
259
+ canInsertLink: canLinkBeCreatedInRange(newState.selection.from, newState.selection.to)(newState),
260
+ activeLinkMark: mapTransactionToState(state.activeLinkMark, tr)
261
+ };
262
+ }
263
+
264
+ if (action) {
265
+ state = {
266
+ activeText: state.activeText,
267
+ canInsertLink: state.canInsertLink,
268
+ activeLinkMark: toState(state.activeLinkMark, action, newState)
269
+ };
270
+ }
271
+
272
+ if (tr.selectionSet) {
273
+ state = {
274
+ activeText: getActiveText(newState.selection),
275
+ canInsertLink: canLinkBeCreatedInRange(newState.selection.from, newState.selection.to)(newState),
276
+ activeLinkMark: toState(state.activeLinkMark, LinkAction.SELECTION_CHANGE, newState)
277
+ };
278
+ }
279
+
280
+ if (!(0, _helpers.shallowEqual)(state, pluginState)) {
281
+ dispatch(stateKey, state);
282
+ }
283
+
284
+ return state;
285
+ }
286
+ },
287
+ key: stateKey
288
+ });
289
+ };
290
+
291
+ exports.plugin = plugin;
292
+ var _default = plugin;
293
+ exports["default"] = _default;
@@ -0,0 +1,79 @@
1
+ .ProseMirror .ProseMirror-fake-text-cursor {
2
+ display: inline;
3
+ pointer-events: none;
4
+ position: relative;
5
+ }
6
+
7
+ .ProseMirror .ProseMirror-fake-text-selection {
8
+ display: inline;
9
+ pointer-events: none;
10
+ position: relative;
11
+ background-color: #b3d4ff;
12
+ }
13
+
14
+ .tita-rich-editor-link {
15
+ box-sizing: border-box;
16
+ width: 348px;
17
+ padding: 24px 32px 20px;
18
+ background: #ffffff;
19
+ box-shadow: 0px 8px 24px 0px rgba(127, 145, 180, 0.2);
20
+ border-radius: 24px;
21
+ }
22
+
23
+ .tita-rich-editor-link__btn-wrapper {
24
+ display: flex;
25
+ margin-top: 16px;
26
+ justify-content: flex-end;
27
+ }
28
+
29
+ .tita-rich-editor-link__input:first-child {
30
+ margin-bottom: 16px;
31
+ }
32
+
33
+ .tita-rich-editor-link__input .form-field-input__label-text {
34
+ color: #89919f;
35
+ }
36
+
37
+ .tita-rich-editor-link__common-tool-bar-btn {
38
+ width: 100%;
39
+ height: 100%;
40
+ display: flex;
41
+ align-items: center;
42
+ justify-content: center;
43
+ }
44
+
45
+ .tita-rich-editor-toolbar {
46
+ box-sizing: border-box;
47
+ padding: 0 12px;
48
+ display: flex;
49
+ align-items: center;
50
+ width: 344px;
51
+ height: 44px;
52
+ background: #ffffff;
53
+ box-shadow: 0px 4px 12px 0px rgba(127, 145, 180, 0.2);
54
+ border-radius: 8px;
55
+ border: 1px solid #f0f2f5;
56
+ }
57
+
58
+ .tita-rich-editor-toolbar__text {
59
+ flex: 1;
60
+ width: 0;
61
+ overflow: hidden;
62
+ text-overflow: ellipsis;
63
+ white-space: nowrap;
64
+ }
65
+
66
+ .tita-rich-editor-toolbar__btn {
67
+ width: 24px;
68
+ height: 24px;
69
+ font-size: 18px;
70
+ display: flex;
71
+ align-items: center;
72
+ justify-content: center;
73
+ margin-left: 8px;
74
+ cursor: pointer;
75
+ }
76
+
77
+ .tita-rich-editor-toolbar__btn:hover {
78
+ background-color: #f0f4fa;
79
+ }