@tiptap/core 2.0.0-beta.159 → 2.0.0-beta.162
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/dist/packages/core/src/InputRule.d.ts +2 -2
- package/dist/packages/core/src/Node.d.ts +9 -0
- package/dist/packages/core/src/PasteRule.d.ts +3 -3
- package/dist/tiptap-core.cjs.js +71 -71
- package/dist/tiptap-core.cjs.js.map +1 -1
- package/dist/tiptap-core.esm.js +71 -71
- package/dist/tiptap-core.esm.js.map +1 -1
- package/dist/tiptap-core.umd.js +71 -71
- package/dist/tiptap-core.umd.js.map +1 -1
- package/package.json +6 -5
- package/src/ExtensionManager.ts +1 -1
- package/src/InputRule.ts +5 -5
- package/src/Node.ts +10 -0
- package/src/PasteRule.ts +74 -72
- package/src/inputRules/markInputRule.ts +1 -1
- package/src/pasteRules/markPasteRule.ts +1 -1
package/dist/tiptap-core.esm.js
CHANGED
|
@@ -2270,7 +2270,7 @@ function run$1(config) {
|
|
|
2270
2270
|
editor,
|
|
2271
2271
|
state,
|
|
2272
2272
|
});
|
|
2273
|
-
rule.handler({
|
|
2273
|
+
const handler = rule.handler({
|
|
2274
2274
|
state,
|
|
2275
2275
|
range,
|
|
2276
2276
|
match,
|
|
@@ -2279,7 +2279,7 @@ function run$1(config) {
|
|
|
2279
2279
|
can,
|
|
2280
2280
|
});
|
|
2281
2281
|
// stop if there are no changes
|
|
2282
|
-
if (!tr.steps.length) {
|
|
2282
|
+
if (handler === null || !tr.steps.length) {
|
|
2283
2283
|
return;
|
|
2284
2284
|
}
|
|
2285
2285
|
// store transform as meta data
|
|
@@ -2406,11 +2406,12 @@ const pasteRuleMatcherHandler = (text, find) => {
|
|
|
2406
2406
|
});
|
|
2407
2407
|
};
|
|
2408
2408
|
function run(config) {
|
|
2409
|
-
const { editor, state, from, to,
|
|
2409
|
+
const { editor, state, from, to, rule, } = config;
|
|
2410
2410
|
const { commands, chain, can } = new CommandManager({
|
|
2411
2411
|
editor,
|
|
2412
2412
|
state,
|
|
2413
2413
|
});
|
|
2414
|
+
const handlers = [];
|
|
2414
2415
|
state.doc.nodesBetween(from, to, (node, pos) => {
|
|
2415
2416
|
if (!node.isTextblock || node.type.spec.code) {
|
|
2416
2417
|
return;
|
|
@@ -2418,29 +2419,30 @@ function run(config) {
|
|
|
2418
2419
|
const resolvedFrom = Math.max(from, pos);
|
|
2419
2420
|
const resolvedTo = Math.min(to, pos + node.content.size);
|
|
2420
2421
|
const textToMatch = node.textBetween(resolvedFrom - pos, resolvedTo - pos, undefined, '\ufffc');
|
|
2421
|
-
|
|
2422
|
-
|
|
2423
|
-
|
|
2424
|
-
|
|
2425
|
-
|
|
2426
|
-
|
|
2427
|
-
|
|
2428
|
-
|
|
2429
|
-
|
|
2430
|
-
|
|
2431
|
-
|
|
2432
|
-
|
|
2433
|
-
|
|
2434
|
-
|
|
2435
|
-
|
|
2436
|
-
|
|
2437
|
-
|
|
2438
|
-
|
|
2439
|
-
can,
|
|
2440
|
-
});
|
|
2422
|
+
const matches = pasteRuleMatcherHandler(textToMatch, rule.find);
|
|
2423
|
+
matches.forEach(match => {
|
|
2424
|
+
if (match.index === undefined) {
|
|
2425
|
+
return;
|
|
2426
|
+
}
|
|
2427
|
+
const start = resolvedFrom + match.index + 1;
|
|
2428
|
+
const end = start + match[0].length;
|
|
2429
|
+
const range = {
|
|
2430
|
+
from: state.tr.mapping.map(start),
|
|
2431
|
+
to: state.tr.mapping.map(end),
|
|
2432
|
+
};
|
|
2433
|
+
const handler = rule.handler({
|
|
2434
|
+
state,
|
|
2435
|
+
range,
|
|
2436
|
+
match,
|
|
2437
|
+
commands,
|
|
2438
|
+
chain,
|
|
2439
|
+
can,
|
|
2441
2440
|
});
|
|
2441
|
+
handlers.push(handler);
|
|
2442
2442
|
});
|
|
2443
2443
|
});
|
|
2444
|
+
const success = handlers.every(handler => handler !== null);
|
|
2445
|
+
return success;
|
|
2444
2446
|
}
|
|
2445
2447
|
/**
|
|
2446
2448
|
* Create an paste rules plugin. When enabled, it will cause pasted
|
|
@@ -2450,53 +2452,51 @@ function run(config) {
|
|
|
2450
2452
|
function pasteRulesPlugin(props) {
|
|
2451
2453
|
const { editor, rules } = props;
|
|
2452
2454
|
let isProseMirrorHTML = false;
|
|
2453
|
-
const
|
|
2454
|
-
|
|
2455
|
-
|
|
2456
|
-
|
|
2457
|
-
|
|
2458
|
-
|
|
2459
|
-
|
|
2455
|
+
const plugins = rules.map(rule => {
|
|
2456
|
+
return new Plugin({
|
|
2457
|
+
props: {
|
|
2458
|
+
handlePaste: (view, event) => {
|
|
2459
|
+
var _a;
|
|
2460
|
+
const html = (_a = event.clipboardData) === null || _a === void 0 ? void 0 : _a.getData('text/html');
|
|
2461
|
+
isProseMirrorHTML = !!(html === null || html === void 0 ? void 0 : html.includes('data-pm-slice'));
|
|
2462
|
+
return false;
|
|
2463
|
+
},
|
|
2460
2464
|
},
|
|
2461
|
-
|
|
2462
|
-
|
|
2463
|
-
|
|
2464
|
-
|
|
2465
|
-
|
|
2466
|
-
|
|
2467
|
-
|
|
2468
|
-
|
|
2469
|
-
|
|
2470
|
-
|
|
2471
|
-
|
|
2472
|
-
|
|
2473
|
-
|
|
2474
|
-
|
|
2475
|
-
|
|
2476
|
-
|
|
2477
|
-
|
|
2478
|
-
|
|
2479
|
-
|
|
2480
|
-
|
|
2481
|
-
|
|
2482
|
-
|
|
2483
|
-
|
|
2484
|
-
|
|
2485
|
-
|
|
2486
|
-
|
|
2487
|
-
|
|
2488
|
-
|
|
2489
|
-
|
|
2490
|
-
|
|
2491
|
-
|
|
2492
|
-
|
|
2493
|
-
|
|
2494
|
-
return tr;
|
|
2495
|
-
},
|
|
2496
|
-
// @ts-ignore
|
|
2497
|
-
isPasteRules: true,
|
|
2465
|
+
appendTransaction: (transactions, oldState, state) => {
|
|
2466
|
+
const transaction = transactions[0];
|
|
2467
|
+
// stop if there is not a paste event
|
|
2468
|
+
if (!transaction.getMeta('paste') || isProseMirrorHTML) {
|
|
2469
|
+
return;
|
|
2470
|
+
}
|
|
2471
|
+
// stop if there is no changed range
|
|
2472
|
+
const from = oldState.doc.content.findDiffStart(state.doc.content);
|
|
2473
|
+
const to = oldState.doc.content.findDiffEnd(state.doc.content);
|
|
2474
|
+
if (!isNumber(from) || !to || from === to.b) {
|
|
2475
|
+
return;
|
|
2476
|
+
}
|
|
2477
|
+
// build a chainable state
|
|
2478
|
+
// so we can use a single transaction for all paste rules
|
|
2479
|
+
const tr = state.tr;
|
|
2480
|
+
const chainableState = createChainableState({
|
|
2481
|
+
state,
|
|
2482
|
+
transaction: tr,
|
|
2483
|
+
});
|
|
2484
|
+
const handler = run({
|
|
2485
|
+
editor,
|
|
2486
|
+
state: chainableState,
|
|
2487
|
+
from: Math.max(from - 1, 0),
|
|
2488
|
+
to: to.b,
|
|
2489
|
+
rule,
|
|
2490
|
+
});
|
|
2491
|
+
// stop if there are no changes
|
|
2492
|
+
if (!handler || !tr.steps.length) {
|
|
2493
|
+
return;
|
|
2494
|
+
}
|
|
2495
|
+
return tr;
|
|
2496
|
+
},
|
|
2497
|
+
});
|
|
2498
2498
|
});
|
|
2499
|
-
return
|
|
2499
|
+
return plugins;
|
|
2500
2500
|
}
|
|
2501
2501
|
|
|
2502
2502
|
/**
|
|
@@ -2970,7 +2970,7 @@ class ExtensionManager {
|
|
|
2970
2970
|
editor,
|
|
2971
2971
|
rules: inputRules,
|
|
2972
2972
|
}),
|
|
2973
|
-
pasteRulesPlugin({
|
|
2973
|
+
...pasteRulesPlugin({
|
|
2974
2974
|
editor,
|
|
2975
2975
|
rules: pasteRules,
|
|
2976
2976
|
}),
|
|
@@ -3889,7 +3889,7 @@ function markInputRule(config) {
|
|
|
3889
3889
|
handler: ({ state, range, match }) => {
|
|
3890
3890
|
const attributes = callOrReturn(config.getAttributes, undefined, match);
|
|
3891
3891
|
if (attributes === false || attributes === null) {
|
|
3892
|
-
return;
|
|
3892
|
+
return null;
|
|
3893
3893
|
}
|
|
3894
3894
|
const { tr } = state;
|
|
3895
3895
|
const captureGroup = match[match.length - 1];
|
|
@@ -4019,7 +4019,7 @@ function markPasteRule(config) {
|
|
|
4019
4019
|
handler: ({ state, range, match }) => {
|
|
4020
4020
|
const attributes = callOrReturn(config.getAttributes, undefined, match);
|
|
4021
4021
|
if (attributes === false || attributes === null) {
|
|
4022
|
-
return;
|
|
4022
|
+
return null;
|
|
4023
4023
|
}
|
|
4024
4024
|
const { tr } = state;
|
|
4025
4025
|
const captureGroup = match[match.length - 1];
|