@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.
Files changed (46) hide show
  1. package/dist/chunks/{super-editor.es-CnpejCPC.js → super-editor.es-DIeHC3Si.js} +484 -168
  2. package/dist/chunks/super-editor.es-DIeHC3Si.js.map +1 -0
  3. package/dist/super-editor/chunks/{converter-B5SRaBp5.js → converter-CVSaF15S.js} +28 -27
  4. package/dist/super-editor/chunks/converter-CVSaF15S.js.map +1 -0
  5. package/dist/super-editor/chunks/{docx-zipper-fdMcchlI.js → docx-zipper-BHwY_rz6.js} +2 -2
  6. package/dist/super-editor/chunks/{docx-zipper-fdMcchlI.js.map → docx-zipper-BHwY_rz6.js.map} +1 -1
  7. package/dist/super-editor/chunks/{editor-nlt5JeOJ.js → editor-H6Apbtdi.js} +481 -165
  8. package/dist/super-editor/chunks/editor-H6Apbtdi.js.map +1 -0
  9. package/dist/super-editor/chunks/{toolbar-COfngBDY.js → toolbar-D9ELD8Tt.js} +3 -3
  10. package/dist/super-editor/chunks/{toolbar-COfngBDY.js.map → toolbar-D9ELD8Tt.js.map} +1 -1
  11. package/dist/super-editor/converter.es.js +2 -2
  12. package/dist/super-editor/core/Editor.d.ts +1 -0
  13. package/dist/super-editor/core/Editor.d.ts.map +1 -1
  14. package/dist/super-editor/core/ExtensionService.d.ts.map +1 -1
  15. package/dist/super-editor/core/InputRule.d.ts +11 -0
  16. package/dist/super-editor/core/InputRule.d.ts.map +1 -0
  17. package/dist/super-editor/core/commands/index.d.ts +1 -0
  18. package/dist/super-editor/core/commands/undoInputRule.d.ts +5 -0
  19. package/dist/super-editor/core/commands/undoInputRule.d.ts.map +1 -0
  20. package/dist/super-editor/core/extensions/keymap.d.ts.map +1 -1
  21. package/dist/super-editor/core/helpers/getHTMLFromFragment.d.ts +2 -0
  22. package/dist/super-editor/core/helpers/getHTMLFromFragment.d.ts.map +1 -0
  23. package/dist/super-editor/core/helpers/getTextContentFromNodes.d.ts +2 -0
  24. package/dist/super-editor/core/helpers/getTextContentFromNodes.d.ts.map +1 -0
  25. package/dist/super-editor/core/helpers/isExtentionRulesEnabled.d.ts +2 -0
  26. package/dist/super-editor/core/helpers/isExtentionRulesEnabled.d.ts.map +1 -0
  27. package/dist/super-editor/core/inputRules/wrappingInputRule.d.ts +9 -0
  28. package/dist/super-editor/core/inputRules/wrappingInputRule.d.ts.map +1 -0
  29. package/dist/super-editor/core/utilities/isRegExp.d.ts +2 -0
  30. package/dist/super-editor/core/utilities/isRegExp.d.ts.map +1 -0
  31. package/dist/super-editor/core/utilities/objectIncludes.d.ts.map +1 -1
  32. package/dist/super-editor/docx-zipper.es.js +2 -2
  33. package/dist/super-editor/editor.es.js +3 -3
  34. package/dist/super-editor/extensions/bullet-list/bullet-list.d.ts.map +1 -1
  35. package/dist/super-editor/extensions/ordered-list/ordered-list.d.ts.map +1 -1
  36. package/dist/super-editor/file-zipper.es.js +1 -1
  37. package/dist/super-editor/super-editor.es.js +7 -7
  38. package/dist/super-editor/toolbar.es.js +2 -2
  39. package/dist/super-editor.es.js +1 -1
  40. package/dist/superdoc.es.js +3 -3
  41. package/dist/superdoc.umd.js +495 -179
  42. package/dist/superdoc.umd.js.map +1 -1
  43. package/package.json +1 -1
  44. package/dist/chunks/super-editor.es-CnpejCPC.js.map +0 -1
  45. package/dist/super-editor/chunks/converter-B5SRaBp5.js.map +0 -1
  46. package/dist/super-editor/chunks/editor-nlt5JeOJ.js.map +0 -1
@@ -727,7 +727,7 @@
727
727
  globalVersion++;
728
728
  return;
729
729
  }
730
- const run = (dep) => {
730
+ const run2 = (dep) => {
731
731
  if (dep) {
732
732
  {
733
733
  dep.trigger();
@@ -736,7 +736,7 @@
736
736
  };
737
737
  startBatch();
738
738
  if (type2 === "clear") {
739
- depsMap.forEach(run);
739
+ depsMap.forEach(run2);
740
740
  } else {
741
741
  const targetIsArray = isArray$4(target);
742
742
  const isArrayIndex = targetIsArray && isIntegerKey(key);
@@ -744,38 +744,38 @@
744
744
  const newLength = Number(newValue);
745
745
  depsMap.forEach((dep, key2) => {
746
746
  if (key2 === "length" || key2 === ARRAY_ITERATE_KEY || !isSymbol$2(key2) && key2 >= newLength) {
747
- run(dep);
747
+ run2(dep);
748
748
  }
749
749
  });
750
750
  } else {
751
751
  if (key !== void 0 || depsMap.has(void 0)) {
752
- run(depsMap.get(key));
752
+ run2(depsMap.get(key));
753
753
  }
754
754
  if (isArrayIndex) {
755
- run(depsMap.get(ARRAY_ITERATE_KEY));
755
+ run2(depsMap.get(ARRAY_ITERATE_KEY));
756
756
  }
757
757
  switch (type2) {
758
758
  case "add":
759
759
  if (!targetIsArray) {
760
- run(depsMap.get(ITERATE_KEY));
760
+ run2(depsMap.get(ITERATE_KEY));
761
761
  if (isMap(target)) {
762
- run(depsMap.get(MAP_KEY_ITERATE_KEY));
762
+ run2(depsMap.get(MAP_KEY_ITERATE_KEY));
763
763
  }
764
764
  } else if (isArrayIndex) {
765
- run(depsMap.get("length"));
765
+ run2(depsMap.get("length"));
766
766
  }
767
767
  break;
768
768
  case "delete":
769
769
  if (!targetIsArray) {
770
- run(depsMap.get(ITERATE_KEY));
770
+ run2(depsMap.get(ITERATE_KEY));
771
771
  if (isMap(target)) {
772
- run(depsMap.get(MAP_KEY_ITERATE_KEY));
772
+ run2(depsMap.get(MAP_KEY_ITERATE_KEY));
773
773
  }
774
774
  }
775
775
  break;
776
776
  case "set":
777
777
  if (isMap(target)) {
778
- run(depsMap.get(ITERATE_KEY));
778
+ run2(depsMap.get(ITERATE_KEY));
779
779
  }
780
780
  break;
781
781
  }
@@ -26498,7 +26498,7 @@
26498
26498
  };
26499
26499
  function hasTextNode(elements) {
26500
26500
  const runs = elements.filter((el) => el.name === "w:r");
26501
- const runsHaveText = runs.some((run) => run.elements.some((el) => el.name === "w:t"));
26501
+ const runsHaveText = runs.some((run2) => run2.elements.some((el) => el.name === "w:t"));
26502
26502
  return runsHaveText;
26503
26503
  }
26504
26504
  const handleTrackChangeNode = (params2) => {
@@ -27397,8 +27397,8 @@
27397
27397
  };
27398
27398
  };
27399
27399
  const parseAnnotationMarks = (content = {}) => {
27400
- const run = content.elements?.find((el) => el.name === "w:r");
27401
- const rPr = run?.elements?.find((el) => el.name === "w:rPr");
27400
+ const run2 = content.elements?.find((el) => el.name === "w:r");
27401
+ const rPr = run2?.elements?.find((el) => el.name === "w:rPr");
27402
27402
  if (!rPr) return {};
27403
27403
  const unknownMarks = [];
27404
27404
  const marks = parseMarks(rPr, unknownMarks) || [];
@@ -28001,7 +28001,7 @@
28001
28001
  return;
28002
28002
  }
28003
28003
  }
28004
- static updateDocumentVersion(docx = this.convertedXml, version2 = "0.8.10") {
28004
+ static updateDocumentVersion(docx = this.convertedXml, version2 = "0.8.11") {
28005
28005
  const customLocation = "docProps/custom.xml";
28006
28006
  if (!docx[customLocation]) {
28007
28007
  docx[customLocation] = generateCustomXml();
@@ -28274,7 +28274,7 @@
28274
28274
  function generateCustomXml() {
28275
28275
  return DEFAULT_CUSTOM_XML;
28276
28276
  }
28277
- function generateSuperdocVersion(pid = 2, version2 = "0.8.10") {
28277
+ function generateSuperdocVersion(pid = 2, version2 = "0.8.11") {
28278
28278
  return {
28279
28279
  type: "element",
28280
28280
  name: "property",
@@ -38735,6 +38735,357 @@
38735
38735
  function getSchemaTypeByName(name, schema) {
38736
38736
  return schema.nodes[name] || schema.marks[name] || null;
38737
38737
  }
38738
+ function isExtensionRulesEnabled(extension, enabled) {
38739
+ if (Array.isArray(enabled)) {
38740
+ return enabled.some((enabledExtension) => {
38741
+ const name = typeof enabledExtension === "string" ? enabledExtension : enabledExtension.name;
38742
+ return name === extension.name;
38743
+ });
38744
+ }
38745
+ return enabled;
38746
+ }
38747
+ function chainableEditorState(transaction, state2) {
38748
+ let { selection, doc: doc2, storedMarks } = transaction;
38749
+ return {
38750
+ ...state2,
38751
+ apply: state2.apply.bind(state2),
38752
+ applyTransaction: state2.applyTransaction.bind(state2),
38753
+ plugins: state2.plugins,
38754
+ schema: state2.schema,
38755
+ reconfigure: state2.reconfigure.bind(state2),
38756
+ toJSON: state2.toJSON.bind(state2),
38757
+ get storedMarks() {
38758
+ return storedMarks;
38759
+ },
38760
+ get selection() {
38761
+ return selection;
38762
+ },
38763
+ get doc() {
38764
+ return doc2;
38765
+ },
38766
+ get tr() {
38767
+ selection = transaction.selection;
38768
+ doc2 = transaction.doc;
38769
+ storedMarks = transaction.storedMarks;
38770
+ return transaction;
38771
+ }
38772
+ };
38773
+ }
38774
+ class CommandService {
38775
+ constructor(props) {
38776
+ __publicField$1(this, "editor");
38777
+ __publicField$1(this, "rawCommands");
38778
+ this.editor = props.editor;
38779
+ this.rawCommands = this.editor.extensionService.commands;
38780
+ }
38781
+ /**
38782
+ * Static method for creating a service.
38783
+ * @param args Arguments for the constructor.
38784
+ */
38785
+ static create(...args) {
38786
+ return new CommandService(...args);
38787
+ }
38788
+ /**
38789
+ * Get editor state.
38790
+ */
38791
+ get state() {
38792
+ return this.editor.state;
38793
+ }
38794
+ /**
38795
+ * Get all commands with wrapped command method.
38796
+ */
38797
+ get commands() {
38798
+ const { editor, state: state2 } = this;
38799
+ const { view } = editor;
38800
+ const { tr } = state2;
38801
+ const props = this.createProps(tr);
38802
+ const entries = Object.entries(this.rawCommands).map(([name, command2]) => {
38803
+ const method = (...args) => {
38804
+ const fn2 = command2(...args)(props);
38805
+ if (!tr.getMeta("preventDispatch")) {
38806
+ view.dispatch(tr);
38807
+ }
38808
+ return fn2;
38809
+ };
38810
+ return [name, method];
38811
+ });
38812
+ return Object.fromEntries(entries);
38813
+ }
38814
+ /**
38815
+ * Create a chain of commands to call multiple commands at once.
38816
+ */
38817
+ get chain() {
38818
+ return () => this.createChain();
38819
+ }
38820
+ /**
38821
+ * Check if a command or a chain of commands can be executed. Without executing it.
38822
+ */
38823
+ get can() {
38824
+ return () => this.createCan();
38825
+ }
38826
+ /**
38827
+ * Creates a chain of commands.
38828
+ * @param startTr Start transaction.
38829
+ * @param shouldDispatch Should dispatch or not.
38830
+ */
38831
+ createChain(startTr, shouldDispatch = true) {
38832
+ const { editor, state: state2, rawCommands } = this;
38833
+ const { view } = editor;
38834
+ const callbacks2 = [];
38835
+ const hasStartTr = !!startTr;
38836
+ const tr = startTr || state2.tr;
38837
+ const run2 = () => {
38838
+ if (!hasStartTr && shouldDispatch && !tr.getMeta("preventDispatch")) {
38839
+ view.dispatch(tr);
38840
+ }
38841
+ return callbacks2.every((cb) => cb === true);
38842
+ };
38843
+ const entries = Object.entries(rawCommands).map(([name, command2]) => {
38844
+ const chainedCommand = (...args) => {
38845
+ const props = this.createProps(tr, shouldDispatch);
38846
+ const callback = command2(...args)(props);
38847
+ callbacks2.push(callback);
38848
+ return chain;
38849
+ };
38850
+ return [name, chainedCommand];
38851
+ });
38852
+ const chain = {
38853
+ ...Object.fromEntries(entries),
38854
+ run: run2
38855
+ };
38856
+ return chain;
38857
+ }
38858
+ /**
38859
+ * Creates a can check for commands.
38860
+ * @param startTr Start transaction.
38861
+ */
38862
+ createCan(startTr) {
38863
+ const { rawCommands, state: state2 } = this;
38864
+ const dispatch = false;
38865
+ const tr = startTr || state2.tr;
38866
+ const props = this.createProps(tr, dispatch);
38867
+ const commands2 = Object.fromEntries(
38868
+ Object.entries(rawCommands).map(([name, command2]) => {
38869
+ return [name, (...args) => command2(...args)({ ...props, dispatch: void 0 })];
38870
+ })
38871
+ );
38872
+ return {
38873
+ ...commands2,
38874
+ chain: () => this.createChain(tr, dispatch)
38875
+ };
38876
+ }
38877
+ /**
38878
+ * Creates default props for the command method.
38879
+ * @param {*} tr Transaction.
38880
+ * @param {*} shouldDispatch Check if should dispatch.
38881
+ * @returns Object with props.
38882
+ */
38883
+ createProps(tr, shouldDispatch = true) {
38884
+ const { editor, state: state2, rawCommands } = this;
38885
+ const { view } = editor;
38886
+ const props = {
38887
+ tr,
38888
+ editor,
38889
+ view,
38890
+ state: chainableEditorState(tr, state2),
38891
+ dispatch: shouldDispatch ? () => void 0 : void 0,
38892
+ chain: () => this.createChain(tr, shouldDispatch),
38893
+ can: () => this.createCan(tr),
38894
+ get commands() {
38895
+ return Object.fromEntries(
38896
+ Object.entries(rawCommands).map(([name, command2]) => {
38897
+ return [name, (...args) => command2(...args)(props)];
38898
+ })
38899
+ );
38900
+ }
38901
+ };
38902
+ return props;
38903
+ }
38904
+ }
38905
+ function getHTMLFromFragment(fragment, schema) {
38906
+ const documentFragment = DOMSerializer.fromSchema(schema).serializeFragment(fragment);
38907
+ const temporaryDocument = document.implementation.createHTMLDocument();
38908
+ const container = temporaryDocument.createElement("div");
38909
+ container.appendChild(documentFragment);
38910
+ return container.innerHTML;
38911
+ }
38912
+ const getTextContentFromNodes = ($from, maxMatch = 500) => {
38913
+ let textBefore = "";
38914
+ const sliceEndPos = $from.parentOffset;
38915
+ $from.parent.nodesBetween(
38916
+ Math.max(0, sliceEndPos - maxMatch),
38917
+ sliceEndPos,
38918
+ (node2, pos, parent, index2) => {
38919
+ const chunk = node2.type.spec.toText?.({
38920
+ node: node2,
38921
+ pos,
38922
+ parent,
38923
+ index: index2
38924
+ }) || node2.textContent || "%leaf%";
38925
+ textBefore += node2.isAtom && !node2.isText ? chunk : chunk.slice(0, Math.max(0, sliceEndPos - pos));
38926
+ }
38927
+ );
38928
+ return textBefore;
38929
+ };
38930
+ class InputRule {
38931
+ constructor(config) {
38932
+ __publicField$1(this, "match");
38933
+ __publicField$1(this, "handler");
38934
+ this.match = config.match;
38935
+ this.handler = config.handler;
38936
+ }
38937
+ }
38938
+ const inputRuleMatcherHandler = (text, match2) => {
38939
+ if (isRegExp(match2)) {
38940
+ return match2.exec(text);
38941
+ }
38942
+ const inputRuleMatch = match2(text);
38943
+ if (!inputRuleMatch) {
38944
+ return null;
38945
+ }
38946
+ const result = [inputRuleMatch.text];
38947
+ result.index = inputRuleMatch.index;
38948
+ result.input = text;
38949
+ result.data = inputRuleMatch.data;
38950
+ if (inputRuleMatch.replaceWith) {
38951
+ if (!inputRuleMatch.text.includes(inputRuleMatch.replaceWith)) {
38952
+ console.warn(
38953
+ '[super-editor warn]: "inputRuleMatch.replaceWith" must be part of "inputRuleMatch.text".'
38954
+ );
38955
+ }
38956
+ result.push(inputRuleMatch.replaceWith);
38957
+ }
38958
+ return result;
38959
+ };
38960
+ const run = (config) => {
38961
+ const {
38962
+ editor,
38963
+ from: from2,
38964
+ to,
38965
+ text,
38966
+ rules,
38967
+ plugin: plugin2
38968
+ } = config;
38969
+ const { view } = editor;
38970
+ if (view.composing) {
38971
+ return false;
38972
+ }
38973
+ const $from = view.state.doc.resolve(from2);
38974
+ if ($from.parent.type.spec.code || !!($from.nodeBefore || $from.nodeAfter)?.marks.find((mark) => mark.type.spec.code)) {
38975
+ return false;
38976
+ }
38977
+ let matched = false;
38978
+ const textBefore = getTextContentFromNodes($from) + text;
38979
+ rules.forEach((rule) => {
38980
+ if (matched) {
38981
+ return;
38982
+ }
38983
+ const match2 = inputRuleMatcherHandler(textBefore, rule.match);
38984
+ if (!match2) {
38985
+ return;
38986
+ }
38987
+ const tr = view.state.tr;
38988
+ const state2 = chainableEditorState(tr, view.state);
38989
+ const range2 = {
38990
+ from: from2 - (match2[0].length - text.length),
38991
+ to
38992
+ };
38993
+ const { commands: commands2, chain, can } = new CommandService({
38994
+ editor,
38995
+ state: state2
38996
+ });
38997
+ const handler = rule.handler({
38998
+ state: state2,
38999
+ range: range2,
39000
+ match: match2,
39001
+ commands: commands2,
39002
+ chain,
39003
+ can
39004
+ });
39005
+ if (handler === null || !tr.steps.length) {
39006
+ return;
39007
+ }
39008
+ tr.setMeta(plugin2, {
39009
+ transform: tr,
39010
+ from: from2,
39011
+ to,
39012
+ text
39013
+ });
39014
+ view.dispatch(tr);
39015
+ matched = true;
39016
+ });
39017
+ return matched;
39018
+ };
39019
+ const inputRulesPlugin = ({ editor, rules }) => {
39020
+ const plugin2 = new Plugin({
39021
+ key: new PluginKey("inputRulesPlugin"),
39022
+ state: {
39023
+ init() {
39024
+ return null;
39025
+ },
39026
+ apply(tr, prev, state2) {
39027
+ const stored = tr.getMeta(plugin2);
39028
+ if (stored) {
39029
+ return stored;
39030
+ }
39031
+ const simulatedInputMeta = tr.getMeta("applyInputRules");
39032
+ const isSimulatedInput = !!simulatedInputMeta;
39033
+ if (isSimulatedInput) {
39034
+ setTimeout(() => {
39035
+ let { text } = simulatedInputMeta;
39036
+ if (typeof text !== "string") {
39037
+ text = getHTMLFromFragment(Fragment.from(text), state2.schema);
39038
+ }
39039
+ const { from: from2 } = simulatedInputMeta;
39040
+ const to = from2 + text.length;
39041
+ run({
39042
+ editor,
39043
+ from: from2,
39044
+ to,
39045
+ text,
39046
+ rules,
39047
+ plugin: plugin2
39048
+ });
39049
+ });
39050
+ }
39051
+ return tr.selectionSet || tr.docChanged ? null : prev;
39052
+ }
39053
+ },
39054
+ props: {
39055
+ handleTextInput(view, from2, to, text) {
39056
+ return run({
39057
+ editor,
39058
+ from: from2,
39059
+ to,
39060
+ text,
39061
+ rules,
39062
+ plugin: plugin2
39063
+ });
39064
+ },
39065
+ // add support for input rules to trigger on enter
39066
+ // this is useful for example for code blocks
39067
+ handleKeyDown(view, event) {
39068
+ if (event.key !== "Enter") {
39069
+ return false;
39070
+ }
39071
+ const { $cursor } = view.state.selection;
39072
+ if ($cursor) {
39073
+ return run({
39074
+ editor,
39075
+ from: $cursor.pos,
39076
+ to: $cursor.pos,
39077
+ text: "\n",
39078
+ rules,
39079
+ plugin: plugin2
39080
+ });
39081
+ }
39082
+ return false;
39083
+ }
39084
+ },
39085
+ isInputRules: true
39086
+ });
39087
+ return plugin2;
39088
+ };
38738
39089
  const _ExtensionService = class _ExtensionService2 {
38739
39090
  constructor(extensions, userExtensions, editor) {
38740
39091
  __privateAdd$1(this, _ExtensionService_instances);
@@ -38819,6 +39170,7 @@
38819
39170
  get plugins() {
38820
39171
  const editor = this.editor;
38821
39172
  const extensions = _ExtensionService2.sortByPriority([...this.extensions].reverse());
39173
+ const inputRules = [];
38822
39174
  const allPlugins = extensions.map((extension) => {
38823
39175
  const context = {
38824
39176
  name: extension.name,
@@ -38837,6 +39189,10 @@
38837
39189
  bindingsObject = { ...Object.fromEntries(entries) };
38838
39190
  }
38839
39191
  plugins.push(keymap(bindingsObject));
39192
+ const addInputRules = getExtensionConfigField(extension, "addInputRules", context);
39193
+ if (isExtensionRulesEnabled(extension, editor.options.enableInputRules) && addInputRules) {
39194
+ inputRules.push(...addInputRules());
39195
+ }
38840
39196
  const addPmPlugins = getExtensionConfigField(extension, "addPmPlugins", context);
38841
39197
  if (addPmPlugins) {
38842
39198
  const pmPlugins = addPmPlugins();
@@ -38844,7 +39200,13 @@
38844
39200
  }
38845
39201
  return plugins;
38846
39202
  }).flat();
38847
- return [...allPlugins];
39203
+ return [
39204
+ inputRulesPlugin({
39205
+ editor,
39206
+ rules: inputRules
39207
+ }),
39208
+ ...allPlugins
39209
+ ];
38848
39210
  }
38849
39211
  /**
38850
39212
  * Get all node views from the extensions.
@@ -38926,164 +39288,6 @@
38926
39288
  if (onDestroy2) this.editor.on("destroy", onDestroy2);
38927
39289
  };
38928
39290
  let ExtensionService = _ExtensionService;
38929
- function chainableEditorState(transaction, state2) {
38930
- let { selection, doc: doc2, storedMarks } = transaction;
38931
- return {
38932
- ...state2,
38933
- apply: state2.apply.bind(state2),
38934
- applyTransaction: state2.applyTransaction.bind(state2),
38935
- plugins: state2.plugins,
38936
- schema: state2.schema,
38937
- reconfigure: state2.reconfigure.bind(state2),
38938
- toJSON: state2.toJSON.bind(state2),
38939
- get storedMarks() {
38940
- return storedMarks;
38941
- },
38942
- get selection() {
38943
- return selection;
38944
- },
38945
- get doc() {
38946
- return doc2;
38947
- },
38948
- get tr() {
38949
- selection = transaction.selection;
38950
- doc2 = transaction.doc;
38951
- storedMarks = transaction.storedMarks;
38952
- return transaction;
38953
- }
38954
- };
38955
- }
38956
- class CommandService {
38957
- constructor(props) {
38958
- __publicField$1(this, "editor");
38959
- __publicField$1(this, "rawCommands");
38960
- this.editor = props.editor;
38961
- this.rawCommands = this.editor.extensionService.commands;
38962
- }
38963
- /**
38964
- * Static method for creating a service.
38965
- * @param args Arguments for the constructor.
38966
- */
38967
- static create(...args) {
38968
- return new CommandService(...args);
38969
- }
38970
- /**
38971
- * Get editor state.
38972
- */
38973
- get state() {
38974
- return this.editor.state;
38975
- }
38976
- /**
38977
- * Get all commands with wrapped command method.
38978
- */
38979
- get commands() {
38980
- const { editor, state: state2 } = this;
38981
- const { view } = editor;
38982
- const { tr } = state2;
38983
- const props = this.createProps(tr);
38984
- const entries = Object.entries(this.rawCommands).map(([name, command2]) => {
38985
- const method = (...args) => {
38986
- const fn2 = command2(...args)(props);
38987
- if (!tr.getMeta("preventDispatch")) {
38988
- view.dispatch(tr);
38989
- }
38990
- return fn2;
38991
- };
38992
- return [name, method];
38993
- });
38994
- return Object.fromEntries(entries);
38995
- }
38996
- /**
38997
- * Create a chain of commands to call multiple commands at once.
38998
- */
38999
- get chain() {
39000
- return () => this.createChain();
39001
- }
39002
- /**
39003
- * Check if a command or a chain of commands can be executed. Without executing it.
39004
- */
39005
- get can() {
39006
- return () => this.createCan();
39007
- }
39008
- /**
39009
- * Creates a chain of commands.
39010
- * @param startTr Start transaction.
39011
- * @param shouldDispatch Should dispatch or not.
39012
- */
39013
- createChain(startTr, shouldDispatch = true) {
39014
- const { editor, state: state2, rawCommands } = this;
39015
- const { view } = editor;
39016
- const callbacks2 = [];
39017
- const hasStartTr = !!startTr;
39018
- const tr = startTr || state2.tr;
39019
- const run = () => {
39020
- if (!hasStartTr && shouldDispatch && !tr.getMeta("preventDispatch")) {
39021
- view.dispatch(tr);
39022
- }
39023
- return callbacks2.every((cb) => cb === true);
39024
- };
39025
- const entries = Object.entries(rawCommands).map(([name, command2]) => {
39026
- const chainedCommand = (...args) => {
39027
- const props = this.createProps(tr, shouldDispatch);
39028
- const callback = command2(...args)(props);
39029
- callbacks2.push(callback);
39030
- return chain;
39031
- };
39032
- return [name, chainedCommand];
39033
- });
39034
- const chain = {
39035
- ...Object.fromEntries(entries),
39036
- run
39037
- };
39038
- return chain;
39039
- }
39040
- /**
39041
- * Creates a can check for commands.
39042
- * @param startTr Start transaction.
39043
- */
39044
- createCan(startTr) {
39045
- const { rawCommands, state: state2 } = this;
39046
- const dispatch = false;
39047
- const tr = startTr || state2.tr;
39048
- const props = this.createProps(tr, dispatch);
39049
- const commands2 = Object.fromEntries(
39050
- Object.entries(rawCommands).map(([name, command2]) => {
39051
- return [name, (...args) => command2(...args)({ ...props, dispatch: void 0 })];
39052
- })
39053
- );
39054
- return {
39055
- ...commands2,
39056
- chain: () => this.createChain(tr, dispatch)
39057
- };
39058
- }
39059
- /**
39060
- * Creates default props for the command method.
39061
- * @param {*} tr Transaction.
39062
- * @param {*} shouldDispatch Check if should dispatch.
39063
- * @returns Object with props.
39064
- */
39065
- createProps(tr, shouldDispatch = true) {
39066
- const { editor, state: state2, rawCommands } = this;
39067
- const { view } = editor;
39068
- const props = {
39069
- tr,
39070
- editor,
39071
- view,
39072
- state: chainableEditorState(tr, state2),
39073
- dispatch: shouldDispatch ? () => void 0 : void 0,
39074
- chain: () => this.createChain(tr, shouldDispatch),
39075
- can: () => this.createCan(tr),
39076
- get commands() {
39077
- return Object.fromEntries(
39078
- Object.entries(rawCommands).map(([name, command2]) => {
39079
- return [name, (...args) => command2(...args)(props)];
39080
- })
39081
- );
39082
- }
39083
- };
39084
- return props;
39085
- }
39086
- }
39087
39291
  const first = (commands2) => (props) => {
39088
39292
  const items = typeof commands2 === "function" ? commands2(props) : commands2;
39089
39293
  for (let i2 = 0; i2 < items.length; i2 += 1) {
@@ -40120,6 +40324,30 @@
40120
40324
  }
40121
40325
  return true;
40122
40326
  };
40327
+ const undoInputRule = () => ({ state: state2, dispatch }) => {
40328
+ const plugins = state2.plugins;
40329
+ for (let i2 = 0; i2 < plugins.length; i2 += 1) {
40330
+ const plugin2 = plugins[i2];
40331
+ let undoable;
40332
+ if (plugin2.spec.isInputRules && (undoable = plugin2.getState(state2))) {
40333
+ if (dispatch) {
40334
+ const tr = state2.tr;
40335
+ const toUndo = undoable.transform;
40336
+ for (let j = toUndo.steps.length - 1; j >= 0; j -= 1) {
40337
+ tr.step(toUndo.steps[j].invert(toUndo.docs[j]));
40338
+ }
40339
+ if (undoable.text) {
40340
+ const marks = tr.doc.resolve(undoable.from).marks();
40341
+ tr.replaceWith(undoable.from, undoable.to, state2.schema.text(undoable.text, marks));
40342
+ } else {
40343
+ tr.delete(undoable.from, undoable.to);
40344
+ }
40345
+ }
40346
+ return true;
40347
+ }
40348
+ }
40349
+ return false;
40350
+ };
40123
40351
  function wrapInList$1(listType, attrs = null) {
40124
40352
  return function(state2, dispatch) {
40125
40353
  let { $from, $to } = state2.selection;
@@ -40449,6 +40677,7 @@
40449
40677
  toggleList,
40450
40678
  toggleMark,
40451
40679
  toggleNode,
40680
+ undoInputRule,
40452
40681
  unsetAllMarks,
40453
40682
  unsetMark,
40454
40683
  updateAttributes,
@@ -40478,6 +40707,7 @@
40478
40707
  () => commands2.splitBlock()
40479
40708
  ]);
40480
40709
  const handleBackspace = () => this.editor.commands.first(({ commands: commands2, tr }) => [
40710
+ () => commands2.undoInputRule(),
40481
40711
  () => {
40482
40712
  tr.setMeta("inputType", "deleteContentBackward");
40483
40713
  return false;
@@ -42140,6 +42370,7 @@
42140
42370
  editorProps: {},
42141
42371
  parseOptions: {},
42142
42372
  coreExtensionOptions: {},
42373
+ enableInputRules: true,
42143
42374
  isCommentsEnabled: false,
42144
42375
  isNewFile: false,
42145
42376
  scale: 1,
@@ -42578,7 +42809,7 @@
42578
42809
  * @returns {Y.Doc | undefined} Updated Y.Doc if any, otherwise undefined
42579
42810
  */
42580
42811
  processCollaborationMigrations() {
42581
- console.debug("[checkVersionMigrations] Current editor version", "0.8.10");
42812
+ console.debug("[checkVersionMigrations] Current editor version", "0.8.11");
42582
42813
  if (!this.options.ydoc) return;
42583
42814
  const metaMap = this.options.ydoc.getMap("meta");
42584
42815
  let docVersion = metaMap.get("version");
@@ -43923,6 +44154,45 @@
43923
44154
  };
43924
44155
  }
43925
44156
  });
44157
+ function wrappingInputRule(config) {
44158
+ return new InputRule({
44159
+ match: config.match,
44160
+ handler: ({
44161
+ state: state2,
44162
+ range: range2,
44163
+ match: match2,
44164
+ chain
44165
+ }) => {
44166
+ const attributes = callOrGet(config.getAttributes, null, match2) || {};
44167
+ const tr = state2.tr.delete(range2.from, range2.to);
44168
+ const $start = tr.doc.resolve(range2.from);
44169
+ const blockRange = $start.blockRange();
44170
+ const wrapping = blockRange && findWrapping(blockRange, config.type, attributes);
44171
+ if (!wrapping) {
44172
+ return null;
44173
+ }
44174
+ tr.wrap(blockRange, wrapping);
44175
+ if (config.keepMarks && config.editor) {
44176
+ const { selection, storedMarks } = state2;
44177
+ const { splittableMarks } = config.editor.extensionService;
44178
+ const marks = storedMarks || selection.$to.parentOffset && selection.$from.marks();
44179
+ if (marks) {
44180
+ const filteredMarks = marks.filter((mark) => splittableMarks.includes(mark.type.name));
44181
+ tr.ensureMarks(filteredMarks);
44182
+ }
44183
+ }
44184
+ if (config.keepAttributes) {
44185
+ const nodeType = config.type.name === "bulletList" || config.type.name === "orderedList" ? "listItem" : config.type.name;
44186
+ chain().updateAttributes(nodeType, attributes).run();
44187
+ }
44188
+ const before = tr.doc.resolve(range2.from - 1).nodeBefore;
44189
+ if (before && before.type === config.type && canJoin(tr.doc, range2.from - 1) && (!config.joinPredicate || config.joinPredicate(match2, before))) {
44190
+ tr.join(range2.from - 1);
44191
+ }
44192
+ }
44193
+ });
44194
+ }
44195
+ const inputRegex$1 = /^\s*([-+*])\s$/;
43926
44196
  const BulletList = Node$1.create({
43927
44197
  name: "bulletList",
43928
44198
  group: "block list",
@@ -43933,7 +44203,8 @@
43933
44203
  return {
43934
44204
  itemTypeName: "listItem",
43935
44205
  htmlAttributes: {},
43936
- keepMarks: true
44206
+ keepMarks: true,
44207
+ keepAttributes: false
43937
44208
  };
43938
44209
  },
43939
44210
  parseDOM() {
@@ -43971,8 +44242,29 @@
43971
44242
  return this.editor.commands.toggleBulletList();
43972
44243
  }
43973
44244
  };
43974
- }
44245
+ },
43975
44246
  // Input rules.
44247
+ addInputRules() {
44248
+ let inputRule = wrappingInputRule({
44249
+ match: inputRegex$1,
44250
+ type: this.type
44251
+ });
44252
+ if (this.options.keepMarks || this.options.keepAttributes) {
44253
+ inputRule = wrappingInputRule({
44254
+ match: inputRegex$1,
44255
+ type: this.type,
44256
+ keepMarks: this.options.keepMarks,
44257
+ keepAttributes: this.options.keepAttributes,
44258
+ getAttributes: () => {
44259
+ return this.editor.getAttributes("textStyle");
44260
+ },
44261
+ editor: this.editor
44262
+ });
44263
+ }
44264
+ return [
44265
+ inputRule
44266
+ ];
44267
+ }
43976
44268
  });
43977
44269
  function orderedListSync(options2 = {}) {
43978
44270
  return new Plugin({
@@ -44183,6 +44475,7 @@
44183
44475
  listNumberingType
44184
44476
  };
44185
44477
  }
44478
+ const inputRegex = /^(\d+)\.\s$/;
44186
44479
  const OrderedList = Node$1.create({
44187
44480
  name: "orderedList",
44188
44481
  group: "block list",
@@ -44194,6 +44487,7 @@
44194
44487
  itemTypeName: "listItem",
44195
44488
  htmlAttributes: {},
44196
44489
  keepMarks: true,
44490
+ keepAttributes: false,
44197
44491
  listStyleTypes: ["decimal", "lowerAlpha", "lowerRoman"]
44198
44492
  };
44199
44493
  },
@@ -44351,6 +44645,28 @@
44351
44645
  },
44352
44646
  addPmPlugins() {
44353
44647
  return [orderedListMarker(), orderedListSync()];
44648
+ },
44649
+ addInputRules() {
44650
+ let inputRule = wrappingInputRule({
44651
+ match: inputRegex,
44652
+ type: this.type,
44653
+ getAttributes: (match2) => ({ start: +match2[1] }),
44654
+ joinPredicate: (match2, node2) => node2.childCount + node2.attrs.start === +match2[1]
44655
+ });
44656
+ if (this.options.keepMarks || this.options.keepAttributes) {
44657
+ inputRule = wrappingInputRule({
44658
+ match: inputRegex,
44659
+ type: this.type,
44660
+ keepMarks: this.options.keepMarks,
44661
+ keepAttributes: this.options.keepAttributes,
44662
+ getAttributes: (match2) => ({ start: +match2[1], ...this.editor.getAttributes("textStyle") }),
44663
+ joinPredicate: (match2, node2) => node2.childCount + node2.attrs.start === +match2[1],
44664
+ editor: this.editor
44665
+ });
44666
+ }
44667
+ return [
44668
+ inputRule
44669
+ ];
44354
44670
  }
44355
44671
  });
44356
44672
  function randomId() {
@@ -110962,7 +111278,7 @@ ${style2}
110962
111278
  this.config.colors = shuffleArray(this.config.colors);
110963
111279
  this.userColorMap = /* @__PURE__ */ new Map();
110964
111280
  this.colorIndex = 0;
110965
- this.version = "0.8.10";
111281
+ this.version = "0.8.11";
110966
111282
  console.debug("🦋 [superdoc] Using SuperDoc version:", this.version);
110967
111283
  this.superdocId = config.superdocId || v4();
110968
111284
  this.colors = this.config.colors;