@ecodev/natural-editor 41.2.0 → 41.2.1

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.
@@ -1,8 +1,8 @@
1
1
  (function (global, factory) {
2
- typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@angular/localize/init'), require('@angular/core'), require('prosemirror-view'), require('prosemirror-state'), require('prosemirror-example-setup'), require('prosemirror-model'), require('@angular/common'), require('prosemirror-tables'), require('prosemirror-keymap'), require('prosemirror-schema-basic'), require('prosemirror-schema-list'), require('prosemirror-menu'), require('prosemirror-commands'), require('@angular/material/dialog'), require('@angular/forms'), require('@ecodev/natural'), require('@angular/material/form-field'), require('@angular/material/button'), require('@angular/material/input'), require('@angular/material/icon'), require('@angular/material/button-toggle'), require('@angular/material/menu'), require('@angular/material/divider'), require('@angular/material/tooltip'), require('@angular/material/toolbar')) :
3
- typeof define === 'function' && define.amd ? define('@ecodev/natural-editor', ['exports', '@angular/localize/init', '@angular/core', 'prosemirror-view', 'prosemirror-state', 'prosemirror-example-setup', 'prosemirror-model', '@angular/common', 'prosemirror-tables', 'prosemirror-keymap', 'prosemirror-schema-basic', 'prosemirror-schema-list', 'prosemirror-menu', 'prosemirror-commands', '@angular/material/dialog', '@angular/forms', '@ecodev/natural', '@angular/material/form-field', '@angular/material/button', '@angular/material/input', '@angular/material/icon', '@angular/material/button-toggle', '@angular/material/menu', '@angular/material/divider', '@angular/material/tooltip', '@angular/material/toolbar'], factory) :
4
- (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory((global.ecodev = global.ecodev || {}, global.ecodev["natural-editor"] = {}), global.ng.localize.init, global.ng.core, global["prosemirror-view"], global["prosemirror-state"], global["prosemirror-example-setup"], global["prosemirror-model"], global.ng.common, global.prosemirrorTables, global.prosemirrorKeymap, global["prosemirror-schema-basic"], global["prosemirror-schema-list"], global["prosemirror-menu"], global["prosemirror-commands"], global.ng.material.dialog, global.ng.forms, global.i11, global.ng.material.formField, global.ng.material.button, global.ng.material.input, global.ng.material.icon, global.ng.material.buttonToggle, global.ng.material.menu, global.ng.material.divider, global.ng.material.tooltip, global.ng.material.toolbar));
5
- })(this, (function (exports, init, i0, prosemirrorView, prosemirrorState, prosemirrorExampleSetup, prosemirrorModel, i6, prosemirrorTables, prosemirrorKeymap, prosemirrorSchemaBasic, prosemirrorSchemaList, prosemirrorMenu, prosemirrorCommands, i1, i4, i11, i2, i3, i5, i5$1, i6$1, i7, i8, i10, toolbar) { 'use strict';
2
+ typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@angular/localize/init'), require('@angular/core'), require('prosemirror-view'), require('prosemirror-state'), require('prosemirror-model'), require('@angular/common'), require('prosemirror-tables'), require('prosemirror-keymap'), require('prosemirror-schema-basic'), require('prosemirror-schema-list'), require('prosemirror-menu'), require('prosemirror-commands'), require('@angular/material/dialog'), require('@angular/forms'), require('@ecodev/natural'), require('@angular/material/form-field'), require('@angular/material/button'), require('@angular/material/input'), require('prosemirror-history'), require('prosemirror-dropcursor'), require('prosemirror-gapcursor'), require('prosemirror-inputrules'), require('@angular/material/icon'), require('@angular/material/button-toggle'), require('@angular/material/menu'), require('@angular/material/divider'), require('@angular/material/tooltip'), require('@angular/material/toolbar')) :
3
+ typeof define === 'function' && define.amd ? define('@ecodev/natural-editor', ['exports', '@angular/localize/init', '@angular/core', 'prosemirror-view', 'prosemirror-state', 'prosemirror-model', '@angular/common', 'prosemirror-tables', 'prosemirror-keymap', 'prosemirror-schema-basic', 'prosemirror-schema-list', 'prosemirror-menu', 'prosemirror-commands', '@angular/material/dialog', '@angular/forms', '@ecodev/natural', '@angular/material/form-field', '@angular/material/button', '@angular/material/input', 'prosemirror-history', 'prosemirror-dropcursor', 'prosemirror-gapcursor', 'prosemirror-inputrules', '@angular/material/icon', '@angular/material/button-toggle', '@angular/material/menu', '@angular/material/divider', '@angular/material/tooltip', '@angular/material/toolbar'], factory) :
4
+ (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory((global.ecodev = global.ecodev || {}, global.ecodev["natural-editor"] = {}), global.ng.localize.init, global.ng.core, global["prosemirror-view"], global["prosemirror-state"], global["prosemirror-model"], global.ng.common, global.prosemirrorTables, global.prosemirrorKeymap, global["prosemirror-schema-basic"], global["prosemirror-schema-list"], global["prosemirror-menu"], global["prosemirror-commands"], global.ng.material.dialog, global.ng.forms, global.i11, global.ng.material.formField, global.ng.material.button, global.ng.material.input, global.prosemirrorHistory, global.prosemirrorDropcursor, global.prosemirrorGapcursor, global.prosemirrorInputrules, global.ng.material.icon, global.ng.material.buttonToggle, global.ng.material.menu, global.ng.material.divider, global.ng.material.tooltip, global.ng.material.toolbar));
5
+ })(this, (function (exports, init, i0, prosemirrorView, prosemirrorState, prosemirrorModel, i6, prosemirrorTables, prosemirrorKeymap, prosemirrorSchemaBasic, prosemirrorSchemaList, prosemirrorMenu, prosemirrorCommands, i1, i4, i11, i2, i3, i5, prosemirrorHistory, prosemirrorDropcursor, prosemirrorGapcursor, prosemirrorInputrules, i5$1, i6$1, i7, i8, i10, toolbar) { 'use strict';
6
6
 
7
7
  function _interopNamespace(e) {
8
8
  if (e && e.__esModule) return e;
@@ -752,6 +752,186 @@
752
752
  return r;
753
753
  }
754
754
 
755
+ /**
756
+ * Given a blockquote node type, returns an input rule that turns `"> "`
757
+ * at the start of a textblock into a blockquote.
758
+ */
759
+ function blockQuoteRule(nodeType) {
760
+ return prosemirrorInputrules.wrappingInputRule(/^\s*>\s$/, nodeType);
761
+ }
762
+ /**
763
+ * Given a list node type, returns an input rule that turns a number
764
+ * followed by a dot at the start of a textblock into an ordered list.
765
+ */
766
+ function orderedListRule(nodeType) {
767
+ return prosemirrorInputrules.wrappingInputRule(/^(\d+)\.\s$/, nodeType, function (match) { return ({ order: +match[1] }); }, function (match, node) { return node.childCount + node.attrs.order === +match[1]; });
768
+ }
769
+ /**
770
+ * Given a list node type, returns an input rule that turns a bullet
771
+ * (dash, plush, or asterisk) at the start of a textblock into a
772
+ * bullet list.
773
+ */
774
+ function bulletListRule(nodeType) {
775
+ return prosemirrorInputrules.wrappingInputRule(/^\s*([-+*])\s$/, nodeType);
776
+ }
777
+ /**
778
+ * Given a code block node type, returns an input rule that turns a
779
+ * textblock starting with three backticks into a code block.
780
+ */
781
+ function codeBlockRule(nodeType) {
782
+ return prosemirrorInputrules.textblockTypeInputRule(/^```$/, nodeType);
783
+ }
784
+ /**
785
+ * Given a node type and a maximum level, creates an input rule that
786
+ * turns up to that number of `#` characters followed by a space at
787
+ * the start of a textblock into a heading whose level corresponds to
788
+ * the number of `#` signs.
789
+ */
790
+ function headingRule(nodeType, maxLevel) {
791
+ return prosemirrorInputrules.textblockTypeInputRule(new RegExp('^(#{1,' + maxLevel + '})\\s$'), nodeType, function (match) { return ({
792
+ level: match[1].length,
793
+ }); });
794
+ }
795
+ /**
796
+ * A set of input rules for creating the basic block quotes, lists,
797
+ * code blocks, and heading.
798
+ */
799
+ function buildInputRules(schema) {
800
+ var rules = [prosemirrorInputrules.ellipsis, prosemirrorInputrules.emDash];
801
+ var type = schema.nodes.blockquote;
802
+ if (type) {
803
+ rules.push(blockQuoteRule(type));
804
+ }
805
+ type = schema.nodes.ordered_list;
806
+ if (type) {
807
+ rules.push(orderedListRule(type));
808
+ }
809
+ type = schema.nodes.bullet_list;
810
+ if (type) {
811
+ rules.push(bulletListRule(type));
812
+ }
813
+ type = schema.nodes.code_block;
814
+ if (type) {
815
+ rules.push(codeBlockRule(type));
816
+ }
817
+ type = schema.nodes.heading;
818
+ if (type) {
819
+ rules.push(headingRule(type, 6));
820
+ }
821
+ return prosemirrorInputrules.inputRules({ rules: rules });
822
+ }
823
+
824
+ /**
825
+ * Inspect the given schema looking for marks and nodes from the
826
+ * basic schema, and if found, add key bindings related to them.
827
+ * This will add:
828
+ *
829
+ * * **Mod-b** for toggling [strong](#schema-basic.StrongMark)
830
+ * * **Mod-i** for toggling [emphasis](#schema-basic.EmMark)
831
+ * * **Mod-`** for toggling [code font](#schema-basic.CodeMark)
832
+ * * **Ctrl-Shift-0** for making the current textblock a paragraph
833
+ * * **Ctrl-Shift-1** to **Ctrl-Shift-Digit6** for making the current
834
+ * textblock a heading of the corresponding level
835
+ * * **Ctrl-Shift-Backslash** to make the current textblock a code block
836
+ * * **Ctrl-Shift-8** to wrap the selection in an ordered list
837
+ * * **Ctrl-Shift-9** to wrap the selection in a bullet list
838
+ * * **Ctrl->** to wrap the selection in a block quote
839
+ * * **Enter** to split a non-empty textblock in a list item while at
840
+ * the same time splitting the list item
841
+ * * **Mod-Enter** to insert a hard break
842
+ * * **Mod-_** to insert a horizontal rule
843
+ * * **Backspace** to undo an input rule
844
+ * * **Alt-ArrowUp** to `joinUp`
845
+ * * **Alt-ArrowDown** to `joinDown`
846
+ * * **Mod-BracketLeft** to `lift`
847
+ * * **Escape** to `selectParentNode`
848
+ *
849
+ * You can suppress or map these bindings by passing a `mapKeys`
850
+ * argument, which maps key names (say `"Mod-B"` to either `false`, to
851
+ * remove the binding, or a new key name string.
852
+ */
853
+ function buildKeymap(schema, isMac) {
854
+ var keys = {};
855
+ keys['Mod-z'] = prosemirrorHistory.undo;
856
+ keys['Shift-Mod-z'] = prosemirrorHistory.redo;
857
+ keys['Backspace'] = prosemirrorInputrules.undoInputRule;
858
+ if (!isMac) {
859
+ keys['Mod-y'] = prosemirrorHistory.redo;
860
+ }
861
+ keys['Alt-ArrowUp'] = prosemirrorCommands.joinUp;
862
+ keys['Alt-ArrowDown'] = prosemirrorCommands.joinDown;
863
+ keys['Mod-BracketLeft'] = prosemirrorCommands.lift;
864
+ keys['Escape'] = prosemirrorCommands.selectParentNode;
865
+ var type = schema.marks.strong;
866
+ if (type) {
867
+ keys['Mod-b'] = prosemirrorCommands.toggleMark(type);
868
+ keys['Mod-B'] = prosemirrorCommands.toggleMark(type);
869
+ }
870
+ type = schema.marks.em;
871
+ if (type) {
872
+ keys['Mod-i'] = prosemirrorCommands.toggleMark(type);
873
+ keys['Mod-I'] = prosemirrorCommands.toggleMark(type);
874
+ }
875
+ type = schema.marks.code;
876
+ if (type) {
877
+ keys['Mod-`'] = prosemirrorCommands.toggleMark(type);
878
+ }
879
+ type = schema.nodes.bullet_list;
880
+ if (type) {
881
+ keys['Shift-Ctrl-8'] = prosemirrorSchemaList.wrapInList(type);
882
+ }
883
+ type = schema.nodes.ordered_list;
884
+ if (type) {
885
+ keys['Shift-Ctrl-9'] = prosemirrorSchemaList.wrapInList(type);
886
+ }
887
+ type = schema.nodes.blockquote;
888
+ if (type) {
889
+ keys['Ctrl->'] = prosemirrorCommands.wrapIn(type);
890
+ }
891
+ type = schema.nodes.hard_break;
892
+ if (type) {
893
+ var br_1 = type;
894
+ var cmd = prosemirrorCommands.chainCommands(prosemirrorCommands.exitCode, function (state, dispatch) {
895
+ dispatch === null || dispatch === void 0 ? void 0 : dispatch(state.tr.replaceSelectionWith(br_1.create()).scrollIntoView());
896
+ return true;
897
+ });
898
+ keys['Mod-Enter'] = cmd;
899
+ keys['Shift-Enter'] = cmd;
900
+ if (isMac) {
901
+ keys['Ctrl-Enter'] = cmd;
902
+ }
903
+ }
904
+ type = schema.nodes.list_item;
905
+ if (type) {
906
+ keys['Enter'] = prosemirrorSchemaList.splitListItem(type);
907
+ keys['Mod-['] = prosemirrorSchemaList.liftListItem(type);
908
+ keys['Mod-]'] = prosemirrorSchemaList.sinkListItem(type);
909
+ }
910
+ type = schema.nodes.paragraph;
911
+ if (type) {
912
+ keys['Shift-Ctrl-0'] = prosemirrorCommands.setBlockType(type);
913
+ }
914
+ type = schema.nodes.code_block;
915
+ if (type) {
916
+ keys['Shift-Ctrl-\\'] = prosemirrorCommands.setBlockType(type);
917
+ }
918
+ type = schema.nodes.heading;
919
+ if (type) {
920
+ for (var i = 1; i <= 6; i++) {
921
+ keys['Shift-Ctrl-' + i] = prosemirrorCommands.setBlockType(type, { level: i });
922
+ }
923
+ }
924
+ type = schema.nodes.horizontal_rule;
925
+ if (type) {
926
+ var hr_1 = type;
927
+ keys['Mod-_'] = function (state, dispatch) {
928
+ dispatch === null || dispatch === void 0 ? void 0 : dispatch(state.tr.replaceSelectionWith(hr_1.create()).scrollIntoView());
929
+ return true;
930
+ };
931
+ }
932
+ return keys;
933
+ }
934
+
755
935
  /**
756
936
  * Prosemirror component
757
937
  *
@@ -832,7 +1012,6 @@
832
1012
  }
833
1013
  };
834
1014
  NaturalEditorComponent.prototype.createState = function () {
835
- var _this = this;
836
1015
  var template = this.document.createElement('_');
837
1016
  template.innerHTML = '<div>' + this.content + '</div>';
838
1017
  if (!template.firstChild) {
@@ -840,40 +1019,57 @@
840
1019
  }
841
1020
  var parser = prosemirrorModel.DOMParser.fromSchema(this.schema);
842
1021
  var doc = parser.parse(template.firstChild);
843
- var plugins = __spreadArray(__spreadArray([], __read(prosemirrorExampleSetup.exampleSetup({ schema: this.schema, menuBar: false }))), [
1022
+ return prosemirrorState.EditorState.create({
1023
+ doc: doc,
1024
+ plugins: this.createPlugins(),
1025
+ });
1026
+ };
1027
+ NaturalEditorComponent.prototype.createPlugins = function () {
1028
+ var _this = this;
1029
+ var _a;
1030
+ var isMac = !!((_a = this.document.defaultView) === null || _a === void 0 ? void 0 : _a.navigator.platform.match(/Mac/));
1031
+ var plugins = [
1032
+ buildInputRules(this.schema),
1033
+ prosemirrorKeymap.keymap(buildKeymap(this.schema, isMac)),
1034
+ prosemirrorKeymap.keymap(prosemirrorCommands.baseKeymap),
1035
+ prosemirrorDropcursor.dropCursor(),
1036
+ prosemirrorGapcursor.gapCursor(),
1037
+ prosemirrorHistory.history(),
1038
+ new prosemirrorState.Plugin({
1039
+ props: {
1040
+ attributes: { class: 'ProseMirror-example-setup-style' },
1041
+ },
1042
+ }),
844
1043
  new prosemirrorState.Plugin({
845
1044
  view: function () { return _this; },
846
1045
  }),
847
- ]);
1046
+ ];
848
1047
  if (this.schema === advancedSchema) {
849
1048
  plugins.push(this.imagePlugin.plugin, prosemirrorTables.columnResizing(undefined), prosemirrorTables.tableEditing(), prosemirrorKeymap.keymap({
850
1049
  Tab: prosemirrorTables.goToNextCell(1),
851
1050
  'Shift-Tab': prosemirrorTables.goToNextCell(-1),
852
1051
  }));
853
1052
  }
854
- return prosemirrorState.EditorState.create({
855
- doc: doc,
856
- plugins: plugins,
857
- });
1053
+ return plugins;
858
1054
  };
859
1055
  /**
860
1056
  * Called by Prosemirror whenever the editor state changes. So we update our menu states.
861
1057
  */
862
1058
  NaturalEditorComponent.prototype.update = function () {
863
- var e_1, _a;
1059
+ var e_1, _b;
864
1060
  if (!this.view || !this.menu) {
865
1061
  return;
866
1062
  }
867
1063
  try {
868
- for (var _b = __values(Object.values(this.menu)), _c = _b.next(); !_c.done; _c = _b.next()) {
869
- var item = _c.value;
1064
+ for (var _c = __values(Object.values(this.menu)), _d = _c.next(); !_d.done; _d = _c.next()) {
1065
+ var item = _d.value;
870
1066
  item.update(this.view, this.view.state);
871
1067
  }
872
1068
  }
873
1069
  catch (e_1_1) { e_1 = { error: e_1_1 }; }
874
1070
  finally {
875
1071
  try {
876
- if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
1072
+ if (_d && !_d.done && (_b = _c.return)) _b.call(_c);
877
1073
  }
878
1074
  finally { if (e_1) throw e_1.error; }
879
1075
  }