@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.
- package/lib/components/rich-editor/basic/schema.js +47 -0
- package/lib/components/rich-editor/consts/events.js +12 -0
- package/lib/components/rich-editor/enums.js +42 -0
- package/lib/components/rich-editor/index.js +58 -0
- package/lib/components/rich-editor/keymap.js +119 -0
- package/lib/components/rich-editor/keymaps/index.js +241 -0
- package/lib/components/rich-editor/models/controller.js +18 -0
- package/lib/components/rich-editor/models/editor.js +47 -0
- package/lib/components/rich-editor/models/plugin.js +20 -0
- package/lib/components/rich-editor/models/schema.js +121 -0
- package/lib/components/rich-editor/plugins/block/block-quote/commond.js +27 -0
- package/lib/components/rich-editor/plugins/block/block-quote/index.js +126 -0
- package/lib/components/rich-editor/plugins/block/heading/commonds.js +31 -0
- package/lib/components/rich-editor/plugins/block/heading/index.js +188 -0
- package/lib/components/rich-editor/plugins/block/index.js +57 -0
- package/lib/components/rich-editor/plugins/block/lists/actions/conversions.js +172 -0
- package/lib/components/rich-editor/plugins/block/lists/actions/indent-list-items-selected.js +163 -0
- package/lib/components/rich-editor/plugins/block/lists/actions/indent-list.js +59 -0
- package/lib/components/rich-editor/plugins/block/lists/actions/join-list-items-forward.js +74 -0
- package/lib/components/rich-editor/plugins/block/lists/actions/join-list-items-scenarios/index.js +45 -0
- package/lib/components/rich-editor/plugins/block/lists/actions/join-list-items-scenarios/join-list-item-with-paragraph.js +104 -0
- package/lib/components/rich-editor/plugins/block/lists/actions/join-list-items-scenarios/join-list-item-with-parent-nested-list.js +92 -0
- package/lib/components/rich-editor/plugins/block/lists/actions/join-list-items-scenarios/join-nested-list-with-parent-list-item.js +89 -0
- package/lib/components/rich-editor/plugins/block/lists/actions/join-list-items-scenarios/join-paragraph-with-list.js +48 -0
- package/lib/components/rich-editor/plugins/block/lists/actions/join-list-items-scenarios/join-sibling-list-items.js +61 -0
- package/lib/components/rich-editor/plugins/block/lists/actions/merge-lists.js +34 -0
- package/lib/components/rich-editor/plugins/block/lists/actions/outdent-list-items-selected.js +289 -0
- package/lib/components/rich-editor/plugins/block/lists/actions/wrap-and-join-lists.js +180 -0
- package/lib/components/rich-editor/plugins/block/lists/baseCommand.js +328 -0
- package/lib/components/rich-editor/plugins/block/lists/commond/indent-list.js +60 -0
- package/lib/components/rich-editor/plugins/block/lists/commond/index.js +396 -0
- package/lib/components/rich-editor/plugins/block/lists/commond/join-list-item-forward.js +45 -0
- package/lib/components/rich-editor/plugins/block/lists/commond/listBackspace.js +302 -0
- package/lib/components/rich-editor/plugins/block/lists/commond/outdent-list.js +43 -0
- package/lib/components/rich-editor/plugins/block/lists/index.js +222 -0
- package/lib/components/rich-editor/plugins/block/lists/messages.js +38 -0
- package/lib/components/rich-editor/plugins/block/lists/pm-plugins/input-rule.js +152 -0
- package/lib/components/rich-editor/plugins/block/lists/pm-plugins/keymap.js +33 -0
- package/lib/components/rich-editor/plugins/block/lists/pm-plugins/main.js +94 -0
- package/lib/components/rich-editor/plugins/block/lists/styles.js +15 -0
- package/lib/components/rich-editor/plugins/block/lists/transforms.js +347 -0
- package/lib/components/rich-editor/plugins/block/lists/utils/analytics.js +48 -0
- package/lib/components/rich-editor/plugins/block/lists/utils/find.js +126 -0
- package/lib/components/rich-editor/plugins/block/lists/utils/indentation.js +87 -0
- package/lib/components/rich-editor/plugins/block/lists/utils/node.js +144 -0
- package/lib/components/rich-editor/plugins/block/lists/utils/replace-content.js +31 -0
- package/lib/components/rich-editor/plugins/block/lists/utils/selection.js +201 -0
- package/lib/components/rich-editor/plugins/block/lists/utils.js +52 -0
- package/lib/components/rich-editor/plugins/block/paragraph/index.js +91 -0
- package/lib/components/rich-editor/plugins/core/index.js +90 -0
- package/lib/components/rich-editor/plugins/core/pm-plugins/focus-handler.js +67 -0
- package/lib/components/rich-editor/plugins/core/pm-plugins/keymap.js +29 -0
- package/lib/components/rich-editor/plugins/core/pm-plugins/reactNodeView.js +80 -0
- package/lib/components/rich-editor/plugins/extension/alignment/commond.js +24 -0
- package/lib/components/rich-editor/plugins/extension/alignment/index.js +111 -0
- package/lib/components/rich-editor/plugins/extension/alignment/utils.js +19 -0
- package/lib/components/rich-editor/plugins/extension/index.js +18 -0
- package/lib/components/rich-editor/plugins/index.js +44 -0
- package/lib/components/rich-editor/plugins/inline/color/commond.js +128 -0
- package/lib/components/rich-editor/plugins/inline/color/consts.js +43 -0
- package/lib/components/rich-editor/plugins/inline/color/index.css +61 -0
- package/lib/components/rich-editor/plugins/inline/color/index.js +209 -0
- package/lib/components/rich-editor/plugins/inline/color/selector.js +250 -0
- package/lib/components/rich-editor/plugins/inline/delete-line/index.js +147 -0
- package/lib/components/rich-editor/plugins/inline/em/index.js +93 -0
- package/lib/components/rich-editor/plugins/inline/index.js +83 -0
- package/lib/components/rich-editor/plugins/inline/link/commands.js +256 -0
- package/lib/components/rich-editor/plugins/inline/link/index.js +149 -0
- package/lib/components/rich-editor/plugins/inline/link/pm-plugins/fake-cursor-for-toolbar.js +77 -0
- package/lib/components/rich-editor/plugins/inline/link/pm-plugins/main.js +293 -0
- package/lib/components/rich-editor/plugins/inline/link/ui/index.css +79 -0
- package/lib/components/rich-editor/plugins/inline/link/ui/linkEditor.js +148 -0
- package/lib/components/rich-editor/plugins/inline/link/ui/linkToolbar.js +88 -0
- package/lib/components/rich-editor/plugins/inline/link/ui/toolbarBtn.js +117 -0
- package/lib/components/rich-editor/plugins/inline/link/utils.js +33 -0
- package/lib/components/rich-editor/plugins/inline/strong/index.js +137 -0
- package/lib/components/rich-editor/plugins/inline/under-line/index.js +145 -0
- package/lib/components/rich-editor/plugins/util.js +281 -0
- package/lib/components/rich-editor/react/reactNodeView.js +383 -0
- package/lib/components/rich-editor/react/uiProvider.js +185 -0
- package/lib/components/rich-editor/schemas/basic.js +309 -0
- package/lib/components/rich-editor/schemas/index.js +19 -0
- package/lib/components/rich-editor/schemas/list.js +342 -0
- package/lib/components/rich-editor/types/commond.js +5 -0
- package/lib/components/rich-editor/types/index.js +18 -0
- package/lib/components/rich-editor/ui/Popup/index.js +247 -0
- package/lib/components/rich-editor/ui/Popup/utils.js +399 -0
- package/lib/components/rich-editor/ui/editor/index.css +144 -0
- package/lib/components/rich-editor/ui/editor/index.js +143 -0
- package/lib/components/rich-editor/ui/normal-toolbar/index.css +29 -0
- package/lib/components/rich-editor/ui/normal-toolbar/index.js +109 -0
- package/lib/components/rich-editor/utils/browser.js +35 -0
- package/lib/components/rich-editor/utils/commands.js +266 -0
- package/lib/components/rich-editor/utils/document.js +160 -0
- package/lib/components/rich-editor/utils/event.js +79 -0
- package/lib/components/rich-editor/utils/helpers.js +16 -0
- package/lib/components/rich-editor/utils/mark.js +168 -0
- package/lib/components/rich-editor/utils/slice.js +85 -0
- package/lib/components/rich-editor/utils/toolbar.js +228 -0
- package/lib/components/upload/index.js +4 -2
- package/lib/components/upload/util.js +2 -0
- package/lib/index.js +8 -0
- package/package.json +20 -2
- package/yarn-error.log +22184 -0
|
@@ -0,0 +1,145 @@
|
|
|
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.UnderLineSchema = exports.UnderLinePlugin = exports.UnderLineController = void 0;
|
|
9
|
+
|
|
10
|
+
var _mark = require("../../../utils/mark");
|
|
11
|
+
|
|
12
|
+
var _prosemirrorCommands = require("prosemirror-commands");
|
|
13
|
+
|
|
14
|
+
var _controller = _interopRequireDefault(require("../../../models/controller"));
|
|
15
|
+
|
|
16
|
+
var _plugin = _interopRequireDefault(require("../../../models/plugin"));
|
|
17
|
+
|
|
18
|
+
var _schema = require("../../../models/schema");
|
|
19
|
+
|
|
20
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
21
|
+
|
|
22
|
+
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
23
|
+
|
|
24
|
+
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); } }
|
|
25
|
+
|
|
26
|
+
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
27
|
+
|
|
28
|
+
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); }
|
|
29
|
+
|
|
30
|
+
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
|
|
31
|
+
|
|
32
|
+
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); }; }
|
|
33
|
+
|
|
34
|
+
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); }
|
|
35
|
+
|
|
36
|
+
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
|
|
37
|
+
|
|
38
|
+
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; } }
|
|
39
|
+
|
|
40
|
+
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
|
|
41
|
+
|
|
42
|
+
var PLUGIN_NAME = 'underLine';
|
|
43
|
+
|
|
44
|
+
function getAttrs(dom) {
|
|
45
|
+
var value = dom.style.textDecorationLine || dom.style.textDecoration || '';
|
|
46
|
+
var result = /underline/i.exec(value);
|
|
47
|
+
|
|
48
|
+
if (result) {
|
|
49
|
+
return true;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
return false;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
var UnderLineSchema = /*#__PURE__*/function (_InlineSchema) {
|
|
56
|
+
_inherits(UnderLineSchema, _InlineSchema);
|
|
57
|
+
|
|
58
|
+
var _super = _createSuper(UnderLineSchema);
|
|
59
|
+
|
|
60
|
+
function UnderLineSchema() {
|
|
61
|
+
var _this;
|
|
62
|
+
|
|
63
|
+
_classCallCheck(this, UnderLineSchema);
|
|
64
|
+
|
|
65
|
+
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
66
|
+
args[_key] = arguments[_key];
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
return _possibleConstructorReturn(_this, (_this = _super.call.apply(_super, [this].concat(args)), _this.name = PLUGIN_NAME, _this.parseDOM = [{
|
|
70
|
+
tag: 'ins'
|
|
71
|
+
}, {
|
|
72
|
+
tag: 'u'
|
|
73
|
+
}, {
|
|
74
|
+
tag: 'span',
|
|
75
|
+
getAttrs: getAttrs
|
|
76
|
+
}], _assertThisInitialized(_this)));
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
_createClass(UnderLineSchema, [{
|
|
80
|
+
key: "toDOM",
|
|
81
|
+
value: function toDOM() {
|
|
82
|
+
return ["u", {
|
|
83
|
+
style: 'text-decoration:underline;'
|
|
84
|
+
}, 0];
|
|
85
|
+
}
|
|
86
|
+
}]);
|
|
87
|
+
|
|
88
|
+
return UnderLineSchema;
|
|
89
|
+
}(_schema.InlineSchema);
|
|
90
|
+
|
|
91
|
+
exports.UnderLineSchema = UnderLineSchema;
|
|
92
|
+
|
|
93
|
+
var UnderLineController = /*#__PURE__*/function (_BaseController) {
|
|
94
|
+
_inherits(UnderLineController, _BaseController);
|
|
95
|
+
|
|
96
|
+
var _super2 = _createSuper(UnderLineController);
|
|
97
|
+
|
|
98
|
+
function UnderLineController() {
|
|
99
|
+
var _this2;
|
|
100
|
+
|
|
101
|
+
_classCallCheck(this, UnderLineController);
|
|
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-underline',
|
|
110
|
+
handler: function handler(editor) {
|
|
111
|
+
(0, _prosemirrorCommands.toggleMark)(editor.state.schema.marks[PLUGIN_NAME])(editor.state, editor.view.dispatch);
|
|
112
|
+
editor.view.focus();
|
|
113
|
+
},
|
|
114
|
+
active: function active(state) {
|
|
115
|
+
return (0, _mark.selectionContainsMark)(state, PLUGIN_NAME);
|
|
116
|
+
}
|
|
117
|
+
}, _assertThisInitialized(_this2)));
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
return _createClass(UnderLineController);
|
|
121
|
+
}(_controller["default"]);
|
|
122
|
+
|
|
123
|
+
exports.UnderLineController = UnderLineController;
|
|
124
|
+
|
|
125
|
+
var UnderLinePlugin = /*#__PURE__*/function (_BasePlugin) {
|
|
126
|
+
_inherits(UnderLinePlugin, _BasePlugin);
|
|
127
|
+
|
|
128
|
+
var _super3 = _createSuper(UnderLinePlugin);
|
|
129
|
+
|
|
130
|
+
function UnderLinePlugin() {
|
|
131
|
+
var _this3;
|
|
132
|
+
|
|
133
|
+
_classCallCheck(this, UnderLinePlugin);
|
|
134
|
+
|
|
135
|
+
for (var _len3 = arguments.length, args = new Array(_len3), _key3 = 0; _key3 < _len3; _key3++) {
|
|
136
|
+
args[_key3] = arguments[_key3];
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
return _possibleConstructorReturn(_this3, (_this3 = _super3.call.apply(_super3, [this].concat(args)), _this3.name = PLUGIN_NAME, _this3.schema = UnderLineSchema, _this3.controller = UnderLineController, _assertThisInitialized(_this3)));
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
return _createClass(UnderLinePlugin);
|
|
143
|
+
}(_plugin["default"]);
|
|
144
|
+
|
|
145
|
+
exports.UnderLinePlugin = UnderLinePlugin;
|
|
@@ -0,0 +1,281 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.applyPlugins = applyPlugins;
|
|
7
|
+
exports.compose = compose;
|
|
8
|
+
exports.findAncestorPosition = findAncestorPosition;
|
|
9
|
+
exports.getAncestorNodesBetween = getAncestorNodesBetween;
|
|
10
|
+
exports.isBlockActive = isBlockActive;
|
|
11
|
+
exports.isRangeOfType = isRangeOfType;
|
|
12
|
+
exports.isSharedMark = isSharedMark;
|
|
13
|
+
exports.sanitiseSelectionMarksForWrapping = void 0;
|
|
14
|
+
|
|
15
|
+
var _prosemirrorKeymap = require("prosemirror-keymap");
|
|
16
|
+
|
|
17
|
+
var _schema = require("../models/schema");
|
|
18
|
+
|
|
19
|
+
var _event = require("../utils/event");
|
|
20
|
+
|
|
21
|
+
var _core = require("./core");
|
|
22
|
+
|
|
23
|
+
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
|
|
24
|
+
|
|
25
|
+
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
26
|
+
|
|
27
|
+
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
28
|
+
|
|
29
|
+
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
|
|
30
|
+
|
|
31
|
+
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
|
|
32
|
+
|
|
33
|
+
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
|
|
34
|
+
|
|
35
|
+
function applyPlugins() {
|
|
36
|
+
var plugins = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
|
|
37
|
+
var defaultSchema = arguments.length > 1 ? arguments[1] : undefined;
|
|
38
|
+
var dispatcher = arguments.length > 2 ? arguments[2] : undefined;
|
|
39
|
+
var nodes = defaultSchema.nodes;
|
|
40
|
+
var marks = defaultSchema.marks || {};
|
|
41
|
+
var nativePlugins = [];
|
|
42
|
+
var controllers = [];
|
|
43
|
+
var schemas = [];
|
|
44
|
+
plugins.forEach(function (p) {
|
|
45
|
+
if (p.schema) {
|
|
46
|
+
Array.isArray(p.schema) ? schemas.push.apply(schemas, _toConsumableArray(p.schema.map(function (S) {
|
|
47
|
+
return new S();
|
|
48
|
+
}))) : schemas.push(new p.schema());
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
dealPlugin(p, nativePlugins, controllers, dispatcher);
|
|
52
|
+
});
|
|
53
|
+
dealPlugin(new _core.CorePlugin(), nativePlugins, controllers, dispatcher);
|
|
54
|
+
schemas.sort(function (s1, s2) {
|
|
55
|
+
return s2.priority - s1.priority;
|
|
56
|
+
}).forEach(function (s) {
|
|
57
|
+
if (s instanceof _schema.InlineSchema) {
|
|
58
|
+
marks[s.name] = s;
|
|
59
|
+
} else {
|
|
60
|
+
nodes[s.name] = s;
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
|
+
return {
|
|
64
|
+
nodes: nodes,
|
|
65
|
+
marks: marks,
|
|
66
|
+
nativePlugins: nativePlugins,
|
|
67
|
+
controllers: controllers
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
function dealPlugin(plugin, nativePlugins, controllers, dispatcher) {
|
|
72
|
+
if (plugin.controller) {
|
|
73
|
+
var pController = new plugin.controller();
|
|
74
|
+
controllers.push(pController);
|
|
75
|
+
|
|
76
|
+
if (pController.pmPlugins) {
|
|
77
|
+
nativePlugins.push.apply(nativePlugins, _toConsumableArray(pController.pmPlugins.map(function (pm) {
|
|
78
|
+
return typeof pm == 'function' ? pm((0, _event.createDispatch)(dispatcher)) : pm;
|
|
79
|
+
})));
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
if (pController.keymap) {
|
|
83
|
+
nativePlugins.push((0, _prosemirrorKeymap.keymap)(pController.keymap));
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
function addSchema(nodes, marks, SchemaCtor) {
|
|
89
|
+
var pSchema = new SchemaCtor();
|
|
90
|
+
|
|
91
|
+
if (pSchema instanceof _schema.InlineSchema) {
|
|
92
|
+
marks[pSchema.name] = pSchema;
|
|
93
|
+
} else {
|
|
94
|
+
nodes[pSchema.name] = pSchema;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
function isSharedMark(editor, from, to, type) {
|
|
99
|
+
var attrs = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : {};
|
|
100
|
+
var state = editor.state;
|
|
101
|
+
var allHasMark = true;
|
|
102
|
+
state.doc.nodesBetween(from, to, function (node) {
|
|
103
|
+
if (!node.isText || !allHasMark) return;
|
|
104
|
+
var sameTypeMarks = node.marks.filter(function (m) {
|
|
105
|
+
return m.type == type;
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
if (!sameTypeMarks.length) {
|
|
109
|
+
allHasMark = false;
|
|
110
|
+
return;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
sameTypeMarks.forEach(function (mark) {
|
|
114
|
+
if (!allHasMark) return;
|
|
115
|
+
|
|
116
|
+
if (Object.keys(attrs).length != Object.keys(mark.attrs).length) {
|
|
117
|
+
allHasMark = false;
|
|
118
|
+
return;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
for (var key in attrs) {
|
|
122
|
+
if (!(key in mark.attrs) || mark.attrs[key] !== attrs[key]) {
|
|
123
|
+
allHasMark = false;
|
|
124
|
+
return;
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
});
|
|
128
|
+
});
|
|
129
|
+
return allHasMark;
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* Traverse the document until an "ancestor" is found. Any nestable block can be an ancestor.
|
|
133
|
+
*/
|
|
134
|
+
|
|
135
|
+
|
|
136
|
+
function findAncestorPosition(doc, pos) {
|
|
137
|
+
var nestableBlocks = ['blockquote', 'bulletList', 'orderedList'];
|
|
138
|
+
|
|
139
|
+
if (pos.depth === 1) {
|
|
140
|
+
return pos;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
var node = pos.node(pos.depth);
|
|
144
|
+
var newPos = pos;
|
|
145
|
+
|
|
146
|
+
while (pos.depth >= 1) {
|
|
147
|
+
pos = doc.resolve(pos.before(pos.depth));
|
|
148
|
+
node = pos.node(pos.depth);
|
|
149
|
+
|
|
150
|
+
if (node && nestableBlocks.indexOf(node.type.name) !== -1) {
|
|
151
|
+
newPos = pos;
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
return newPos;
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
* Returns all top-level ancestor-nodes between $from and $to
|
|
159
|
+
*/
|
|
160
|
+
|
|
161
|
+
|
|
162
|
+
function getAncestorNodesBetween(doc, $from, $to) {
|
|
163
|
+
var nodes = Array();
|
|
164
|
+
var maxDepth = findAncestorPosition(doc, $from).depth;
|
|
165
|
+
var current = doc.resolve($from.start(maxDepth));
|
|
166
|
+
|
|
167
|
+
while (current.pos <= $to.start($to.depth)) {
|
|
168
|
+
var depth = Math.min(current.depth, maxDepth);
|
|
169
|
+
var node = current.node(depth);
|
|
170
|
+
|
|
171
|
+
if (node) {
|
|
172
|
+
nodes.push(node);
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
if (depth === 0) {
|
|
176
|
+
break;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
var next = doc.resolve(current.after(depth));
|
|
180
|
+
|
|
181
|
+
if (next.start(depth) >= doc.nodeSize - 2) {
|
|
182
|
+
break;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
if (next.depth !== current.depth) {
|
|
186
|
+
next = doc.resolve(next.pos + 2);
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
if (next.depth) {
|
|
190
|
+
current = doc.resolve(next.start(next.depth));
|
|
191
|
+
} else {
|
|
192
|
+
current = doc.resolve(next.end(next.depth));
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
return nodes;
|
|
197
|
+
}
|
|
198
|
+
/**
|
|
199
|
+
* Step through block-nodes between $from and $to and returns false if a node is
|
|
200
|
+
* found that isn't of the specified type
|
|
201
|
+
*/
|
|
202
|
+
|
|
203
|
+
|
|
204
|
+
function isRangeOfType(doc, $from, $to, nodeType) {
|
|
205
|
+
return getAncestorNodesBetween(doc, $from, $to).filter(function (node) {
|
|
206
|
+
return node.type !== nodeType;
|
|
207
|
+
}).length === 0;
|
|
208
|
+
}
|
|
209
|
+
/** Helper type for single arg function */
|
|
210
|
+
|
|
211
|
+
|
|
212
|
+
/**
|
|
213
|
+
* Compose 1 to n functions.
|
|
214
|
+
* @param func first function
|
|
215
|
+
* @param funcs additional functions
|
|
216
|
+
*/
|
|
217
|
+
function compose(func) {
|
|
218
|
+
for (var _len = arguments.length, funcs = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
|
|
219
|
+
funcs[_key - 1] = arguments[_key];
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
var allFuncs = [func].concat(funcs);
|
|
223
|
+
return function composed(raw) {
|
|
224
|
+
return allFuncs.reduceRight(function (memo, func) {
|
|
225
|
+
return func(memo);
|
|
226
|
+
}, raw);
|
|
227
|
+
};
|
|
228
|
+
}
|
|
229
|
+
/**
|
|
230
|
+
* Removes marks from nodes in the current selection that are not supported
|
|
231
|
+
*/
|
|
232
|
+
|
|
233
|
+
|
|
234
|
+
var sanitiseSelectionMarksForWrapping = function sanitiseSelectionMarksForWrapping(state, newParentType) {
|
|
235
|
+
var tr;
|
|
236
|
+
var _state$tr$selection = state.tr.selection,
|
|
237
|
+
from = _state$tr$selection.from,
|
|
238
|
+
to = _state$tr$selection.to;
|
|
239
|
+
state.doc.nodesBetween(from, to, function (node, pos, parent) {
|
|
240
|
+
// If iterate over a node thats out of our defined range
|
|
241
|
+
// We skip here but continue to iterate over its children.
|
|
242
|
+
if (node.isText || pos < from || pos > to) {
|
|
243
|
+
return true;
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
node.marks.forEach(function (mark) {
|
|
247
|
+
if (!parent.type.allowsMarkType(mark.type) || newParentType && !newParentType.allowsMarkType(mark.type)) {
|
|
248
|
+
var filteredMarks = node.marks.filter(function (m) {
|
|
249
|
+
return m.type !== mark.type;
|
|
250
|
+
});
|
|
251
|
+
var position = pos > 0 ? pos - 1 : 0;
|
|
252
|
+
tr = (tr || state.tr).setNodeMarkup(position, undefined, node.attrs, filteredMarks);
|
|
253
|
+
}
|
|
254
|
+
});
|
|
255
|
+
}, from);
|
|
256
|
+
return tr;
|
|
257
|
+
};
|
|
258
|
+
|
|
259
|
+
exports.sanitiseSelectionMarksForWrapping = sanitiseSelectionMarksForWrapping;
|
|
260
|
+
|
|
261
|
+
function isAttrEquals(node, attrs) {
|
|
262
|
+
for (var key in attrs) {
|
|
263
|
+
if (attrs[key] != node.attrs[key]) return false;
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
return true;
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
function isBlockActive(state, type) {
|
|
270
|
+
var attrs = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
271
|
+
var _state$selection = state.selection,
|
|
272
|
+
from = _state$selection.from,
|
|
273
|
+
to = _state$selection.to;
|
|
274
|
+
var active = false;
|
|
275
|
+
state.doc.nodesBetween(from, to, function (node) {
|
|
276
|
+
if (active) return false;
|
|
277
|
+
if (node.type.name == type && isAttrEquals(node, attrs)) active = true;
|
|
278
|
+
return !active;
|
|
279
|
+
});
|
|
280
|
+
return active;
|
|
281
|
+
}
|