@tiptap/core 2.0.0-beta.160 → 2.0.0-beta.164
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/PasteRule.d.ts +3 -3
- package/dist/packages/core/src/index.d.ts +1 -0
- package/dist/packages/core/src/utilities/escapeForRegEx.d.ts +1 -0
- package/dist/tiptap-core.cjs.js +102 -72
- package/dist/tiptap-core.cjs.js.map +1 -1
- package/dist/tiptap-core.esm.js +102 -73
- package/dist/tiptap-core.esm.js.map +1 -1
- package/dist/tiptap-core.umd.js +102 -72
- package/dist/tiptap-core.umd.js.map +1 -1
- package/package.json +4 -3
- package/src/ExtensionManager.ts +1 -1
- package/src/InputRule.ts +5 -5
- package/src/PasteRule.ts +103 -72
- package/src/index.ts +1 -0
- package/src/inputRules/markInputRule.ts +1 -1
- package/src/pasteRules/markPasteRule.ts +1 -1
- package/src/utilities/escapeForRegEx.ts +4 -0
|
@@ -18,7 +18,7 @@ export declare class InputRule {
|
|
|
18
18
|
commands: SingleCommands;
|
|
19
19
|
chain: () => ChainedCommands;
|
|
20
20
|
can: () => CanCommands;
|
|
21
|
-
}) => void;
|
|
21
|
+
}) => void | null;
|
|
22
22
|
constructor(config: {
|
|
23
23
|
find: InputRuleFinder;
|
|
24
24
|
handler: (props: {
|
|
@@ -28,7 +28,7 @@ export declare class InputRule {
|
|
|
28
28
|
commands: SingleCommands;
|
|
29
29
|
chain: () => ChainedCommands;
|
|
30
30
|
can: () => CanCommands;
|
|
31
|
-
}) => void;
|
|
31
|
+
}) => void | null;
|
|
32
32
|
});
|
|
33
33
|
}
|
|
34
34
|
/**
|
|
@@ -18,7 +18,7 @@ export declare class PasteRule {
|
|
|
18
18
|
commands: SingleCommands;
|
|
19
19
|
chain: () => ChainedCommands;
|
|
20
20
|
can: () => CanCommands;
|
|
21
|
-
}) => void;
|
|
21
|
+
}) => void | null;
|
|
22
22
|
constructor(config: {
|
|
23
23
|
find: PasteRuleFinder;
|
|
24
24
|
handler: (props: {
|
|
@@ -28,7 +28,7 @@ export declare class PasteRule {
|
|
|
28
28
|
commands: SingleCommands;
|
|
29
29
|
chain: () => ChainedCommands;
|
|
30
30
|
can: () => CanCommands;
|
|
31
|
-
}) => void;
|
|
31
|
+
}) => void | null;
|
|
32
32
|
});
|
|
33
33
|
}
|
|
34
34
|
/**
|
|
@@ -39,4 +39,4 @@ export declare class PasteRule {
|
|
|
39
39
|
export declare function pasteRulesPlugin(props: {
|
|
40
40
|
editor: Editor;
|
|
41
41
|
rules: PasteRule[];
|
|
42
|
-
}): Plugin;
|
|
42
|
+
}): Plugin[];
|
|
@@ -18,6 +18,7 @@ export * from './inputRules/wrappingInputRule';
|
|
|
18
18
|
export * from './pasteRules/markPasteRule';
|
|
19
19
|
export * from './pasteRules/textPasteRule';
|
|
20
20
|
export * from './utilities/callOrReturn';
|
|
21
|
+
export * from './utilities/escapeForRegEx';
|
|
21
22
|
export * from './utilities/mergeAttributes';
|
|
22
23
|
export * from './helpers/combineTransactionSteps';
|
|
23
24
|
export * from './helpers/defaultBlockAt';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function escapeForRegEx(string: string): string;
|
package/dist/tiptap-core.cjs.js
CHANGED
|
@@ -2274,7 +2274,7 @@ function run$1(config) {
|
|
|
2274
2274
|
editor,
|
|
2275
2275
|
state,
|
|
2276
2276
|
});
|
|
2277
|
-
rule.handler({
|
|
2277
|
+
const handler = rule.handler({
|
|
2278
2278
|
state,
|
|
2279
2279
|
range,
|
|
2280
2280
|
match,
|
|
@@ -2283,7 +2283,7 @@ function run$1(config) {
|
|
|
2283
2283
|
can,
|
|
2284
2284
|
});
|
|
2285
2285
|
// stop if there are no changes
|
|
2286
|
-
if (!tr.steps.length) {
|
|
2286
|
+
if (handler === null || !tr.steps.length) {
|
|
2287
2287
|
return;
|
|
2288
2288
|
}
|
|
2289
2289
|
// store transform as meta data
|
|
@@ -2410,11 +2410,12 @@ const pasteRuleMatcherHandler = (text, find) => {
|
|
|
2410
2410
|
});
|
|
2411
2411
|
};
|
|
2412
2412
|
function run(config) {
|
|
2413
|
-
const { editor, state, from, to,
|
|
2413
|
+
const { editor, state, from, to, rule, } = config;
|
|
2414
2414
|
const { commands, chain, can } = new CommandManager({
|
|
2415
2415
|
editor,
|
|
2416
2416
|
state,
|
|
2417
2417
|
});
|
|
2418
|
+
const handlers = [];
|
|
2418
2419
|
state.doc.nodesBetween(from, to, (node, pos) => {
|
|
2419
2420
|
if (!node.isTextblock || node.type.spec.code) {
|
|
2420
2421
|
return;
|
|
@@ -2422,29 +2423,30 @@ function run(config) {
|
|
|
2422
2423
|
const resolvedFrom = Math.max(from, pos);
|
|
2423
2424
|
const resolvedTo = Math.min(to, pos + node.content.size);
|
|
2424
2425
|
const textToMatch = node.textBetween(resolvedFrom - pos, resolvedTo - pos, undefined, '\ufffc');
|
|
2425
|
-
|
|
2426
|
-
|
|
2427
|
-
|
|
2428
|
-
|
|
2429
|
-
|
|
2430
|
-
|
|
2431
|
-
|
|
2432
|
-
|
|
2433
|
-
|
|
2434
|
-
|
|
2435
|
-
|
|
2436
|
-
|
|
2437
|
-
|
|
2438
|
-
|
|
2439
|
-
|
|
2440
|
-
|
|
2441
|
-
|
|
2442
|
-
|
|
2443
|
-
can,
|
|
2444
|
-
});
|
|
2426
|
+
const matches = pasteRuleMatcherHandler(textToMatch, rule.find);
|
|
2427
|
+
matches.forEach(match => {
|
|
2428
|
+
if (match.index === undefined) {
|
|
2429
|
+
return;
|
|
2430
|
+
}
|
|
2431
|
+
const start = resolvedFrom + match.index + 1;
|
|
2432
|
+
const end = start + match[0].length;
|
|
2433
|
+
const range = {
|
|
2434
|
+
from: state.tr.mapping.map(start),
|
|
2435
|
+
to: state.tr.mapping.map(end),
|
|
2436
|
+
};
|
|
2437
|
+
const handler = rule.handler({
|
|
2438
|
+
state,
|
|
2439
|
+
range,
|
|
2440
|
+
match,
|
|
2441
|
+
commands,
|
|
2442
|
+
chain,
|
|
2443
|
+
can,
|
|
2445
2444
|
});
|
|
2445
|
+
handlers.push(handler);
|
|
2446
2446
|
});
|
|
2447
2447
|
});
|
|
2448
|
+
const success = handlers.every(handler => handler !== null);
|
|
2449
|
+
return success;
|
|
2448
2450
|
}
|
|
2449
2451
|
/**
|
|
2450
2452
|
* Create an paste rules plugin. When enabled, it will cause pasted
|
|
@@ -2453,54 +2455,76 @@ function run(config) {
|
|
|
2453
2455
|
*/
|
|
2454
2456
|
function pasteRulesPlugin(props) {
|
|
2455
2457
|
const { editor, rules } = props;
|
|
2456
|
-
let
|
|
2457
|
-
|
|
2458
|
-
|
|
2459
|
-
|
|
2460
|
-
|
|
2461
|
-
|
|
2462
|
-
|
|
2463
|
-
|
|
2458
|
+
let dragSourceElement = null;
|
|
2459
|
+
let isPastedFromProseMirror = false;
|
|
2460
|
+
let isDroppedFromProseMirror = false;
|
|
2461
|
+
const plugins = rules.map(rule => {
|
|
2462
|
+
return new prosemirrorState.Plugin({
|
|
2463
|
+
// we register a global drag handler to track the current drag source element
|
|
2464
|
+
view(view) {
|
|
2465
|
+
const handleDragstart = (event) => {
|
|
2466
|
+
var _a;
|
|
2467
|
+
dragSourceElement = ((_a = view.dom.parentElement) === null || _a === void 0 ? void 0 : _a.contains(event.target))
|
|
2468
|
+
? view.dom.parentElement
|
|
2469
|
+
: null;
|
|
2470
|
+
};
|
|
2471
|
+
window.addEventListener('dragstart', handleDragstart);
|
|
2472
|
+
return {
|
|
2473
|
+
destroy() {
|
|
2474
|
+
window.removeEventListener('dragstart', handleDragstart);
|
|
2475
|
+
},
|
|
2476
|
+
};
|
|
2464
2477
|
},
|
|
2465
|
-
|
|
2466
|
-
|
|
2467
|
-
|
|
2468
|
-
|
|
2469
|
-
|
|
2470
|
-
|
|
2471
|
-
|
|
2472
|
-
|
|
2473
|
-
|
|
2474
|
-
|
|
2475
|
-
|
|
2476
|
-
|
|
2477
|
-
|
|
2478
|
-
}
|
|
2479
|
-
|
|
2480
|
-
|
|
2481
|
-
|
|
2482
|
-
|
|
2483
|
-
|
|
2484
|
-
|
|
2485
|
-
|
|
2486
|
-
|
|
2487
|
-
|
|
2488
|
-
state
|
|
2489
|
-
|
|
2490
|
-
|
|
2491
|
-
|
|
2492
|
-
|
|
2493
|
-
|
|
2494
|
-
|
|
2495
|
-
|
|
2496
|
-
|
|
2497
|
-
|
|
2498
|
-
|
|
2499
|
-
|
|
2500
|
-
|
|
2501
|
-
|
|
2478
|
+
props: {
|
|
2479
|
+
handleDOMEvents: {
|
|
2480
|
+
drop: view => {
|
|
2481
|
+
isDroppedFromProseMirror = dragSourceElement === view.dom.parentElement;
|
|
2482
|
+
return false;
|
|
2483
|
+
},
|
|
2484
|
+
paste: (view, event) => {
|
|
2485
|
+
var _a;
|
|
2486
|
+
const html = (_a = event.clipboardData) === null || _a === void 0 ? void 0 : _a.getData('text/html');
|
|
2487
|
+
isPastedFromProseMirror = !!(html === null || html === void 0 ? void 0 : html.includes('data-pm-slice'));
|
|
2488
|
+
return false;
|
|
2489
|
+
},
|
|
2490
|
+
},
|
|
2491
|
+
},
|
|
2492
|
+
appendTransaction: (transactions, oldState, state) => {
|
|
2493
|
+
const transaction = transactions[0];
|
|
2494
|
+
const isPaste = transaction.getMeta('uiEvent') === 'paste' && !isPastedFromProseMirror;
|
|
2495
|
+
const isDrop = transaction.getMeta('uiEvent') === 'drop' && !isDroppedFromProseMirror;
|
|
2496
|
+
if (!isPaste && !isDrop) {
|
|
2497
|
+
return;
|
|
2498
|
+
}
|
|
2499
|
+
// stop if there is no changed range
|
|
2500
|
+
const from = oldState.doc.content.findDiffStart(state.doc.content);
|
|
2501
|
+
const to = oldState.doc.content.findDiffEnd(state.doc.content);
|
|
2502
|
+
if (!isNumber(from) || !to || from === to.b) {
|
|
2503
|
+
return;
|
|
2504
|
+
}
|
|
2505
|
+
// build a chainable state
|
|
2506
|
+
// so we can use a single transaction for all paste rules
|
|
2507
|
+
const tr = state.tr;
|
|
2508
|
+
const chainableState = createChainableState({
|
|
2509
|
+
state,
|
|
2510
|
+
transaction: tr,
|
|
2511
|
+
});
|
|
2512
|
+
const handler = run({
|
|
2513
|
+
editor,
|
|
2514
|
+
state: chainableState,
|
|
2515
|
+
from: Math.max(from - 1, 0),
|
|
2516
|
+
to: to.b,
|
|
2517
|
+
rule,
|
|
2518
|
+
});
|
|
2519
|
+
// stop if there are no changes
|
|
2520
|
+
if (!handler || !tr.steps.length) {
|
|
2521
|
+
return;
|
|
2522
|
+
}
|
|
2523
|
+
return tr;
|
|
2524
|
+
},
|
|
2525
|
+
});
|
|
2502
2526
|
});
|
|
2503
|
-
return
|
|
2527
|
+
return plugins;
|
|
2504
2528
|
}
|
|
2505
2529
|
|
|
2506
2530
|
/**
|
|
@@ -2974,7 +2998,7 @@ class ExtensionManager {
|
|
|
2974
2998
|
editor,
|
|
2975
2999
|
rules: inputRules,
|
|
2976
3000
|
}),
|
|
2977
|
-
pasteRulesPlugin({
|
|
3001
|
+
...pasteRulesPlugin({
|
|
2978
3002
|
editor,
|
|
2979
3003
|
rules: pasteRules,
|
|
2980
3004
|
}),
|
|
@@ -3893,7 +3917,7 @@ function markInputRule(config) {
|
|
|
3893
3917
|
handler: ({ state, range, match }) => {
|
|
3894
3918
|
const attributes = callOrReturn(config.getAttributes, undefined, match);
|
|
3895
3919
|
if (attributes === false || attributes === null) {
|
|
3896
|
-
return;
|
|
3920
|
+
return null;
|
|
3897
3921
|
}
|
|
3898
3922
|
const { tr } = state;
|
|
3899
3923
|
const captureGroup = match[match.length - 1];
|
|
@@ -4023,7 +4047,7 @@ function markPasteRule(config) {
|
|
|
4023
4047
|
handler: ({ state, range, match }) => {
|
|
4024
4048
|
const attributes = callOrReturn(config.getAttributes, undefined, match);
|
|
4025
4049
|
if (attributes === false || attributes === null) {
|
|
4026
|
-
return;
|
|
4050
|
+
return null;
|
|
4027
4051
|
}
|
|
4028
4052
|
const { tr } = state;
|
|
4029
4053
|
const captureGroup = match[match.length - 1];
|
|
@@ -4083,6 +4107,11 @@ function textPasteRule(config) {
|
|
|
4083
4107
|
});
|
|
4084
4108
|
}
|
|
4085
4109
|
|
|
4110
|
+
// source: https://stackoverflow.com/a/6969486
|
|
4111
|
+
function escapeForRegEx(string) {
|
|
4112
|
+
return string.replace(/[-/\\^$*+?.()|[\]{}]/g, '\\$&');
|
|
4113
|
+
}
|
|
4114
|
+
|
|
4086
4115
|
/**
|
|
4087
4116
|
* Returns a new `Transform` based on all steps of the passed transactions.
|
|
4088
4117
|
*/
|
|
@@ -4338,6 +4367,7 @@ exports.Tracker = Tracker;
|
|
|
4338
4367
|
exports.callOrReturn = callOrReturn;
|
|
4339
4368
|
exports.combineTransactionSteps = combineTransactionSteps;
|
|
4340
4369
|
exports.defaultBlockAt = defaultBlockAt;
|
|
4370
|
+
exports.escapeForRegEx = escapeForRegEx;
|
|
4341
4371
|
exports.extensions = extensions;
|
|
4342
4372
|
exports.findChildren = findChildren;
|
|
4343
4373
|
exports.findChildrenInRange = findChildrenInRange;
|