@harbour-enterprises/superdoc 0.8.10 → 0.8.11
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/chunks/{super-editor.es-CnpejCPC.js → super-editor.es-DIeHC3Si.js} +484 -168
- package/dist/chunks/super-editor.es-DIeHC3Si.js.map +1 -0
- package/dist/super-editor/chunks/{converter-B5SRaBp5.js → converter-CVSaF15S.js} +28 -27
- package/dist/super-editor/chunks/converter-CVSaF15S.js.map +1 -0
- package/dist/super-editor/chunks/{docx-zipper-fdMcchlI.js → docx-zipper-BHwY_rz6.js} +2 -2
- package/dist/super-editor/chunks/{docx-zipper-fdMcchlI.js.map → docx-zipper-BHwY_rz6.js.map} +1 -1
- package/dist/super-editor/chunks/{editor-nlt5JeOJ.js → editor-H6Apbtdi.js} +481 -165
- package/dist/super-editor/chunks/editor-H6Apbtdi.js.map +1 -0
- package/dist/super-editor/chunks/{toolbar-COfngBDY.js → toolbar-D9ELD8Tt.js} +3 -3
- package/dist/super-editor/chunks/{toolbar-COfngBDY.js.map → toolbar-D9ELD8Tt.js.map} +1 -1
- package/dist/super-editor/converter.es.js +2 -2
- package/dist/super-editor/core/Editor.d.ts +1 -0
- package/dist/super-editor/core/Editor.d.ts.map +1 -1
- package/dist/super-editor/core/ExtensionService.d.ts.map +1 -1
- package/dist/super-editor/core/InputRule.d.ts +11 -0
- package/dist/super-editor/core/InputRule.d.ts.map +1 -0
- package/dist/super-editor/core/commands/index.d.ts +1 -0
- package/dist/super-editor/core/commands/undoInputRule.d.ts +5 -0
- package/dist/super-editor/core/commands/undoInputRule.d.ts.map +1 -0
- package/dist/super-editor/core/extensions/keymap.d.ts.map +1 -1
- package/dist/super-editor/core/helpers/getHTMLFromFragment.d.ts +2 -0
- package/dist/super-editor/core/helpers/getHTMLFromFragment.d.ts.map +1 -0
- package/dist/super-editor/core/helpers/getTextContentFromNodes.d.ts +2 -0
- package/dist/super-editor/core/helpers/getTextContentFromNodes.d.ts.map +1 -0
- package/dist/super-editor/core/helpers/isExtentionRulesEnabled.d.ts +2 -0
- package/dist/super-editor/core/helpers/isExtentionRulesEnabled.d.ts.map +1 -0
- package/dist/super-editor/core/inputRules/wrappingInputRule.d.ts +9 -0
- package/dist/super-editor/core/inputRules/wrappingInputRule.d.ts.map +1 -0
- package/dist/super-editor/core/utilities/isRegExp.d.ts +2 -0
- package/dist/super-editor/core/utilities/isRegExp.d.ts.map +1 -0
- package/dist/super-editor/core/utilities/objectIncludes.d.ts.map +1 -1
- package/dist/super-editor/docx-zipper.es.js +2 -2
- package/dist/super-editor/editor.es.js +3 -3
- package/dist/super-editor/extensions/bullet-list/bullet-list.d.ts.map +1 -1
- package/dist/super-editor/extensions/ordered-list/ordered-list.d.ts.map +1 -1
- package/dist/super-editor/file-zipper.es.js +1 -1
- package/dist/super-editor/super-editor.es.js +7 -7
- package/dist/super-editor/toolbar.es.js +2 -2
- package/dist/super-editor.es.js +1 -1
- package/dist/superdoc.es.js +3 -3
- package/dist/superdoc.umd.js +495 -179
- package/dist/superdoc.umd.js.map +1 -1
- package/package.json +1 -1
- package/dist/chunks/super-editor.es-CnpejCPC.js.map +0 -1
- package/dist/super-editor/chunks/converter-B5SRaBp5.js.map +0 -1
- package/dist/super-editor/chunks/editor-nlt5JeOJ.js.map +0 -1
|
@@ -19161,7 +19161,7 @@ const isPropertiesElement = (element) => {
|
|
|
19161
19161
|
};
|
|
19162
19162
|
function hasTextNode(elements) {
|
|
19163
19163
|
const runs = elements.filter((el) => el.name === "w:r");
|
|
19164
|
-
const runsHaveText = runs.some((
|
|
19164
|
+
const runsHaveText = runs.some((run2) => run2.elements.some((el) => el.name === "w:t"));
|
|
19165
19165
|
return runsHaveText;
|
|
19166
19166
|
}
|
|
19167
19167
|
const handleTrackChangeNode = (params2) => {
|
|
@@ -20060,8 +20060,8 @@ const handleAnnotationNode = (params2) => {
|
|
|
20060
20060
|
};
|
|
20061
20061
|
};
|
|
20062
20062
|
const parseAnnotationMarks = (content = {}) => {
|
|
20063
|
-
const
|
|
20064
|
-
const rPr =
|
|
20063
|
+
const run2 = content.elements?.find((el) => el.name === "w:r");
|
|
20064
|
+
const rPr = run2?.elements?.find((el) => el.name === "w:rPr");
|
|
20065
20065
|
if (!rPr) return {};
|
|
20066
20066
|
const unknownMarks = [];
|
|
20067
20067
|
const marks = parseMarks(rPr, unknownMarks) || [];
|
|
@@ -20664,7 +20664,7 @@ const _SuperConverter = class _SuperConverter2 {
|
|
|
20664
20664
|
return;
|
|
20665
20665
|
}
|
|
20666
20666
|
}
|
|
20667
|
-
static updateDocumentVersion(docx = this.convertedXml, version = "0.8.
|
|
20667
|
+
static updateDocumentVersion(docx = this.convertedXml, version = "0.8.11") {
|
|
20668
20668
|
const customLocation = "docProps/custom.xml";
|
|
20669
20669
|
if (!docx[customLocation]) {
|
|
20670
20670
|
docx[customLocation] = generateCustomXml();
|
|
@@ -20937,7 +20937,7 @@ function storeSuperdocVersion(docx) {
|
|
|
20937
20937
|
function generateCustomXml() {
|
|
20938
20938
|
return DEFAULT_CUSTOM_XML;
|
|
20939
20939
|
}
|
|
20940
|
-
function generateSuperdocVersion(pid = 2, version = "0.8.
|
|
20940
|
+
function generateSuperdocVersion(pid = 2, version = "0.8.11") {
|
|
20941
20941
|
return {
|
|
20942
20942
|
type: "element",
|
|
20943
20943
|
name: "property",
|
|
@@ -31398,6 +31398,357 @@ let Schema2 = _Schema;
|
|
|
31398
31398
|
function getSchemaTypeByName(name, schema) {
|
|
31399
31399
|
return schema.nodes[name] || schema.marks[name] || null;
|
|
31400
31400
|
}
|
|
31401
|
+
function isExtensionRulesEnabled(extension, enabled) {
|
|
31402
|
+
if (Array.isArray(enabled)) {
|
|
31403
|
+
return enabled.some((enabledExtension) => {
|
|
31404
|
+
const name = typeof enabledExtension === "string" ? enabledExtension : enabledExtension.name;
|
|
31405
|
+
return name === extension.name;
|
|
31406
|
+
});
|
|
31407
|
+
}
|
|
31408
|
+
return enabled;
|
|
31409
|
+
}
|
|
31410
|
+
function chainableEditorState(transaction, state2) {
|
|
31411
|
+
let { selection, doc: doc2, storedMarks } = transaction;
|
|
31412
|
+
return {
|
|
31413
|
+
...state2,
|
|
31414
|
+
apply: state2.apply.bind(state2),
|
|
31415
|
+
applyTransaction: state2.applyTransaction.bind(state2),
|
|
31416
|
+
plugins: state2.plugins,
|
|
31417
|
+
schema: state2.schema,
|
|
31418
|
+
reconfigure: state2.reconfigure.bind(state2),
|
|
31419
|
+
toJSON: state2.toJSON.bind(state2),
|
|
31420
|
+
get storedMarks() {
|
|
31421
|
+
return storedMarks;
|
|
31422
|
+
},
|
|
31423
|
+
get selection() {
|
|
31424
|
+
return selection;
|
|
31425
|
+
},
|
|
31426
|
+
get doc() {
|
|
31427
|
+
return doc2;
|
|
31428
|
+
},
|
|
31429
|
+
get tr() {
|
|
31430
|
+
selection = transaction.selection;
|
|
31431
|
+
doc2 = transaction.doc;
|
|
31432
|
+
storedMarks = transaction.storedMarks;
|
|
31433
|
+
return transaction;
|
|
31434
|
+
}
|
|
31435
|
+
};
|
|
31436
|
+
}
|
|
31437
|
+
class CommandService {
|
|
31438
|
+
constructor(props) {
|
|
31439
|
+
__publicField$1(this, "editor");
|
|
31440
|
+
__publicField$1(this, "rawCommands");
|
|
31441
|
+
this.editor = props.editor;
|
|
31442
|
+
this.rawCommands = this.editor.extensionService.commands;
|
|
31443
|
+
}
|
|
31444
|
+
/**
|
|
31445
|
+
* Static method for creating a service.
|
|
31446
|
+
* @param args Arguments for the constructor.
|
|
31447
|
+
*/
|
|
31448
|
+
static create(...args) {
|
|
31449
|
+
return new CommandService(...args);
|
|
31450
|
+
}
|
|
31451
|
+
/**
|
|
31452
|
+
* Get editor state.
|
|
31453
|
+
*/
|
|
31454
|
+
get state() {
|
|
31455
|
+
return this.editor.state;
|
|
31456
|
+
}
|
|
31457
|
+
/**
|
|
31458
|
+
* Get all commands with wrapped command method.
|
|
31459
|
+
*/
|
|
31460
|
+
get commands() {
|
|
31461
|
+
const { editor, state: state2 } = this;
|
|
31462
|
+
const { view } = editor;
|
|
31463
|
+
const { tr } = state2;
|
|
31464
|
+
const props = this.createProps(tr);
|
|
31465
|
+
const entries = Object.entries(this.rawCommands).map(([name, command2]) => {
|
|
31466
|
+
const method = (...args) => {
|
|
31467
|
+
const fn2 = command2(...args)(props);
|
|
31468
|
+
if (!tr.getMeta("preventDispatch")) {
|
|
31469
|
+
view.dispatch(tr);
|
|
31470
|
+
}
|
|
31471
|
+
return fn2;
|
|
31472
|
+
};
|
|
31473
|
+
return [name, method];
|
|
31474
|
+
});
|
|
31475
|
+
return Object.fromEntries(entries);
|
|
31476
|
+
}
|
|
31477
|
+
/**
|
|
31478
|
+
* Create a chain of commands to call multiple commands at once.
|
|
31479
|
+
*/
|
|
31480
|
+
get chain() {
|
|
31481
|
+
return () => this.createChain();
|
|
31482
|
+
}
|
|
31483
|
+
/**
|
|
31484
|
+
* Check if a command or a chain of commands can be executed. Without executing it.
|
|
31485
|
+
*/
|
|
31486
|
+
get can() {
|
|
31487
|
+
return () => this.createCan();
|
|
31488
|
+
}
|
|
31489
|
+
/**
|
|
31490
|
+
* Creates a chain of commands.
|
|
31491
|
+
* @param startTr Start transaction.
|
|
31492
|
+
* @param shouldDispatch Should dispatch or not.
|
|
31493
|
+
*/
|
|
31494
|
+
createChain(startTr, shouldDispatch = true) {
|
|
31495
|
+
const { editor, state: state2, rawCommands } = this;
|
|
31496
|
+
const { view } = editor;
|
|
31497
|
+
const callbacks2 = [];
|
|
31498
|
+
const hasStartTr = !!startTr;
|
|
31499
|
+
const tr = startTr || state2.tr;
|
|
31500
|
+
const run2 = () => {
|
|
31501
|
+
if (!hasStartTr && shouldDispatch && !tr.getMeta("preventDispatch")) {
|
|
31502
|
+
view.dispatch(tr);
|
|
31503
|
+
}
|
|
31504
|
+
return callbacks2.every((cb) => cb === true);
|
|
31505
|
+
};
|
|
31506
|
+
const entries = Object.entries(rawCommands).map(([name, command2]) => {
|
|
31507
|
+
const chainedCommand = (...args) => {
|
|
31508
|
+
const props = this.createProps(tr, shouldDispatch);
|
|
31509
|
+
const callback = command2(...args)(props);
|
|
31510
|
+
callbacks2.push(callback);
|
|
31511
|
+
return chain;
|
|
31512
|
+
};
|
|
31513
|
+
return [name, chainedCommand];
|
|
31514
|
+
});
|
|
31515
|
+
const chain = {
|
|
31516
|
+
...Object.fromEntries(entries),
|
|
31517
|
+
run: run2
|
|
31518
|
+
};
|
|
31519
|
+
return chain;
|
|
31520
|
+
}
|
|
31521
|
+
/**
|
|
31522
|
+
* Creates a can check for commands.
|
|
31523
|
+
* @param startTr Start transaction.
|
|
31524
|
+
*/
|
|
31525
|
+
createCan(startTr) {
|
|
31526
|
+
const { rawCommands, state: state2 } = this;
|
|
31527
|
+
const dispatch = false;
|
|
31528
|
+
const tr = startTr || state2.tr;
|
|
31529
|
+
const props = this.createProps(tr, dispatch);
|
|
31530
|
+
const commands2 = Object.fromEntries(
|
|
31531
|
+
Object.entries(rawCommands).map(([name, command2]) => {
|
|
31532
|
+
return [name, (...args) => command2(...args)({ ...props, dispatch: void 0 })];
|
|
31533
|
+
})
|
|
31534
|
+
);
|
|
31535
|
+
return {
|
|
31536
|
+
...commands2,
|
|
31537
|
+
chain: () => this.createChain(tr, dispatch)
|
|
31538
|
+
};
|
|
31539
|
+
}
|
|
31540
|
+
/**
|
|
31541
|
+
* Creates default props for the command method.
|
|
31542
|
+
* @param {*} tr Transaction.
|
|
31543
|
+
* @param {*} shouldDispatch Check if should dispatch.
|
|
31544
|
+
* @returns Object with props.
|
|
31545
|
+
*/
|
|
31546
|
+
createProps(tr, shouldDispatch = true) {
|
|
31547
|
+
const { editor, state: state2, rawCommands } = this;
|
|
31548
|
+
const { view } = editor;
|
|
31549
|
+
const props = {
|
|
31550
|
+
tr,
|
|
31551
|
+
editor,
|
|
31552
|
+
view,
|
|
31553
|
+
state: chainableEditorState(tr, state2),
|
|
31554
|
+
dispatch: shouldDispatch ? () => void 0 : void 0,
|
|
31555
|
+
chain: () => this.createChain(tr, shouldDispatch),
|
|
31556
|
+
can: () => this.createCan(tr),
|
|
31557
|
+
get commands() {
|
|
31558
|
+
return Object.fromEntries(
|
|
31559
|
+
Object.entries(rawCommands).map(([name, command2]) => {
|
|
31560
|
+
return [name, (...args) => command2(...args)(props)];
|
|
31561
|
+
})
|
|
31562
|
+
);
|
|
31563
|
+
}
|
|
31564
|
+
};
|
|
31565
|
+
return props;
|
|
31566
|
+
}
|
|
31567
|
+
}
|
|
31568
|
+
function getHTMLFromFragment(fragment, schema) {
|
|
31569
|
+
const documentFragment = DOMSerializer.fromSchema(schema).serializeFragment(fragment);
|
|
31570
|
+
const temporaryDocument = document.implementation.createHTMLDocument();
|
|
31571
|
+
const container = temporaryDocument.createElement("div");
|
|
31572
|
+
container.appendChild(documentFragment);
|
|
31573
|
+
return container.innerHTML;
|
|
31574
|
+
}
|
|
31575
|
+
const getTextContentFromNodes = ($from, maxMatch = 500) => {
|
|
31576
|
+
let textBefore = "";
|
|
31577
|
+
const sliceEndPos = $from.parentOffset;
|
|
31578
|
+
$from.parent.nodesBetween(
|
|
31579
|
+
Math.max(0, sliceEndPos - maxMatch),
|
|
31580
|
+
sliceEndPos,
|
|
31581
|
+
(node2, pos, parent, index2) => {
|
|
31582
|
+
const chunk = node2.type.spec.toText?.({
|
|
31583
|
+
node: node2,
|
|
31584
|
+
pos,
|
|
31585
|
+
parent,
|
|
31586
|
+
index: index2
|
|
31587
|
+
}) || node2.textContent || "%leaf%";
|
|
31588
|
+
textBefore += node2.isAtom && !node2.isText ? chunk : chunk.slice(0, Math.max(0, sliceEndPos - pos));
|
|
31589
|
+
}
|
|
31590
|
+
);
|
|
31591
|
+
return textBefore;
|
|
31592
|
+
};
|
|
31593
|
+
class InputRule {
|
|
31594
|
+
constructor(config) {
|
|
31595
|
+
__publicField$1(this, "match");
|
|
31596
|
+
__publicField$1(this, "handler");
|
|
31597
|
+
this.match = config.match;
|
|
31598
|
+
this.handler = config.handler;
|
|
31599
|
+
}
|
|
31600
|
+
}
|
|
31601
|
+
const inputRuleMatcherHandler = (text, match) => {
|
|
31602
|
+
if (isRegExp(match)) {
|
|
31603
|
+
return match.exec(text);
|
|
31604
|
+
}
|
|
31605
|
+
const inputRuleMatch = match(text);
|
|
31606
|
+
if (!inputRuleMatch) {
|
|
31607
|
+
return null;
|
|
31608
|
+
}
|
|
31609
|
+
const result = [inputRuleMatch.text];
|
|
31610
|
+
result.index = inputRuleMatch.index;
|
|
31611
|
+
result.input = text;
|
|
31612
|
+
result.data = inputRuleMatch.data;
|
|
31613
|
+
if (inputRuleMatch.replaceWith) {
|
|
31614
|
+
if (!inputRuleMatch.text.includes(inputRuleMatch.replaceWith)) {
|
|
31615
|
+
console.warn(
|
|
31616
|
+
'[super-editor warn]: "inputRuleMatch.replaceWith" must be part of "inputRuleMatch.text".'
|
|
31617
|
+
);
|
|
31618
|
+
}
|
|
31619
|
+
result.push(inputRuleMatch.replaceWith);
|
|
31620
|
+
}
|
|
31621
|
+
return result;
|
|
31622
|
+
};
|
|
31623
|
+
const run = (config) => {
|
|
31624
|
+
const {
|
|
31625
|
+
editor,
|
|
31626
|
+
from: from2,
|
|
31627
|
+
to,
|
|
31628
|
+
text,
|
|
31629
|
+
rules,
|
|
31630
|
+
plugin: plugin2
|
|
31631
|
+
} = config;
|
|
31632
|
+
const { view } = editor;
|
|
31633
|
+
if (view.composing) {
|
|
31634
|
+
return false;
|
|
31635
|
+
}
|
|
31636
|
+
const $from = view.state.doc.resolve(from2);
|
|
31637
|
+
if ($from.parent.type.spec.code || !!($from.nodeBefore || $from.nodeAfter)?.marks.find((mark) => mark.type.spec.code)) {
|
|
31638
|
+
return false;
|
|
31639
|
+
}
|
|
31640
|
+
let matched = false;
|
|
31641
|
+
const textBefore = getTextContentFromNodes($from) + text;
|
|
31642
|
+
rules.forEach((rule) => {
|
|
31643
|
+
if (matched) {
|
|
31644
|
+
return;
|
|
31645
|
+
}
|
|
31646
|
+
const match = inputRuleMatcherHandler(textBefore, rule.match);
|
|
31647
|
+
if (!match) {
|
|
31648
|
+
return;
|
|
31649
|
+
}
|
|
31650
|
+
const tr = view.state.tr;
|
|
31651
|
+
const state2 = chainableEditorState(tr, view.state);
|
|
31652
|
+
const range2 = {
|
|
31653
|
+
from: from2 - (match[0].length - text.length),
|
|
31654
|
+
to
|
|
31655
|
+
};
|
|
31656
|
+
const { commands: commands2, chain, can } = new CommandService({
|
|
31657
|
+
editor,
|
|
31658
|
+
state: state2
|
|
31659
|
+
});
|
|
31660
|
+
const handler = rule.handler({
|
|
31661
|
+
state: state2,
|
|
31662
|
+
range: range2,
|
|
31663
|
+
match,
|
|
31664
|
+
commands: commands2,
|
|
31665
|
+
chain,
|
|
31666
|
+
can
|
|
31667
|
+
});
|
|
31668
|
+
if (handler === null || !tr.steps.length) {
|
|
31669
|
+
return;
|
|
31670
|
+
}
|
|
31671
|
+
tr.setMeta(plugin2, {
|
|
31672
|
+
transform: tr,
|
|
31673
|
+
from: from2,
|
|
31674
|
+
to,
|
|
31675
|
+
text
|
|
31676
|
+
});
|
|
31677
|
+
view.dispatch(tr);
|
|
31678
|
+
matched = true;
|
|
31679
|
+
});
|
|
31680
|
+
return matched;
|
|
31681
|
+
};
|
|
31682
|
+
const inputRulesPlugin = ({ editor, rules }) => {
|
|
31683
|
+
const plugin2 = new Plugin({
|
|
31684
|
+
key: new PluginKey("inputRulesPlugin"),
|
|
31685
|
+
state: {
|
|
31686
|
+
init() {
|
|
31687
|
+
return null;
|
|
31688
|
+
},
|
|
31689
|
+
apply(tr, prev, state2) {
|
|
31690
|
+
const stored = tr.getMeta(plugin2);
|
|
31691
|
+
if (stored) {
|
|
31692
|
+
return stored;
|
|
31693
|
+
}
|
|
31694
|
+
const simulatedInputMeta = tr.getMeta("applyInputRules");
|
|
31695
|
+
const isSimulatedInput = !!simulatedInputMeta;
|
|
31696
|
+
if (isSimulatedInput) {
|
|
31697
|
+
setTimeout(() => {
|
|
31698
|
+
let { text } = simulatedInputMeta;
|
|
31699
|
+
if (typeof text !== "string") {
|
|
31700
|
+
text = getHTMLFromFragment(Fragment.from(text), state2.schema);
|
|
31701
|
+
}
|
|
31702
|
+
const { from: from2 } = simulatedInputMeta;
|
|
31703
|
+
const to = from2 + text.length;
|
|
31704
|
+
run({
|
|
31705
|
+
editor,
|
|
31706
|
+
from: from2,
|
|
31707
|
+
to,
|
|
31708
|
+
text,
|
|
31709
|
+
rules,
|
|
31710
|
+
plugin: plugin2
|
|
31711
|
+
});
|
|
31712
|
+
});
|
|
31713
|
+
}
|
|
31714
|
+
return tr.selectionSet || tr.docChanged ? null : prev;
|
|
31715
|
+
}
|
|
31716
|
+
},
|
|
31717
|
+
props: {
|
|
31718
|
+
handleTextInput(view, from2, to, text) {
|
|
31719
|
+
return run({
|
|
31720
|
+
editor,
|
|
31721
|
+
from: from2,
|
|
31722
|
+
to,
|
|
31723
|
+
text,
|
|
31724
|
+
rules,
|
|
31725
|
+
plugin: plugin2
|
|
31726
|
+
});
|
|
31727
|
+
},
|
|
31728
|
+
// add support for input rules to trigger on enter
|
|
31729
|
+
// this is useful for example for code blocks
|
|
31730
|
+
handleKeyDown(view, event) {
|
|
31731
|
+
if (event.key !== "Enter") {
|
|
31732
|
+
return false;
|
|
31733
|
+
}
|
|
31734
|
+
const { $cursor } = view.state.selection;
|
|
31735
|
+
if ($cursor) {
|
|
31736
|
+
return run({
|
|
31737
|
+
editor,
|
|
31738
|
+
from: $cursor.pos,
|
|
31739
|
+
to: $cursor.pos,
|
|
31740
|
+
text: "\n",
|
|
31741
|
+
rules,
|
|
31742
|
+
plugin: plugin2
|
|
31743
|
+
});
|
|
31744
|
+
}
|
|
31745
|
+
return false;
|
|
31746
|
+
}
|
|
31747
|
+
},
|
|
31748
|
+
isInputRules: true
|
|
31749
|
+
});
|
|
31750
|
+
return plugin2;
|
|
31751
|
+
};
|
|
31401
31752
|
const _ExtensionService = class _ExtensionService2 {
|
|
31402
31753
|
constructor(extensions, userExtensions, editor) {
|
|
31403
31754
|
__privateAdd$1(this, _ExtensionService_instances);
|
|
@@ -31482,6 +31833,7 @@ const _ExtensionService = class _ExtensionService2 {
|
|
|
31482
31833
|
get plugins() {
|
|
31483
31834
|
const editor = this.editor;
|
|
31484
31835
|
const extensions = _ExtensionService2.sortByPriority([...this.extensions].reverse());
|
|
31836
|
+
const inputRules = [];
|
|
31485
31837
|
const allPlugins = extensions.map((extension) => {
|
|
31486
31838
|
const context = {
|
|
31487
31839
|
name: extension.name,
|
|
@@ -31500,6 +31852,10 @@ const _ExtensionService = class _ExtensionService2 {
|
|
|
31500
31852
|
bindingsObject = { ...Object.fromEntries(entries) };
|
|
31501
31853
|
}
|
|
31502
31854
|
plugins.push(keymap(bindingsObject));
|
|
31855
|
+
const addInputRules = getExtensionConfigField(extension, "addInputRules", context);
|
|
31856
|
+
if (isExtensionRulesEnabled(extension, editor.options.enableInputRules) && addInputRules) {
|
|
31857
|
+
inputRules.push(...addInputRules());
|
|
31858
|
+
}
|
|
31503
31859
|
const addPmPlugins = getExtensionConfigField(extension, "addPmPlugins", context);
|
|
31504
31860
|
if (addPmPlugins) {
|
|
31505
31861
|
const pmPlugins = addPmPlugins();
|
|
@@ -31507,7 +31863,13 @@ const _ExtensionService = class _ExtensionService2 {
|
|
|
31507
31863
|
}
|
|
31508
31864
|
return plugins;
|
|
31509
31865
|
}).flat();
|
|
31510
|
-
return [
|
|
31866
|
+
return [
|
|
31867
|
+
inputRulesPlugin({
|
|
31868
|
+
editor,
|
|
31869
|
+
rules: inputRules
|
|
31870
|
+
}),
|
|
31871
|
+
...allPlugins
|
|
31872
|
+
];
|
|
31511
31873
|
}
|
|
31512
31874
|
/**
|
|
31513
31875
|
* Get all node views from the extensions.
|
|
@@ -31589,164 +31951,6 @@ attachEditorEvents_fn = function(extension) {
|
|
|
31589
31951
|
if (onDestroy2) this.editor.on("destroy", onDestroy2);
|
|
31590
31952
|
};
|
|
31591
31953
|
let ExtensionService = _ExtensionService;
|
|
31592
|
-
function chainableEditorState(transaction, state2) {
|
|
31593
|
-
let { selection, doc: doc2, storedMarks } = transaction;
|
|
31594
|
-
return {
|
|
31595
|
-
...state2,
|
|
31596
|
-
apply: state2.apply.bind(state2),
|
|
31597
|
-
applyTransaction: state2.applyTransaction.bind(state2),
|
|
31598
|
-
plugins: state2.plugins,
|
|
31599
|
-
schema: state2.schema,
|
|
31600
|
-
reconfigure: state2.reconfigure.bind(state2),
|
|
31601
|
-
toJSON: state2.toJSON.bind(state2),
|
|
31602
|
-
get storedMarks() {
|
|
31603
|
-
return storedMarks;
|
|
31604
|
-
},
|
|
31605
|
-
get selection() {
|
|
31606
|
-
return selection;
|
|
31607
|
-
},
|
|
31608
|
-
get doc() {
|
|
31609
|
-
return doc2;
|
|
31610
|
-
},
|
|
31611
|
-
get tr() {
|
|
31612
|
-
selection = transaction.selection;
|
|
31613
|
-
doc2 = transaction.doc;
|
|
31614
|
-
storedMarks = transaction.storedMarks;
|
|
31615
|
-
return transaction;
|
|
31616
|
-
}
|
|
31617
|
-
};
|
|
31618
|
-
}
|
|
31619
|
-
class CommandService {
|
|
31620
|
-
constructor(props) {
|
|
31621
|
-
__publicField$1(this, "editor");
|
|
31622
|
-
__publicField$1(this, "rawCommands");
|
|
31623
|
-
this.editor = props.editor;
|
|
31624
|
-
this.rawCommands = this.editor.extensionService.commands;
|
|
31625
|
-
}
|
|
31626
|
-
/**
|
|
31627
|
-
* Static method for creating a service.
|
|
31628
|
-
* @param args Arguments for the constructor.
|
|
31629
|
-
*/
|
|
31630
|
-
static create(...args) {
|
|
31631
|
-
return new CommandService(...args);
|
|
31632
|
-
}
|
|
31633
|
-
/**
|
|
31634
|
-
* Get editor state.
|
|
31635
|
-
*/
|
|
31636
|
-
get state() {
|
|
31637
|
-
return this.editor.state;
|
|
31638
|
-
}
|
|
31639
|
-
/**
|
|
31640
|
-
* Get all commands with wrapped command method.
|
|
31641
|
-
*/
|
|
31642
|
-
get commands() {
|
|
31643
|
-
const { editor, state: state2 } = this;
|
|
31644
|
-
const { view } = editor;
|
|
31645
|
-
const { tr } = state2;
|
|
31646
|
-
const props = this.createProps(tr);
|
|
31647
|
-
const entries = Object.entries(this.rawCommands).map(([name, command2]) => {
|
|
31648
|
-
const method = (...args) => {
|
|
31649
|
-
const fn2 = command2(...args)(props);
|
|
31650
|
-
if (!tr.getMeta("preventDispatch")) {
|
|
31651
|
-
view.dispatch(tr);
|
|
31652
|
-
}
|
|
31653
|
-
return fn2;
|
|
31654
|
-
};
|
|
31655
|
-
return [name, method];
|
|
31656
|
-
});
|
|
31657
|
-
return Object.fromEntries(entries);
|
|
31658
|
-
}
|
|
31659
|
-
/**
|
|
31660
|
-
* Create a chain of commands to call multiple commands at once.
|
|
31661
|
-
*/
|
|
31662
|
-
get chain() {
|
|
31663
|
-
return () => this.createChain();
|
|
31664
|
-
}
|
|
31665
|
-
/**
|
|
31666
|
-
* Check if a command or a chain of commands can be executed. Without executing it.
|
|
31667
|
-
*/
|
|
31668
|
-
get can() {
|
|
31669
|
-
return () => this.createCan();
|
|
31670
|
-
}
|
|
31671
|
-
/**
|
|
31672
|
-
* Creates a chain of commands.
|
|
31673
|
-
* @param startTr Start transaction.
|
|
31674
|
-
* @param shouldDispatch Should dispatch or not.
|
|
31675
|
-
*/
|
|
31676
|
-
createChain(startTr, shouldDispatch = true) {
|
|
31677
|
-
const { editor, state: state2, rawCommands } = this;
|
|
31678
|
-
const { view } = editor;
|
|
31679
|
-
const callbacks2 = [];
|
|
31680
|
-
const hasStartTr = !!startTr;
|
|
31681
|
-
const tr = startTr || state2.tr;
|
|
31682
|
-
const run = () => {
|
|
31683
|
-
if (!hasStartTr && shouldDispatch && !tr.getMeta("preventDispatch")) {
|
|
31684
|
-
view.dispatch(tr);
|
|
31685
|
-
}
|
|
31686
|
-
return callbacks2.every((cb) => cb === true);
|
|
31687
|
-
};
|
|
31688
|
-
const entries = Object.entries(rawCommands).map(([name, command2]) => {
|
|
31689
|
-
const chainedCommand = (...args) => {
|
|
31690
|
-
const props = this.createProps(tr, shouldDispatch);
|
|
31691
|
-
const callback = command2(...args)(props);
|
|
31692
|
-
callbacks2.push(callback);
|
|
31693
|
-
return chain;
|
|
31694
|
-
};
|
|
31695
|
-
return [name, chainedCommand];
|
|
31696
|
-
});
|
|
31697
|
-
const chain = {
|
|
31698
|
-
...Object.fromEntries(entries),
|
|
31699
|
-
run
|
|
31700
|
-
};
|
|
31701
|
-
return chain;
|
|
31702
|
-
}
|
|
31703
|
-
/**
|
|
31704
|
-
* Creates a can check for commands.
|
|
31705
|
-
* @param startTr Start transaction.
|
|
31706
|
-
*/
|
|
31707
|
-
createCan(startTr) {
|
|
31708
|
-
const { rawCommands, state: state2 } = this;
|
|
31709
|
-
const dispatch = false;
|
|
31710
|
-
const tr = startTr || state2.tr;
|
|
31711
|
-
const props = this.createProps(tr, dispatch);
|
|
31712
|
-
const commands2 = Object.fromEntries(
|
|
31713
|
-
Object.entries(rawCommands).map(([name, command2]) => {
|
|
31714
|
-
return [name, (...args) => command2(...args)({ ...props, dispatch: void 0 })];
|
|
31715
|
-
})
|
|
31716
|
-
);
|
|
31717
|
-
return {
|
|
31718
|
-
...commands2,
|
|
31719
|
-
chain: () => this.createChain(tr, dispatch)
|
|
31720
|
-
};
|
|
31721
|
-
}
|
|
31722
|
-
/**
|
|
31723
|
-
* Creates default props for the command method.
|
|
31724
|
-
* @param {*} tr Transaction.
|
|
31725
|
-
* @param {*} shouldDispatch Check if should dispatch.
|
|
31726
|
-
* @returns Object with props.
|
|
31727
|
-
*/
|
|
31728
|
-
createProps(tr, shouldDispatch = true) {
|
|
31729
|
-
const { editor, state: state2, rawCommands } = this;
|
|
31730
|
-
const { view } = editor;
|
|
31731
|
-
const props = {
|
|
31732
|
-
tr,
|
|
31733
|
-
editor,
|
|
31734
|
-
view,
|
|
31735
|
-
state: chainableEditorState(tr, state2),
|
|
31736
|
-
dispatch: shouldDispatch ? () => void 0 : void 0,
|
|
31737
|
-
chain: () => this.createChain(tr, shouldDispatch),
|
|
31738
|
-
can: () => this.createCan(tr),
|
|
31739
|
-
get commands() {
|
|
31740
|
-
return Object.fromEntries(
|
|
31741
|
-
Object.entries(rawCommands).map(([name, command2]) => {
|
|
31742
|
-
return [name, (...args) => command2(...args)(props)];
|
|
31743
|
-
})
|
|
31744
|
-
);
|
|
31745
|
-
}
|
|
31746
|
-
};
|
|
31747
|
-
return props;
|
|
31748
|
-
}
|
|
31749
|
-
}
|
|
31750
31954
|
const first = (commands2) => (props) => {
|
|
31751
31955
|
const items = typeof commands2 === "function" ? commands2(props) : commands2;
|
|
31752
31956
|
for (let i = 0; i < items.length; i += 1) {
|
|
@@ -32783,6 +32987,30 @@ const insertContentAt = (position, value, options2) => ({ tr, dispatch, editor }
|
|
|
32783
32987
|
}
|
|
32784
32988
|
return true;
|
|
32785
32989
|
};
|
|
32990
|
+
const undoInputRule = () => ({ state: state2, dispatch }) => {
|
|
32991
|
+
const plugins = state2.plugins;
|
|
32992
|
+
for (let i = 0; i < plugins.length; i += 1) {
|
|
32993
|
+
const plugin2 = plugins[i];
|
|
32994
|
+
let undoable;
|
|
32995
|
+
if (plugin2.spec.isInputRules && (undoable = plugin2.getState(state2))) {
|
|
32996
|
+
if (dispatch) {
|
|
32997
|
+
const tr = state2.tr;
|
|
32998
|
+
const toUndo = undoable.transform;
|
|
32999
|
+
for (let j = toUndo.steps.length - 1; j >= 0; j -= 1) {
|
|
33000
|
+
tr.step(toUndo.steps[j].invert(toUndo.docs[j]));
|
|
33001
|
+
}
|
|
33002
|
+
if (undoable.text) {
|
|
33003
|
+
const marks = tr.doc.resolve(undoable.from).marks();
|
|
33004
|
+
tr.replaceWith(undoable.from, undoable.to, state2.schema.text(undoable.text, marks));
|
|
33005
|
+
} else {
|
|
33006
|
+
tr.delete(undoable.from, undoable.to);
|
|
33007
|
+
}
|
|
33008
|
+
}
|
|
33009
|
+
return true;
|
|
33010
|
+
}
|
|
33011
|
+
}
|
|
33012
|
+
return false;
|
|
33013
|
+
};
|
|
32786
33014
|
function wrapInList$1(listType, attrs = null) {
|
|
32787
33015
|
return function(state2, dispatch) {
|
|
32788
33016
|
let { $from, $to } = state2.selection;
|
|
@@ -33112,6 +33340,7 @@ const commands = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProp
|
|
|
33112
33340
|
toggleList,
|
|
33113
33341
|
toggleMark,
|
|
33114
33342
|
toggleNode,
|
|
33343
|
+
undoInputRule,
|
|
33115
33344
|
unsetAllMarks,
|
|
33116
33345
|
unsetMark,
|
|
33117
33346
|
updateAttributes,
|
|
@@ -33141,6 +33370,7 @@ const Keymap = Extension.create({
|
|
|
33141
33370
|
() => commands2.splitBlock()
|
|
33142
33371
|
]);
|
|
33143
33372
|
const handleBackspace = () => this.editor.commands.first(({ commands: commands2, tr }) => [
|
|
33373
|
+
() => commands2.undoInputRule(),
|
|
33144
33374
|
() => {
|
|
33145
33375
|
tr.setMeta("inputType", "deleteContentBackward");
|
|
33146
33376
|
return false;
|
|
@@ -34803,6 +35033,7 @@ const _Editor = class _Editor2 extends EventEmitter$1 {
|
|
|
34803
35033
|
editorProps: {},
|
|
34804
35034
|
parseOptions: {},
|
|
34805
35035
|
coreExtensionOptions: {},
|
|
35036
|
+
enableInputRules: true,
|
|
34806
35037
|
isCommentsEnabled: false,
|
|
34807
35038
|
isNewFile: false,
|
|
34808
35039
|
scale: 1,
|
|
@@ -35241,7 +35472,7 @@ const _Editor = class _Editor2 extends EventEmitter$1 {
|
|
|
35241
35472
|
* @returns {Y.Doc | undefined} Updated Y.Doc if any, otherwise undefined
|
|
35242
35473
|
*/
|
|
35243
35474
|
processCollaborationMigrations() {
|
|
35244
|
-
console.debug("[checkVersionMigrations] Current editor version", "0.8.
|
|
35475
|
+
console.debug("[checkVersionMigrations] Current editor version", "0.8.11");
|
|
35245
35476
|
if (!this.options.ydoc) return;
|
|
35246
35477
|
const metaMap = this.options.ydoc.getMap("meta");
|
|
35247
35478
|
let docVersion = metaMap.get("version");
|
|
@@ -36586,6 +36817,45 @@ const RunItem = Node2.create({
|
|
|
36586
36817
|
};
|
|
36587
36818
|
}
|
|
36588
36819
|
});
|
|
36820
|
+
function wrappingInputRule(config) {
|
|
36821
|
+
return new InputRule({
|
|
36822
|
+
match: config.match,
|
|
36823
|
+
handler: ({
|
|
36824
|
+
state: state2,
|
|
36825
|
+
range: range2,
|
|
36826
|
+
match,
|
|
36827
|
+
chain
|
|
36828
|
+
}) => {
|
|
36829
|
+
const attributes = callOrGet(config.getAttributes, null, match) || {};
|
|
36830
|
+
const tr = state2.tr.delete(range2.from, range2.to);
|
|
36831
|
+
const $start = tr.doc.resolve(range2.from);
|
|
36832
|
+
const blockRange = $start.blockRange();
|
|
36833
|
+
const wrapping = blockRange && findWrapping(blockRange, config.type, attributes);
|
|
36834
|
+
if (!wrapping) {
|
|
36835
|
+
return null;
|
|
36836
|
+
}
|
|
36837
|
+
tr.wrap(blockRange, wrapping);
|
|
36838
|
+
if (config.keepMarks && config.editor) {
|
|
36839
|
+
const { selection, storedMarks } = state2;
|
|
36840
|
+
const { splittableMarks } = config.editor.extensionService;
|
|
36841
|
+
const marks = storedMarks || selection.$to.parentOffset && selection.$from.marks();
|
|
36842
|
+
if (marks) {
|
|
36843
|
+
const filteredMarks = marks.filter((mark) => splittableMarks.includes(mark.type.name));
|
|
36844
|
+
tr.ensureMarks(filteredMarks);
|
|
36845
|
+
}
|
|
36846
|
+
}
|
|
36847
|
+
if (config.keepAttributes) {
|
|
36848
|
+
const nodeType = config.type.name === "bulletList" || config.type.name === "orderedList" ? "listItem" : config.type.name;
|
|
36849
|
+
chain().updateAttributes(nodeType, attributes).run();
|
|
36850
|
+
}
|
|
36851
|
+
const before = tr.doc.resolve(range2.from - 1).nodeBefore;
|
|
36852
|
+
if (before && before.type === config.type && canJoin(tr.doc, range2.from - 1) && (!config.joinPredicate || config.joinPredicate(match, before))) {
|
|
36853
|
+
tr.join(range2.from - 1);
|
|
36854
|
+
}
|
|
36855
|
+
}
|
|
36856
|
+
});
|
|
36857
|
+
}
|
|
36858
|
+
const inputRegex$1 = /^\s*([-+*])\s$/;
|
|
36589
36859
|
const BulletList = Node2.create({
|
|
36590
36860
|
name: "bulletList",
|
|
36591
36861
|
group: "block list",
|
|
@@ -36596,7 +36866,8 @@ const BulletList = Node2.create({
|
|
|
36596
36866
|
return {
|
|
36597
36867
|
itemTypeName: "listItem",
|
|
36598
36868
|
htmlAttributes: {},
|
|
36599
|
-
keepMarks: true
|
|
36869
|
+
keepMarks: true,
|
|
36870
|
+
keepAttributes: false
|
|
36600
36871
|
};
|
|
36601
36872
|
},
|
|
36602
36873
|
parseDOM() {
|
|
@@ -36634,8 +36905,29 @@ const BulletList = Node2.create({
|
|
|
36634
36905
|
return this.editor.commands.toggleBulletList();
|
|
36635
36906
|
}
|
|
36636
36907
|
};
|
|
36637
|
-
}
|
|
36908
|
+
},
|
|
36638
36909
|
// Input rules.
|
|
36910
|
+
addInputRules() {
|
|
36911
|
+
let inputRule = wrappingInputRule({
|
|
36912
|
+
match: inputRegex$1,
|
|
36913
|
+
type: this.type
|
|
36914
|
+
});
|
|
36915
|
+
if (this.options.keepMarks || this.options.keepAttributes) {
|
|
36916
|
+
inputRule = wrappingInputRule({
|
|
36917
|
+
match: inputRegex$1,
|
|
36918
|
+
type: this.type,
|
|
36919
|
+
keepMarks: this.options.keepMarks,
|
|
36920
|
+
keepAttributes: this.options.keepAttributes,
|
|
36921
|
+
getAttributes: () => {
|
|
36922
|
+
return this.editor.getAttributes("textStyle");
|
|
36923
|
+
},
|
|
36924
|
+
editor: this.editor
|
|
36925
|
+
});
|
|
36926
|
+
}
|
|
36927
|
+
return [
|
|
36928
|
+
inputRule
|
|
36929
|
+
];
|
|
36930
|
+
}
|
|
36639
36931
|
});
|
|
36640
36932
|
function orderedListSync(options2 = {}) {
|
|
36641
36933
|
return new Plugin({
|
|
@@ -36846,6 +37138,7 @@ function buildFirstListItemAttrs({ state: state2, listItems }) {
|
|
|
36846
37138
|
listNumberingType
|
|
36847
37139
|
};
|
|
36848
37140
|
}
|
|
37141
|
+
const inputRegex = /^(\d+)\.\s$/;
|
|
36849
37142
|
const OrderedList = Node2.create({
|
|
36850
37143
|
name: "orderedList",
|
|
36851
37144
|
group: "block list",
|
|
@@ -36857,6 +37150,7 @@ const OrderedList = Node2.create({
|
|
|
36857
37150
|
itemTypeName: "listItem",
|
|
36858
37151
|
htmlAttributes: {},
|
|
36859
37152
|
keepMarks: true,
|
|
37153
|
+
keepAttributes: false,
|
|
36860
37154
|
listStyleTypes: ["decimal", "lowerAlpha", "lowerRoman"]
|
|
36861
37155
|
};
|
|
36862
37156
|
},
|
|
@@ -37014,6 +37308,28 @@ const OrderedList = Node2.create({
|
|
|
37014
37308
|
},
|
|
37015
37309
|
addPmPlugins() {
|
|
37016
37310
|
return [orderedListMarker(), orderedListSync()];
|
|
37311
|
+
},
|
|
37312
|
+
addInputRules() {
|
|
37313
|
+
let inputRule = wrappingInputRule({
|
|
37314
|
+
match: inputRegex,
|
|
37315
|
+
type: this.type,
|
|
37316
|
+
getAttributes: (match) => ({ start: +match[1] }),
|
|
37317
|
+
joinPredicate: (match, node2) => node2.childCount + node2.attrs.start === +match[1]
|
|
37318
|
+
});
|
|
37319
|
+
if (this.options.keepMarks || this.options.keepAttributes) {
|
|
37320
|
+
inputRule = wrappingInputRule({
|
|
37321
|
+
match: inputRegex,
|
|
37322
|
+
type: this.type,
|
|
37323
|
+
keepMarks: this.options.keepMarks,
|
|
37324
|
+
keepAttributes: this.options.keepAttributes,
|
|
37325
|
+
getAttributes: (match) => ({ start: +match[1], ...this.editor.getAttributes("textStyle") }),
|
|
37326
|
+
joinPredicate: (match, node2) => node2.childCount + node2.attrs.start === +match[1],
|
|
37327
|
+
editor: this.editor
|
|
37328
|
+
});
|
|
37329
|
+
}
|
|
37330
|
+
return [
|
|
37331
|
+
inputRule
|
|
37332
|
+
];
|
|
37017
37333
|
}
|
|
37018
37334
|
});
|
|
37019
37335
|
function randomId() {
|
|
@@ -58787,4 +59103,4 @@ export {
|
|
|
58787
59103
|
helpers as m,
|
|
58788
59104
|
index as n
|
|
58789
59105
|
};
|
|
58790
|
-
//# sourceMappingURL=super-editor.es-
|
|
59106
|
+
//# sourceMappingURL=super-editor.es-DIeHC3Si.js.map
|