@tiptap/extension-focus 2.5.0-beta.1 → 2.5.0-beta.3

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 (170) hide show
  1. package/dist/index.cjs +65 -65
  2. package/dist/index.cjs.map +1 -1
  3. package/dist/index.js +64 -64
  4. package/dist/index.js.map +1 -1
  5. package/dist/index.umd.js +65 -65
  6. package/dist/index.umd.js.map +1 -1
  7. package/dist/packages/core/src/CommandManager.d.ts +20 -0
  8. package/dist/packages/core/src/Editor.d.ts +161 -0
  9. package/dist/packages/core/src/EventEmitter.d.ts +11 -0
  10. package/dist/packages/core/src/Extension.d.ts +343 -0
  11. package/dist/packages/core/src/ExtensionManager.d.ts +55 -0
  12. package/dist/packages/core/src/InputRule.d.ts +42 -0
  13. package/dist/packages/core/src/Mark.d.ts +451 -0
  14. package/dist/packages/core/src/Node.d.ts +611 -0
  15. package/dist/packages/core/src/NodePos.d.ts +44 -0
  16. package/dist/packages/core/src/NodeView.d.ts +31 -0
  17. package/dist/packages/core/src/PasteRule.d.ts +50 -0
  18. package/dist/packages/core/src/Tracker.d.ts +11 -0
  19. package/dist/packages/core/src/commands/blur.d.ts +13 -0
  20. package/dist/packages/core/src/commands/clearContent.d.ts +14 -0
  21. package/dist/packages/core/src/commands/clearNodes.d.ts +13 -0
  22. package/dist/packages/core/src/commands/command.d.ts +18 -0
  23. package/dist/packages/core/src/commands/createParagraphNear.d.ts +13 -0
  24. package/dist/packages/core/src/commands/cut.d.ts +20 -0
  25. package/dist/packages/core/src/commands/deleteCurrentNode.d.ts +13 -0
  26. package/dist/packages/core/src/commands/deleteNode.d.ts +15 -0
  27. package/dist/packages/core/src/commands/deleteRange.d.ts +14 -0
  28. package/dist/packages/core/src/commands/deleteSelection.d.ts +13 -0
  29. package/dist/packages/core/src/commands/enter.d.ts +13 -0
  30. package/dist/packages/core/src/commands/exitCode.d.ts +13 -0
  31. package/dist/packages/core/src/commands/extendMarkRange.d.ts +25 -0
  32. package/dist/packages/core/src/commands/first.d.ts +14 -0
  33. package/dist/packages/core/src/commands/focus.d.ts +27 -0
  34. package/dist/packages/core/src/commands/forEach.d.ts +14 -0
  35. package/dist/packages/core/src/commands/index.d.ts +55 -0
  36. package/dist/packages/core/src/commands/insertContent.d.ts +34 -0
  37. package/dist/packages/core/src/commands/insertContentAt.d.ts +47 -0
  38. package/dist/packages/core/src/commands/join.d.ts +41 -0
  39. package/dist/packages/core/src/commands/joinItemBackward.d.ts +13 -0
  40. package/dist/packages/core/src/commands/joinItemForward.d.ts +13 -0
  41. package/dist/packages/core/src/commands/joinTextblockBackward.d.ts +12 -0
  42. package/dist/packages/core/src/commands/joinTextblockForward.d.ts +12 -0
  43. package/dist/packages/core/src/commands/keyboardShortcut.d.ts +14 -0
  44. package/dist/packages/core/src/commands/lift.d.ts +17 -0
  45. package/dist/packages/core/src/commands/liftEmptyBlock.d.ts +13 -0
  46. package/dist/packages/core/src/commands/liftListItem.d.ts +15 -0
  47. package/dist/packages/core/src/commands/newlineInCode.d.ts +13 -0
  48. package/dist/packages/core/src/commands/resetAttributes.d.ts +16 -0
  49. package/dist/packages/core/src/commands/scrollIntoView.d.ts +13 -0
  50. package/dist/packages/core/src/commands/selectAll.d.ts +13 -0
  51. package/dist/packages/core/src/commands/selectNodeBackward.d.ts +13 -0
  52. package/dist/packages/core/src/commands/selectNodeForward.d.ts +13 -0
  53. package/dist/packages/core/src/commands/selectParentNode.d.ts +13 -0
  54. package/dist/packages/core/src/commands/selectTextblockEnd.d.ts +13 -0
  55. package/dist/packages/core/src/commands/selectTextblockStart.d.ts +13 -0
  56. package/dist/packages/core/src/commands/setContent.d.ts +40 -0
  57. package/dist/packages/core/src/commands/setMark.d.ts +15 -0
  58. package/dist/packages/core/src/commands/setMeta.d.ts +15 -0
  59. package/dist/packages/core/src/commands/setNode.d.ts +16 -0
  60. package/dist/packages/core/src/commands/setNodeSelection.d.ts +14 -0
  61. package/dist/packages/core/src/commands/setTextSelection.d.ts +14 -0
  62. package/dist/packages/core/src/commands/sinkListItem.d.ts +15 -0
  63. package/dist/packages/core/src/commands/splitBlock.d.ts +17 -0
  64. package/dist/packages/core/src/commands/splitListItem.d.ts +15 -0
  65. package/dist/packages/core/src/commands/toggleList.d.ts +18 -0
  66. package/dist/packages/core/src/commands/toggleMark.d.ts +30 -0
  67. package/dist/packages/core/src/commands/toggleNode.d.ts +17 -0
  68. package/dist/packages/core/src/commands/toggleWrap.d.ts +16 -0
  69. package/dist/packages/core/src/commands/undoInputRule.d.ts +13 -0
  70. package/dist/packages/core/src/commands/unsetAllMarks.d.ts +13 -0
  71. package/dist/packages/core/src/commands/unsetMark.d.ts +25 -0
  72. package/dist/packages/core/src/commands/updateAttributes.d.ts +24 -0
  73. package/dist/packages/core/src/commands/wrapIn.d.ts +16 -0
  74. package/dist/packages/core/src/commands/wrapInList.d.ts +16 -0
  75. package/dist/packages/core/src/extensions/clipboardTextSerializer.d.ts +5 -0
  76. package/dist/packages/core/src/extensions/commands.d.ts +3 -0
  77. package/dist/packages/core/src/extensions/editable.d.ts +2 -0
  78. package/dist/packages/core/src/extensions/focusEvents.d.ts +2 -0
  79. package/dist/packages/core/src/extensions/index.d.ts +6 -0
  80. package/dist/packages/core/src/extensions/keymap.d.ts +2 -0
  81. package/dist/packages/core/src/extensions/tabindex.d.ts +2 -0
  82. package/dist/packages/core/src/helpers/combineTransactionSteps.d.ts +10 -0
  83. package/dist/packages/core/src/helpers/createChainableState.d.ts +10 -0
  84. package/dist/packages/core/src/helpers/createDocument.d.ts +12 -0
  85. package/dist/packages/core/src/helpers/createNodeFromContent.d.ts +15 -0
  86. package/dist/packages/core/src/helpers/defaultBlockAt.d.ts +7 -0
  87. package/dist/packages/core/src/helpers/findChildren.d.ts +9 -0
  88. package/dist/packages/core/src/helpers/findChildrenInRange.d.ts +10 -0
  89. package/dist/packages/core/src/helpers/findParentNode.d.ts +16 -0
  90. package/dist/packages/core/src/helpers/findParentNodeClosestToPos.d.ts +17 -0
  91. package/dist/packages/core/src/helpers/generateHTML.d.ts +8 -0
  92. package/dist/packages/core/src/helpers/generateJSON.d.ts +8 -0
  93. package/dist/packages/core/src/helpers/generateText.d.ts +12 -0
  94. package/dist/packages/core/src/helpers/getAttributes.d.ts +9 -0
  95. package/dist/packages/core/src/helpers/getAttributesFromExtensions.d.ts +6 -0
  96. package/dist/packages/core/src/helpers/getChangedRanges.d.ts +11 -0
  97. package/dist/packages/core/src/helpers/getDebugJSON.d.ts +8 -0
  98. package/dist/packages/core/src/helpers/getExtensionField.d.ts +9 -0
  99. package/dist/packages/core/src/helpers/getHTMLFromFragment.d.ts +2 -0
  100. package/dist/packages/core/src/helpers/getMarkAttributes.d.ts +3 -0
  101. package/dist/packages/core/src/helpers/getMarkRange.d.ts +3 -0
  102. package/dist/packages/core/src/helpers/getMarkType.d.ts +2 -0
  103. package/dist/packages/core/src/helpers/getMarksBetween.d.ts +3 -0
  104. package/dist/packages/core/src/helpers/getNodeAtPosition.d.ts +11 -0
  105. package/dist/packages/core/src/helpers/getNodeAttributes.d.ts +3 -0
  106. package/dist/packages/core/src/helpers/getNodeType.d.ts +2 -0
  107. package/dist/packages/core/src/helpers/getRenderedAttributes.d.ts +3 -0
  108. package/dist/packages/core/src/helpers/getSchema.d.ts +4 -0
  109. package/dist/packages/core/src/helpers/getSchemaByResolvedExtensions.d.ts +10 -0
  110. package/dist/packages/core/src/helpers/getSchemaTypeByName.d.ts +8 -0
  111. package/dist/packages/core/src/helpers/getSchemaTypeNameByName.d.ts +8 -0
  112. package/dist/packages/core/src/helpers/getSplittedAttributes.d.ts +9 -0
  113. package/dist/packages/core/src/helpers/getText.d.ts +15 -0
  114. package/dist/packages/core/src/helpers/getTextBetween.d.ts +14 -0
  115. package/dist/packages/core/src/helpers/getTextContentFromNodes.d.ts +8 -0
  116. package/dist/packages/core/src/helpers/getTextSerializersFromSchema.d.ts +8 -0
  117. package/dist/packages/core/src/helpers/index.d.ts +50 -0
  118. package/dist/packages/core/src/helpers/injectExtensionAttributesToParseRule.d.ts +9 -0
  119. package/dist/packages/core/src/helpers/isActive.d.ts +2 -0
  120. package/dist/packages/core/src/helpers/isAtEndOfNode.d.ts +2 -0
  121. package/dist/packages/core/src/helpers/isAtStartOfNode.d.ts +2 -0
  122. package/dist/packages/core/src/helpers/isExtensionRulesEnabled.d.ts +2 -0
  123. package/dist/packages/core/src/helpers/isList.d.ts +2 -0
  124. package/dist/packages/core/src/helpers/isMarkActive.d.ts +3 -0
  125. package/dist/packages/core/src/helpers/isNodeActive.d.ts +3 -0
  126. package/dist/packages/core/src/helpers/isNodeEmpty.d.ts +2 -0
  127. package/dist/packages/core/src/helpers/isNodeSelection.d.ts +2 -0
  128. package/dist/packages/core/src/helpers/isTextSelection.d.ts +2 -0
  129. package/dist/packages/core/src/helpers/posToDOMRect.d.ts +2 -0
  130. package/dist/packages/core/src/helpers/resolveFocusPosition.d.ts +4 -0
  131. package/dist/packages/core/src/helpers/selectionToInsertionEnd.d.ts +2 -0
  132. package/dist/packages/core/src/helpers/splitExtensions.d.ts +9 -0
  133. package/dist/packages/core/src/index.d.ts +24 -0
  134. package/dist/packages/core/src/inputRules/index.d.ts +5 -0
  135. package/dist/packages/core/src/inputRules/markInputRule.d.ts +13 -0
  136. package/dist/packages/core/src/inputRules/nodeInputRule.d.ts +23 -0
  137. package/dist/packages/core/src/inputRules/textInputRule.d.ts +10 -0
  138. package/dist/packages/core/src/inputRules/textblockTypeInputRule.d.ts +15 -0
  139. package/dist/packages/core/src/inputRules/wrappingInputRule.d.ts +28 -0
  140. package/dist/packages/core/src/pasteRules/index.d.ts +3 -0
  141. package/dist/packages/core/src/pasteRules/markPasteRule.d.ts +13 -0
  142. package/dist/packages/core/src/pasteRules/nodePasteRule.d.ts +13 -0
  143. package/dist/packages/core/src/pasteRules/textPasteRule.d.ts +10 -0
  144. package/dist/packages/core/src/style.d.ts +1 -0
  145. package/dist/packages/core/src/types.d.ts +250 -0
  146. package/dist/packages/core/src/utilities/callOrReturn.d.ts +9 -0
  147. package/dist/packages/core/src/utilities/createStyleTag.d.ts +1 -0
  148. package/dist/packages/core/src/utilities/deleteProps.d.ts +6 -0
  149. package/dist/packages/core/src/utilities/elementFromString.d.ts +1 -0
  150. package/dist/packages/core/src/utilities/escapeForRegEx.d.ts +1 -0
  151. package/dist/packages/core/src/utilities/findDuplicates.d.ts +1 -0
  152. package/dist/packages/core/src/utilities/fromString.d.ts +1 -0
  153. package/dist/packages/core/src/utilities/index.d.ts +20 -0
  154. package/dist/packages/core/src/utilities/isAndroid.d.ts +1 -0
  155. package/dist/packages/core/src/utilities/isEmptyObject.d.ts +1 -0
  156. package/dist/packages/core/src/utilities/isFunction.d.ts +1 -0
  157. package/dist/packages/core/src/utilities/isMacOS.d.ts +1 -0
  158. package/dist/packages/core/src/utilities/isNumber.d.ts +1 -0
  159. package/dist/packages/core/src/utilities/isPlainObject.d.ts +1 -0
  160. package/dist/packages/core/src/utilities/isRegExp.d.ts +1 -0
  161. package/dist/packages/core/src/utilities/isString.d.ts +1 -0
  162. package/dist/packages/core/src/utilities/isiOS.d.ts +1 -0
  163. package/dist/packages/core/src/utilities/mergeAttributes.d.ts +1 -0
  164. package/dist/packages/core/src/utilities/mergeDeep.d.ts +1 -0
  165. package/dist/packages/core/src/utilities/minMax.d.ts +1 -0
  166. package/dist/packages/core/src/utilities/objectIncludes.d.ts +8 -0
  167. package/dist/packages/core/src/utilities/removeDuplicates.d.ts +8 -0
  168. package/dist/packages/extension-focus/src/focus.d.ts +25 -25
  169. package/dist/packages/extension-focus/src/index.d.ts +3 -3
  170. package/package.json +3 -3
package/dist/index.cjs CHANGED
@@ -6,72 +6,72 @@ var core = require('@tiptap/core');
6
6
  var state = require('@tiptap/pm/state');
7
7
  var view = require('@tiptap/pm/view');
8
8
 
9
- /**
10
- * This extension allows you to add a class to the focused node.
11
- * @see https://www.tiptap.dev/api/extensions/focus
12
- */
13
- const FocusClasses = core.Extension.create({
14
- name: 'focus',
15
- addOptions() {
16
- return {
17
- className: 'has-focus',
18
- mode: 'all',
19
- };
20
- },
21
- addProseMirrorPlugins() {
22
- return [
23
- new state.Plugin({
24
- key: new state.PluginKey('focus'),
25
- props: {
26
- decorations: ({ doc, selection }) => {
27
- const { isEditable, isFocused } = this.editor;
28
- const { anchor } = selection;
29
- const decorations = [];
30
- if (!isEditable || !isFocused) {
31
- return view.DecorationSet.create(doc, []);
32
- }
33
- // Maximum Levels
34
- let maxLevels = 0;
35
- if (this.options.mode === 'deepest') {
36
- doc.descendants((node, pos) => {
37
- if (node.isText) {
38
- return;
39
- }
40
- const isCurrent = anchor >= pos && anchor <= pos + node.nodeSize - 1;
41
- if (!isCurrent) {
42
- return false;
43
- }
44
- maxLevels += 1;
45
- });
46
- }
47
- // Loop through current
48
- let currentLevel = 0;
49
- doc.descendants((node, pos) => {
50
- if (node.isText) {
51
- return false;
52
- }
53
- const isCurrent = anchor >= pos && anchor <= pos + node.nodeSize - 1;
54
- if (!isCurrent) {
55
- return false;
56
- }
57
- currentLevel += 1;
58
- const outOfScope = (this.options.mode === 'deepest' && maxLevels - currentLevel > 0)
59
- || (this.options.mode === 'shallowest' && currentLevel > 1);
60
- if (outOfScope) {
61
- return this.options.mode === 'deepest';
62
- }
63
- decorations.push(view.Decoration.node(pos, pos + node.nodeSize, {
64
- class: this.options.className,
65
- }));
66
- });
67
- return view.DecorationSet.create(doc, decorations);
68
- },
69
- },
70
- }),
71
- ];
72
- },
9
+ /**
10
+ * This extension allows you to add a class to the focused node.
11
+ * @see https://www.tiptap.dev/api/extensions/focus
12
+ */
13
+ const FocusClasses = core.Extension.create({
14
+ name: 'focus',
15
+ addOptions() {
16
+ return {
17
+ className: 'has-focus',
18
+ mode: 'all',
19
+ };
20
+ },
21
+ addProseMirrorPlugins() {
22
+ return [
23
+ new state.Plugin({
24
+ key: new state.PluginKey('focus'),
25
+ props: {
26
+ decorations: ({ doc, selection }) => {
27
+ const { isEditable, isFocused } = this.editor;
28
+ const { anchor } = selection;
29
+ const decorations = [];
30
+ if (!isEditable || !isFocused) {
31
+ return view.DecorationSet.create(doc, []);
32
+ }
33
+ // Maximum Levels
34
+ let maxLevels = 0;
35
+ if (this.options.mode === 'deepest') {
36
+ doc.descendants((node, pos) => {
37
+ if (node.isText) {
38
+ return;
39
+ }
40
+ const isCurrent = anchor >= pos && anchor <= pos + node.nodeSize - 1;
41
+ if (!isCurrent) {
42
+ return false;
43
+ }
44
+ maxLevels += 1;
45
+ });
46
+ }
47
+ // Loop through current
48
+ let currentLevel = 0;
49
+ doc.descendants((node, pos) => {
50
+ if (node.isText) {
51
+ return false;
52
+ }
53
+ const isCurrent = anchor >= pos && anchor <= pos + node.nodeSize - 1;
54
+ if (!isCurrent) {
55
+ return false;
56
+ }
57
+ currentLevel += 1;
58
+ const outOfScope = (this.options.mode === 'deepest' && maxLevels - currentLevel > 0)
59
+ || (this.options.mode === 'shallowest' && currentLevel > 1);
60
+ if (outOfScope) {
61
+ return this.options.mode === 'deepest';
62
+ }
63
+ decorations.push(view.Decoration.node(pos, pos + node.nodeSize, {
64
+ class: this.options.className,
65
+ }));
66
+ });
67
+ return view.DecorationSet.create(doc, decorations);
68
+ },
69
+ },
70
+ }),
71
+ ];
72
+ },
73
73
  });
74
74
 
75
75
  exports.FocusClasses = FocusClasses;
76
- exports["default"] = FocusClasses;
76
+ exports.default = FocusClasses;
77
77
  //# sourceMappingURL=index.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","sources":["../src/focus.ts"],"sourcesContent":["import { Extension } from '@tiptap/core'\nimport { Plugin, PluginKey } from '@tiptap/pm/state'\nimport { Decoration, DecorationSet } from '@tiptap/pm/view'\n\nexport interface FocusOptions {\n /**\n * The class name that should be added to the focused node.\n * @default 'has-focus'\n * @example 'is-focused'\n */\n className: string\n\n /**\n * The mode by which the focused node is determined.\n * - All: All nodes are marked as focused.\n * - Deepest: Only the deepest node is marked as focused.\n * - Shallowest: Only the shallowest node is marked as focused.\n *\n * @default 'all'\n * @example 'deepest'\n * @example 'shallowest'\n */\n mode: 'all' | 'deepest' | 'shallowest'\n}\n\n/**\n * This extension allows you to add a class to the focused node.\n * @see https://www.tiptap.dev/api/extensions/focus\n */\nexport const FocusClasses = Extension.create<FocusOptions>({\n name: 'focus',\n\n addOptions() {\n return {\n className: 'has-focus',\n mode: 'all',\n }\n },\n\n addProseMirrorPlugins() {\n return [\n new Plugin({\n key: new PluginKey('focus'),\n props: {\n decorations: ({ doc, selection }) => {\n const { isEditable, isFocused } = this.editor\n const { anchor } = selection\n const decorations: Decoration[] = []\n\n if (!isEditable || !isFocused) {\n return DecorationSet.create(doc, [])\n }\n\n // Maximum Levels\n let maxLevels = 0\n\n if (this.options.mode === 'deepest') {\n doc.descendants((node, pos) => {\n if (node.isText) {\n return\n }\n\n const isCurrent = anchor >= pos && anchor <= pos + node.nodeSize - 1\n\n if (!isCurrent) {\n return false\n }\n\n maxLevels += 1\n })\n }\n\n // Loop through current\n let currentLevel = 0\n\n doc.descendants((node, pos) => {\n if (node.isText) {\n return false\n }\n\n const isCurrent = anchor >= pos && anchor <= pos + node.nodeSize - 1\n\n if (!isCurrent) {\n return false\n }\n\n currentLevel += 1\n\n const outOfScope = (this.options.mode === 'deepest' && maxLevels - currentLevel > 0)\n || (this.options.mode === 'shallowest' && currentLevel > 1)\n\n if (outOfScope) {\n return this.options.mode === 'deepest'\n }\n\n decorations.push(\n Decoration.node(pos, pos + node.nodeSize, {\n class: this.options.className,\n }),\n )\n })\n\n return DecorationSet.create(doc, decorations)\n },\n },\n }),\n ]\n },\n})\n"],"names":["Extension","Plugin","PluginKey","DecorationSet","Decoration"],"mappings":";;;;;;;;AAyBA;;;AAGG;AACU,MAAA,YAAY,GAAGA,cAAS,CAAC,MAAM,CAAe;AACzD,IAAA,IAAI,EAAE,OAAO;IAEb,UAAU,GAAA;QACR,OAAO;AACL,YAAA,SAAS,EAAE,WAAW;AACtB,YAAA,IAAI,EAAE,KAAK;SACZ,CAAA;KACF;IAED,qBAAq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,IAAI,GAAG,GAAG,IAAI,CAAC,QAAQ,GAAG,CAAC,CAAA;4BAEpE,IAAI,CAAC,SAAS,EAAE;AACd,gCAAA,OAAO,KAAK,CAAA;AACb,6BAAA;4BAED,YAAY,IAAI,CAAC,CAAA;AAEjB,4BAAA,MAAM,UAAU,GAAG,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,KAAK,SAAS,IAAI,SAAS,GAAG,YAAY,GAAG,CAAC;AAC9E,oCAAC,IAAI,CAAC,OAAO,CAAC,IAAI,KAAK,YAAY,IAAI,YAAY,GAAG,CAAC,CAAC,CAAA;AAE7D,4BAAA,IAAI,UAAU,EAAE;AACd,gCAAA,OAAO,IAAI,CAAC,OAAO,CAAC,IAAI,KAAK,SAAS,CAAA;AACvC,6BAAA;AAED,4BAAA,WAAW,CAAC,IAAI,CACdC,eAAU,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,GAAG,IAAI,CAAC,QAAQ,EAAE;AACxC,gCAAA,KAAK,EAAE,IAAI,CAAC,OAAO,CAAC,SAAS;AAC9B,6BAAA,CAAC,CACH,CAAA;AACH,yBAAC,CAAC,CAAA;wBAEF,OAAOD,kBAAa,CAAC,MAAM,CAAC,GAAG,EAAE,WAAW,CAAC,CAAA;qBAC9C;AACF,iBAAA;aACF,CAAC;SACH,CAAA;KACF;AACF,CAAA;;;;;"}
1
+ {"version":3,"file":"index.cjs","sources":["../src/focus.ts"],"sourcesContent":["import { Extension } from '@tiptap/core'\nimport { Plugin, PluginKey } from '@tiptap/pm/state'\nimport { Decoration, DecorationSet } from '@tiptap/pm/view'\n\nexport interface FocusOptions {\n /**\n * The class name that should be added to the focused node.\n * @default 'has-focus'\n * @example 'is-focused'\n */\n className: string\n\n /**\n * The mode by which the focused node is determined.\n * - All: All nodes are marked as focused.\n * - Deepest: Only the deepest node is marked as focused.\n * - Shallowest: Only the shallowest node is marked as focused.\n *\n * @default 'all'\n * @example 'deepest'\n * @example 'shallowest'\n */\n mode: 'all' | 'deepest' | 'shallowest'\n}\n\n/**\n * This extension allows you to add a class to the focused node.\n * @see https://www.tiptap.dev/api/extensions/focus\n */\nexport const FocusClasses = Extension.create<FocusOptions>({\n name: 'focus',\n\n addOptions() {\n return {\n className: 'has-focus',\n mode: 'all',\n }\n },\n\n addProseMirrorPlugins() {\n return [\n new Plugin({\n key: new PluginKey('focus'),\n props: {\n decorations: ({ doc, selection }) => {\n const { isEditable, isFocused } = this.editor\n const { anchor } = selection\n const decorations: Decoration[] = []\n\n if (!isEditable || !isFocused) {\n return DecorationSet.create(doc, [])\n }\n\n // Maximum Levels\n let maxLevels = 0\n\n if (this.options.mode === 'deepest') {\n doc.descendants((node, pos) => {\n if (node.isText) {\n return\n }\n\n const isCurrent = anchor >= pos && anchor <= pos + node.nodeSize - 1\n\n if (!isCurrent) {\n return false\n }\n\n maxLevels += 1\n })\n }\n\n // Loop through current\n let currentLevel = 0\n\n doc.descendants((node, pos) => {\n if (node.isText) {\n return false\n }\n\n const isCurrent = anchor >= pos && anchor <= pos + node.nodeSize - 1\n\n if (!isCurrent) {\n return false\n }\n\n currentLevel += 1\n\n const outOfScope = (this.options.mode === 'deepest' && maxLevels - currentLevel > 0)\n || (this.options.mode === 'shallowest' && currentLevel > 1)\n\n if (outOfScope) {\n return this.options.mode === 'deepest'\n }\n\n decorations.push(\n Decoration.node(pos, pos + node.nodeSize, {\n class: this.options.className,\n }),\n )\n })\n\n return DecorationSet.create(doc, decorations)\n },\n },\n }),\n ]\n },\n})\n"],"names":["Extension","Plugin","PluginKey","DecorationSet","Decoration"],"mappings":";;;;;;;;AAyBA;;;AAGG;AACU,MAAA,YAAY,GAAGA,cAAS,CAAC,MAAM,CAAe;AACzD,IAAA,IAAI,EAAE,OAAO;IAEb,UAAU,GAAA;QACR,OAAO;AACL,YAAA,SAAS,EAAE,WAAW;AACtB,YAAA,IAAI,EAAE,KAAK;SACZ,CAAA;KACF;IAED,qBAAqB,GAAA;QACnB,OAAO;AACL,YAAA,IAAIC,YAAM,CA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CAAC,SAAS,EAAE;AACd,gCAAA,OAAO,KAAK,CAAA;6BACb;4BAED,YAAY,IAAI,CAAC,CAAA;AAEjB,4BAAA,MAAM,UAAU,GAAG,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,KAAK,SAAS,IAAI,SAAS,GAAG,YAAY,GAAG,CAAC;AAC9E,oCAAC,IAAI,CAAC,OAAO,CAAC,IAAI,KAAK,YAAY,IAAI,YAAY,GAAG,CAAC,CAAC,CAAA;4BAE7D,IAAI,UAAU,EAAE;AACd,gCAAA,OAAO,IAAI,CAAC,OAAO,CAAC,IAAI,KAAK,SAAS,CAAA;6BACvC;AAED,4BAAA,WAAW,CAAC,IAAI,CACdC,eAAU,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,GAAG,IAAI,CAAC,QAAQ,EAAE;AACxC,gCAAA,KAAK,EAAE,IAAI,CAAC,OAAO,CAAC,SAAS;AAC9B,6BAAA,CAAC,CACH,CAAA;AACH,yBAAC,CAAC,CAAA;wBAEF,OAAOD,kBAAa,CAAC,MAAM,CAAC,GAAG,EAAE,WAAW,CAAC,CAAA;qBAC9C;AACF,iBAAA;aACF,CAAC;SACH,CAAA;KACF;AACF,CAAA;;;;;"}
package/dist/index.js CHANGED
@@ -2,70 +2,70 @@ import { Extension } from '@tiptap/core';
2
2
  import { Plugin, PluginKey } from '@tiptap/pm/state';
3
3
  import { DecorationSet, Decoration } from '@tiptap/pm/view';
4
4
 
5
- /**
6
- * This extension allows you to add a class to the focused node.
7
- * @see https://www.tiptap.dev/api/extensions/focus
8
- */
9
- const FocusClasses = Extension.create({
10
- name: 'focus',
11
- addOptions() {
12
- return {
13
- className: 'has-focus',
14
- mode: 'all',
15
- };
16
- },
17
- addProseMirrorPlugins() {
18
- return [
19
- new Plugin({
20
- key: new PluginKey('focus'),
21
- props: {
22
- decorations: ({ doc, selection }) => {
23
- const { isEditable, isFocused } = this.editor;
24
- const { anchor } = selection;
25
- const decorations = [];
26
- if (!isEditable || !isFocused) {
27
- return DecorationSet.create(doc, []);
28
- }
29
- // Maximum Levels
30
- let maxLevels = 0;
31
- if (this.options.mode === 'deepest') {
32
- doc.descendants((node, pos) => {
33
- if (node.isText) {
34
- return;
35
- }
36
- const isCurrent = anchor >= pos && anchor <= pos + node.nodeSize - 1;
37
- if (!isCurrent) {
38
- return false;
39
- }
40
- maxLevels += 1;
41
- });
42
- }
43
- // Loop through current
44
- let currentLevel = 0;
45
- doc.descendants((node, pos) => {
46
- if (node.isText) {
47
- return false;
48
- }
49
- const isCurrent = anchor >= pos && anchor <= pos + node.nodeSize - 1;
50
- if (!isCurrent) {
51
- return false;
52
- }
53
- currentLevel += 1;
54
- const outOfScope = (this.options.mode === 'deepest' && maxLevels - currentLevel > 0)
55
- || (this.options.mode === 'shallowest' && currentLevel > 1);
56
- if (outOfScope) {
57
- return this.options.mode === 'deepest';
58
- }
59
- decorations.push(Decoration.node(pos, pos + node.nodeSize, {
60
- class: this.options.className,
61
- }));
62
- });
63
- return DecorationSet.create(doc, decorations);
64
- },
65
- },
66
- }),
67
- ];
68
- },
5
+ /**
6
+ * This extension allows you to add a class to the focused node.
7
+ * @see https://www.tiptap.dev/api/extensions/focus
8
+ */
9
+ const FocusClasses = Extension.create({
10
+ name: 'focus',
11
+ addOptions() {
12
+ return {
13
+ className: 'has-focus',
14
+ mode: 'all',
15
+ };
16
+ },
17
+ addProseMirrorPlugins() {
18
+ return [
19
+ new Plugin({
20
+ key: new PluginKey('focus'),
21
+ props: {
22
+ decorations: ({ doc, selection }) => {
23
+ const { isEditable, isFocused } = this.editor;
24
+ const { anchor } = selection;
25
+ const decorations = [];
26
+ if (!isEditable || !isFocused) {
27
+ return DecorationSet.create(doc, []);
28
+ }
29
+ // Maximum Levels
30
+ let maxLevels = 0;
31
+ if (this.options.mode === 'deepest') {
32
+ doc.descendants((node, pos) => {
33
+ if (node.isText) {
34
+ return;
35
+ }
36
+ const isCurrent = anchor >= pos && anchor <= pos + node.nodeSize - 1;
37
+ if (!isCurrent) {
38
+ return false;
39
+ }
40
+ maxLevels += 1;
41
+ });
42
+ }
43
+ // Loop through current
44
+ let currentLevel = 0;
45
+ doc.descendants((node, pos) => {
46
+ if (node.isText) {
47
+ return false;
48
+ }
49
+ const isCurrent = anchor >= pos && anchor <= pos + node.nodeSize - 1;
50
+ if (!isCurrent) {
51
+ return false;
52
+ }
53
+ currentLevel += 1;
54
+ const outOfScope = (this.options.mode === 'deepest' && maxLevels - currentLevel > 0)
55
+ || (this.options.mode === 'shallowest' && currentLevel > 1);
56
+ if (outOfScope) {
57
+ return this.options.mode === 'deepest';
58
+ }
59
+ decorations.push(Decoration.node(pos, pos + node.nodeSize, {
60
+ class: this.options.className,
61
+ }));
62
+ });
63
+ return DecorationSet.create(doc, decorations);
64
+ },
65
+ },
66
+ }),
67
+ ];
68
+ },
69
69
  });
70
70
 
71
71
  export { FocusClasses, FocusClasses as default };
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":["../src/focus.ts"],"sourcesContent":["import { Extension } from '@tiptap/core'\nimport { Plugin, PluginKey } from '@tiptap/pm/state'\nimport { Decoration, DecorationSet } from '@tiptap/pm/view'\n\nexport interface FocusOptions {\n /**\n * The class name that should be added to the focused node.\n * @default 'has-focus'\n * @example 'is-focused'\n */\n className: string\n\n /**\n * The mode by which the focused node is determined.\n * - All: All nodes are marked as focused.\n * - Deepest: Only the deepest node is marked as focused.\n * - Shallowest: Only the shallowest node is marked as focused.\n *\n * @default 'all'\n * @example 'deepest'\n * @example 'shallowest'\n */\n mode: 'all' | 'deepest' | 'shallowest'\n}\n\n/**\n * This extension allows you to add a class to the focused node.\n * @see https://www.tiptap.dev/api/extensions/focus\n */\nexport const FocusClasses = Extension.create<FocusOptions>({\n name: 'focus',\n\n addOptions() {\n return {\n className: 'has-focus',\n mode: 'all',\n }\n },\n\n addProseMirrorPlugins() {\n return [\n new Plugin({\n key: new PluginKey('focus'),\n props: {\n decorations: ({ doc, selection }) => {\n const { isEditable, isFocused } = this.editor\n const { anchor } = selection\n const decorations: Decoration[] = []\n\n if (!isEditable || !isFocused) {\n return DecorationSet.create(doc, [])\n }\n\n // Maximum Levels\n let maxLevels = 0\n\n if (this.options.mode === 'deepest') {\n doc.descendants((node, pos) => {\n if (node.isText) {\n return\n }\n\n const isCurrent = anchor >= pos && anchor <= pos + node.nodeSize - 1\n\n if (!isCurrent) {\n return false\n }\n\n maxLevels += 1\n })\n }\n\n // Loop through current\n let currentLevel = 0\n\n doc.descendants((node, pos) => {\n if (node.isText) {\n return false\n }\n\n const isCurrent = anchor >= pos && anchor <= pos + node.nodeSize - 1\n\n if (!isCurrent) {\n return false\n }\n\n currentLevel += 1\n\n const outOfScope = (this.options.mode === 'deepest' && maxLevels - currentLevel > 0)\n || (this.options.mode === 'shallowest' && currentLevel > 1)\n\n if (outOfScope) {\n return this.options.mode === 'deepest'\n }\n\n decorations.push(\n Decoration.node(pos, pos + node.nodeSize, {\n class: this.options.className,\n }),\n )\n })\n\n return DecorationSet.create(doc, decorations)\n },\n },\n }),\n ]\n },\n})\n"],"names":[],"mappings":";;;;AAyBA;;;AAGG;AACU,MAAA,YAAY,GAAG,SAAS,CAAC,MAAM,CAAe;AACzD,IAAA,IAAI,EAAE,OAAO;IAEb,UAAU,GAAA;QACR,OAAO;AACL,YAAA,SAAS,EAAE,WAAW;AACtB,YAAA,IAAI,EAAE,KAAK;SACZ,CAAA;KACF;IAED,qBAAqB,GAAA;QACnB,OAAO;AACL,YAAA,IAAI,MAAM,CAAC;AACT,gBAAA,GAAG,EAAE,IAAI,SAAS,CAAC,OAAO,CAAC;AAC3B,gBAAA,KAAK,EAAE;oBACL,WAAW,EAAE,CAAC,EAAE,GAAG,EAAE,SAAS,EAAE,KAAI;wBAClC,MAAM,EAAE,UAAU,EAAE,SAAS,EAAE,GAAG,IAAI,CAAC,MAAM,CAAA;AAC7C,wBAAA,MAAM,EAAE,MAAM,EAAE,GAAG,SAAS,CAAA;wBAC5B,MAAM,WAAW,GA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AAG,CAAC,CAAC,CAAA;AAE7D,4BAAA,IAAI,UAAU,EAAE;AACd,gCAAA,OAAO,IAAI,CAAC,OAAO,CAAC,IAAI,KAAK,SAAS,CAAA;AACvC,6BAAA;AAED,4BAAA,WAAW,CAAC,IAAI,CACd,UAAU,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,GAAG,IAAI,CAAC,QAAQ,EAAE;AACxC,gCAAA,KAAK,EAAE,IAAI,CAAC,OAAO,CAAC,SAAS;AAC9B,6BAAA,CAAC,CACH,CAAA;AACH,yBAAC,CAAC,CAAA;wBAEF,OAAO,aAAa,CAAC,MAAM,CAAC,GAAG,EAAE,WAAW,CAAC,CAAA;qBAC9C;AACF,iBAAA;aACF,CAAC;SACH,CAAA;KACF;AACF,CAAA;;;;"}
1
+ {"version":3,"file":"index.js","sources":["../src/focus.ts"],"sourcesContent":["import { Extension } from '@tiptap/core'\nimport { Plugin, PluginKey } from '@tiptap/pm/state'\nimport { Decoration, DecorationSet } from '@tiptap/pm/view'\n\nexport interface FocusOptions {\n /**\n * The class name that should be added to the focused node.\n * @default 'has-focus'\n * @example 'is-focused'\n */\n className: string\n\n /**\n * The mode by which the focused node is determined.\n * - All: All nodes are marked as focused.\n * - Deepest: Only the deepest node is marked as focused.\n * - Shallowest: Only the shallowest node is marked as focused.\n *\n * @default 'all'\n * @example 'deepest'\n * @example 'shallowest'\n */\n mode: 'all' | 'deepest' | 'shallowest'\n}\n\n/**\n * This extension allows you to add a class to the focused node.\n * @see https://www.tiptap.dev/api/extensions/focus\n */\nexport const FocusClasses = Extension.create<FocusOptions>({\n name: 'focus',\n\n addOptions() {\n return {\n className: 'has-focus',\n mode: 'all',\n }\n },\n\n addProseMirrorPlugins() {\n return [\n new Plugin({\n key: new PluginKey('focus'),\n props: {\n decorations: ({ doc, selection }) => {\n const { isEditable, isFocused } = this.editor\n const { anchor } = selection\n const decorations: Decoration[] = []\n\n if (!isEditable || !isFocused) {\n return DecorationSet.create(doc, [])\n }\n\n // Maximum Levels\n let maxLevels = 0\n\n if (this.options.mode === 'deepest') {\n doc.descendants((node, pos) => {\n if (node.isText) {\n return\n }\n\n const isCurrent = anchor >= pos && anchor <= pos + node.nodeSize - 1\n\n if (!isCurrent) {\n return false\n }\n\n maxLevels += 1\n })\n }\n\n // Loop through current\n let currentLevel = 0\n\n doc.descendants((node, pos) => {\n if (node.isText) {\n return false\n }\n\n const isCurrent = anchor >= pos && anchor <= pos + node.nodeSize - 1\n\n if (!isCurrent) {\n return false\n }\n\n currentLevel += 1\n\n const outOfScope = (this.options.mode === 'deepest' && maxLevels - currentLevel > 0)\n || (this.options.mode === 'shallowest' && currentLevel > 1)\n\n if (outOfScope) {\n return this.options.mode === 'deepest'\n }\n\n decorations.push(\n Decoration.node(pos, pos + node.nodeSize, {\n class: this.options.className,\n }),\n )\n })\n\n return DecorationSet.create(doc, decorations)\n },\n },\n }),\n ]\n },\n})\n"],"names":[],"mappings":";;;;AAyBA;;;AAGG;AACU,MAAA,YAAY,GAAG,SAAS,CAAC,MAAM,CAAe;AACzD,IAAA,IAAI,EAAE,OAAO;IAEb,UAAU,GAAA;QACR,OAAO;AACL,YAAA,SAAS,EAAE,WAAW;AACtB,YAAA,IAAI,EAAE,KAAK;SACZ,CAAA;KACF;IAED,qBAAqB,GAAA;QACnB,OAAO;AACL,YAAA,IAAI,MAAM,CAAC;AACT,gBAAA,GAAG,EAAE,IAAI,SAAS,CAAC,OAAO,CAAC;AAC3B,gBAAA,KAAK,EAAE;oBACL,WAAW,EAAE,CAAC,EAAE,GAAG,EAAE,SAAS,EAAE,KAAI;wBAClC,MAAM,EAAE,UAAU,EAAE,SAAS,EAAE,GAAG,IAAI,CAAC,MAAM,CAAA;AAC7C,wBAAA,MAAM,EAAE,MAAM,EAAE,GAAG,SAAS,CAAA;wBAC5B,MAAM,WAAW,GAAiB,EAAE,CAAA;AAEpC,wBAAA,IAAI,CAAC,UAAU,IAAI,CAAC,SAAS,EAAE;4BAC7B,OAAO,aAAa,CAA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4BAAA,WAAW,CAAC,IAAI,CACd,UAAU,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,GAAG,IAAI,CAAC,QAAQ,EAAE;AACxC,gCAAA,KAAK,EAAE,IAAI,CAAC,OAAO,CAAC,SAAS;AAC9B,6BAAA,CAAC,CACH,CAAA;AACH,yBAAC,CAAC,CAAA;wBAEF,OAAO,aAAa,CAAC,MAAM,CAAC,GAAG,EAAE,WAAW,CAAC,CAAA;qBAC9C;AACF,iBAAA;aACF,CAAC;SACH,CAAA;KACF;AACF,CAAA;;;;"}
package/dist/index.umd.js CHANGED
@@ -4,74 +4,74 @@
4
4
  (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global["@tiptap/extension-focus"] = {}, global.core, global.state, global.view));
5
5
  })(this, (function (exports, core, state, view) { 'use strict';
6
6
 
7
- /**
8
- * This extension allows you to add a class to the focused node.
9
- * @see https://www.tiptap.dev/api/extensions/focus
10
- */
11
- const FocusClasses = core.Extension.create({
12
- name: 'focus',
13
- addOptions() {
14
- return {
15
- className: 'has-focus',
16
- mode: 'all',
17
- };
18
- },
19
- addProseMirrorPlugins() {
20
- return [
21
- new state.Plugin({
22
- key: new state.PluginKey('focus'),
23
- props: {
24
- decorations: ({ doc, selection }) => {
25
- const { isEditable, isFocused } = this.editor;
26
- const { anchor } = selection;
27
- const decorations = [];
28
- if (!isEditable || !isFocused) {
29
- return view.DecorationSet.create(doc, []);
30
- }
31
- // Maximum Levels
32
- let maxLevels = 0;
33
- if (this.options.mode === 'deepest') {
34
- doc.descendants((node, pos) => {
35
- if (node.isText) {
36
- return;
37
- }
38
- const isCurrent = anchor >= pos && anchor <= pos + node.nodeSize - 1;
39
- if (!isCurrent) {
40
- return false;
41
- }
42
- maxLevels += 1;
43
- });
44
- }
45
- // Loop through current
46
- let currentLevel = 0;
47
- doc.descendants((node, pos) => {
48
- if (node.isText) {
49
- return false;
50
- }
51
- const isCurrent = anchor >= pos && anchor <= pos + node.nodeSize - 1;
52
- if (!isCurrent) {
53
- return false;
54
- }
55
- currentLevel += 1;
56
- const outOfScope = (this.options.mode === 'deepest' && maxLevels - currentLevel > 0)
57
- || (this.options.mode === 'shallowest' && currentLevel > 1);
58
- if (outOfScope) {
59
- return this.options.mode === 'deepest';
60
- }
61
- decorations.push(view.Decoration.node(pos, pos + node.nodeSize, {
62
- class: this.options.className,
63
- }));
64
- });
65
- return view.DecorationSet.create(doc, decorations);
66
- },
67
- },
68
- }),
69
- ];
70
- },
7
+ /**
8
+ * This extension allows you to add a class to the focused node.
9
+ * @see https://www.tiptap.dev/api/extensions/focus
10
+ */
11
+ const FocusClasses = core.Extension.create({
12
+ name: 'focus',
13
+ addOptions() {
14
+ return {
15
+ className: 'has-focus',
16
+ mode: 'all',
17
+ };
18
+ },
19
+ addProseMirrorPlugins() {
20
+ return [
21
+ new state.Plugin({
22
+ key: new state.PluginKey('focus'),
23
+ props: {
24
+ decorations: ({ doc, selection }) => {
25
+ const { isEditable, isFocused } = this.editor;
26
+ const { anchor } = selection;
27
+ const decorations = [];
28
+ if (!isEditable || !isFocused) {
29
+ return view.DecorationSet.create(doc, []);
30
+ }
31
+ // Maximum Levels
32
+ let maxLevels = 0;
33
+ if (this.options.mode === 'deepest') {
34
+ doc.descendants((node, pos) => {
35
+ if (node.isText) {
36
+ return;
37
+ }
38
+ const isCurrent = anchor >= pos && anchor <= pos + node.nodeSize - 1;
39
+ if (!isCurrent) {
40
+ return false;
41
+ }
42
+ maxLevels += 1;
43
+ });
44
+ }
45
+ // Loop through current
46
+ let currentLevel = 0;
47
+ doc.descendants((node, pos) => {
48
+ if (node.isText) {
49
+ return false;
50
+ }
51
+ const isCurrent = anchor >= pos && anchor <= pos + node.nodeSize - 1;
52
+ if (!isCurrent) {
53
+ return false;
54
+ }
55
+ currentLevel += 1;
56
+ const outOfScope = (this.options.mode === 'deepest' && maxLevels - currentLevel > 0)
57
+ || (this.options.mode === 'shallowest' && currentLevel > 1);
58
+ if (outOfScope) {
59
+ return this.options.mode === 'deepest';
60
+ }
61
+ decorations.push(view.Decoration.node(pos, pos + node.nodeSize, {
62
+ class: this.options.className,
63
+ }));
64
+ });
65
+ return view.DecorationSet.create(doc, decorations);
66
+ },
67
+ },
68
+ }),
69
+ ];
70
+ },
71
71
  });
72
72
 
73
73
  exports.FocusClasses = FocusClasses;
74
- exports["default"] = FocusClasses;
74
+ exports.default = FocusClasses;
75
75
 
76
76
  Object.defineProperty(exports, '__esModule', { value: true });
77
77
 
@@ -1 +1 @@
1
- {"version":3,"file":"index.umd.js","sources":["../src/focus.ts"],"sourcesContent":["import { Extension } from '@tiptap/core'\nimport { Plugin, PluginKey } from '@tiptap/pm/state'\nimport { Decoration, DecorationSet } from '@tiptap/pm/view'\n\nexport interface FocusOptions {\n /**\n * The class name that should be added to the focused node.\n * @default 'has-focus'\n * @example 'is-focused'\n */\n className: string\n\n /**\n * The mode by which the focused node is determined.\n * - All: All nodes are marked as focused.\n * - Deepest: Only the deepest node is marked as focused.\n * - Shallowest: Only the shallowest node is marked as focused.\n *\n * @default 'all'\n * @example 'deepest'\n * @example 'shallowest'\n */\n mode: 'all' | 'deepest' | 'shallowest'\n}\n\n/**\n * This extension allows you to add a class to the focused node.\n * @see https://www.tiptap.dev/api/extensions/focus\n */\nexport const FocusClasses = Extension.create<FocusOptions>({\n name: 'focus',\n\n addOptions() {\n return {\n className: 'has-focus',\n mode: 'all',\n }\n },\n\n addProseMirrorPlugins() {\n return [\n new Plugin({\n key: new PluginKey('focus'),\n props: {\n decorations: ({ doc, selection }) => {\n const { isEditable, isFocused } = this.editor\n const { anchor } = selection\n const decorations: Decoration[] = []\n\n if (!isEditable || !isFocused) {\n return DecorationSet.create(doc, [])\n }\n\n // Maximum Levels\n let maxLevels = 0\n\n if (this.options.mode === 'deepest') {\n doc.descendants((node, pos) => {\n if (node.isText) {\n return\n }\n\n const isCurrent = anchor >= pos && anchor <= pos + node.nodeSize - 1\n\n if (!isCurrent) {\n return false\n }\n\n maxLevels += 1\n })\n }\n\n // Loop through current\n let currentLevel = 0\n\n doc.descendants((node, pos) => {\n if (node.isText) {\n return false\n }\n\n const isCurrent = anchor >= pos && anchor <= pos + node.nodeSize - 1\n\n if (!isCurrent) {\n return false\n }\n\n currentLevel += 1\n\n const outOfScope = (this.options.mode === 'deepest' && maxLevels - currentLevel > 0)\n || (this.options.mode === 'shallowest' && currentLevel > 1)\n\n if (outOfScope) {\n return this.options.mode === 'deepest'\n }\n\n decorations.push(\n Decoration.node(pos, pos + node.nodeSize, {\n class: this.options.className,\n }),\n )\n })\n\n return DecorationSet.create(doc, decorations)\n },\n },\n }),\n ]\n },\n})\n"],"names":["Extension","Plugin","PluginKey","DecorationSet","Decoration"],"mappings":";;;;;;EAyBA;;;EAGG;AACU,QAAA,YAAY,GAAGA,cAAS,CAAC,MAAM,CAAe;EACzD,IAAA,IAAI,EAAE,OAAO;MAEb,UAAU,GAAA;UACR,OAAO;EACL,YAAA,SAAS,EAAE,WAAW;EACtB,YAAA,IAAI,EAAE,KAAK;WACZ,CAAA;OACF;MAED,qBAAqB,GAAA;UACnB,OAAO;EACL,YAAA,IAAIC,YAAM,CAAC;EACT,gBAAA,GAAG,EAAE,IAAIC,eAAS,CAAC,OAAO,CAAC;EAC3B,gBAAA,KAAK,EAAE;sBACL,WAAW,EAAE,CAAC,EAAE,GAAG,EAAE,SAAS,EAAE,KAAI;0BAClC,MAAM,EAAE,UAAU,EAAE,SAAS,EAAE,GAAG,IAAI,CAAC,MAAM,CAAA;EAC7C,wBAAA,MAAM,EAAE,MAAM,EAAE,GAAG,SAAS,CAAA;0BAC5B,MAAM,WAAW,GAAiB,EAAE,CAAA;EAEpC,wBAAA,IAAI,CAAC,UAAU,IAAI,CAAC,SAAS,EAAE;8BAC7B,OAAOC,kBAAa,CAAC,MAAM,CAAC,GAAG,EAAE,EAAE,CAAC,CAAA;EACrC,yBAAA;;0BAGD,IAAI,SAAS,GAAG,CAAC,CAAA;EAEjB,wBAAA,IAAI,IAAI,CAAC,OAAO,CAA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,EAAE;EACxC,gCAAA,KAAK,EAAE,IAAI,CAAC,OAAO,CAAC,SAAS;EAC9B,6BAAA,CAAC,CACH,CAAA;EACH,yBAAC,CAAC,CAAA;0BAEF,OAAOD,kBAAa,CAAC,MAAM,CAAC,GAAG,EAAE,WAAW,CAAC,CAAA;uBAC9C;EACF,iBAAA;eACF,CAAC;WACH,CAAA;OACF;EACF,CAAA;;;;;;;;;;;"}
1
+ {"version":3,"file":"index.umd.js","sources":["../src/focus.ts"],"sourcesContent":["import { Extension } from '@tiptap/core'\nimport { Plugin, PluginKey } from '@tiptap/pm/state'\nimport { Decoration, DecorationSet } from '@tiptap/pm/view'\n\nexport interface FocusOptions {\n /**\n * The class name that should be added to the focused node.\n * @default 'has-focus'\n * @example 'is-focused'\n */\n className: string\n\n /**\n * The mode by which the focused node is determined.\n * - All: All nodes are marked as focused.\n * - Deepest: Only the deepest node is marked as focused.\n * - Shallowest: Only the shallowest node is marked as focused.\n *\n * @default 'all'\n * @example 'deepest'\n * @example 'shallowest'\n */\n mode: 'all' | 'deepest' | 'shallowest'\n}\n\n/**\n * This extension allows you to add a class to the focused node.\n * @see https://www.tiptap.dev/api/extensions/focus\n */\nexport const FocusClasses = Extension.create<FocusOptions>({\n name: 'focus',\n\n addOptions() {\n return {\n className: 'has-focus',\n mode: 'all',\n }\n },\n\n addProseMirrorPlugins() {\n return [\n new Plugin({\n key: new PluginKey('focus'),\n props: {\n decorations: ({ doc, selection }) => {\n const { isEditable, isFocused } = this.editor\n const { anchor } = selection\n const decorations: Decoration[] = []\n\n if (!isEditable || !isFocused) {\n return DecorationSet.create(doc, [])\n }\n\n // Maximum Levels\n let maxLevels = 0\n\n if (this.options.mode === 'deepest') {\n doc.descendants((node, pos) => {\n if (node.isText) {\n return\n }\n\n const isCurrent = anchor >= pos && anchor <= pos + node.nodeSize - 1\n\n if (!isCurrent) {\n return false\n }\n\n maxLevels += 1\n })\n }\n\n // Loop through current\n let currentLevel = 0\n\n doc.descendants((node, pos) => {\n if (node.isText) {\n return false\n }\n\n const isCurrent = anchor >= pos && anchor <= pos + node.nodeSize - 1\n\n if (!isCurrent) {\n return false\n }\n\n currentLevel += 1\n\n const outOfScope = (this.options.mode === 'deepest' && maxLevels - currentLevel > 0)\n || (this.options.mode === 'shallowest' && currentLevel > 1)\n\n if (outOfScope) {\n return this.options.mode === 'deepest'\n }\n\n decorations.push(\n Decoration.node(pos, pos + node.nodeSize, {\n class: this.options.className,\n }),\n )\n })\n\n return DecorationSet.create(doc, decorations)\n },\n },\n }),\n ]\n },\n})\n"],"names":["Extension","Plugin","PluginKey","DecorationSet","Decoration"],"mappings":";;;;;;EAyBA;;;EAGG;AACU,QAAA,YAAY,GAAGA,cAAS,CAAC,MAAM,CAAe;EACzD,IAAA,IAAI,EAAE,OAAO;MAEb,UAAU,GAAA;UACR,OAAO;EACL,YAAA,SAAS,EAAE,WAAW;EACtB,YAAA,IAAI,EAAE,KAAK;WACZ,CAAA;OACF;MAED,qBAAqB,GAAA;UACnB,OAAO;EACL,YAAA,IAAIC,YAAM,CAAC;EACT,gBAAA,GAAG,EAAE,IAAIC,eAAS,CAAC,OAAO,CAAC;EAC3B,gBAAA,KAAK,EAAE;sBACL,WAAW,EAAE,CAAC,EAAE,GAAG,EAAE,SAAS,EAAE,KAAI;0BAClC,MAAM,EAAE,UAAU,EAAE,SAAS,EAAE,GAAG,IAAI,CAAC,MAAM,CAAA;EAC7C,wBAAA,MAAM,EAAE,MAAM,EAAE,GAAG,SAAS,CAAA;0BAC5B,MAAM,WAAW,GAAiB,EAAE,CAAA;EAEpC,wBAAA,IAAI,CAAC,UAAU,IAAI,CAAC,SAAS,EAAE;8BAC7B,OAAOC,kBAAa,CAAC,MAAM,CAAC,GAAG,EAAE,EAAE,CAAC,CAAA;2BACrC;;0BAGD,IAAI,SAAS,GAAG,CAAC,CAAA;0BAEjB,IAAI,IAAI,CAAC,OAAO,CAAC,IAAI,KAAK,SAAS,EAAE;8BACnC,GAAG,CAAC,WAAW,C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,CACH,CAAA;EACH,yBAAC,CAAC,CAAA;0BAEF,OAAOD,kBAAa,CAAC,MAAM,CAAC,GAAG,EAAE,WAAW,CAAC,CAAA;uBAC9C;EACF,iBAAA;eACF,CAAC;WACH,CAAA;OACF;EACF,CAAA;;;;;;;;;;;"}
@@ -0,0 +1,20 @@
1
+ import { EditorState, Transaction } from '@tiptap/pm/state';
2
+ import { Editor } from './Editor.js';
3
+ import { AnyCommands, CanCommands, ChainedCommands, CommandProps, SingleCommands } from './types.js';
4
+ export declare class CommandManager {
5
+ editor: Editor;
6
+ rawCommands: AnyCommands;
7
+ customState?: EditorState;
8
+ constructor(props: {
9
+ editor: Editor;
10
+ state?: EditorState;
11
+ });
12
+ get hasCustomState(): boolean;
13
+ get state(): EditorState;
14
+ get commands(): SingleCommands;
15
+ get chain(): () => ChainedCommands;
16
+ get can(): () => CanCommands;
17
+ createChain(startTr?: Transaction, shouldDispatch?: boolean): ChainedCommands;
18
+ createCan(startTr?: Transaction): CanCommands;
19
+ buildProps(tr: Transaction, shouldDispatch?: boolean): CommandProps;
20
+ }