@limetech/lime-elements 37.53.4 → 37.53.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,3 +1,11 @@
1
+ ## [37.53.5](https://github.com/Lundalogik/lime-elements/compare/v37.53.4...v37.53.5) (2024-07-04)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+
7
+ * **editor menu:** allow block quotes to be toggled ([169e520](https://github.com/Lundalogik/lime-elements/commit/169e52087190c7c654715f589c1c028563dfdaec))
8
+
1
9
  ## [37.53.4](https://github.com/Lundalogik/lime-elements/compare/v37.53.3...v37.53.4) (2024-07-04)
2
10
 
3
11
 
@@ -16655,25 +16655,40 @@ const getAttributes = (markName, link) => {
16655
16655
  const isExternalLink = (url) => {
16656
16656
  return !url.startsWith(window.location.origin);
16657
16657
  };
16658
- const toggleBlockType = (schema, type, attrs = {}, wrap = false) => {
16659
- const blockType = schema.nodes[type];
16658
+ /**
16659
+ * Toggles or wraps a node type based on the selection and parameters.
16660
+ * - Toggles to paragraph if the selection is of the specified type.
16661
+ * - Lifts content out if already wrapped in the specified type.
16662
+ * - Wraps or sets the selection to the specified type based on `shouldWrap`.
16663
+ * @param schema - ProseMirror schema.
16664
+ * @param type - Block type name to toggle.
16665
+ * @param attrs - Attributes for the block type.
16666
+ * @param shouldWrap - Wrap selection if true, otherwise directly set the block type for the selection.
16667
+ * @returns A command based on selection and action needed.
16668
+ */
16669
+ const toggleNodeType = (schema, type, attrs = {}, shouldWrap = false) => {
16670
+ const nodeType = schema.nodes[type];
16660
16671
  const paragraphType = schema.nodes.paragraph;
16661
16672
  return (state, dispatch) => {
16662
- const { $from, to } = state.selection;
16673
+ const { $from, $to } = state.selection;
16674
+ const hasActiveWrap = $from.node($from.depth - 1).type === nodeType;
16663
16675
  if (state.selection instanceof TextSelection &&
16664
- $from.sameParent($from.doc.resolve(to))) {
16665
- if ($from.parent.type === blockType) {
16676
+ $from.sameParent($from.doc.resolve($to.pos))) {
16677
+ if ($from.parent.type === nodeType) {
16666
16678
  if (dispatch) {
16667
- dispatch(state.tr.setBlockType($from.pos, to, paragraphType));
16679
+ dispatch(state.tr.setBlockType($from.pos, $to.pos, paragraphType));
16668
16680
  }
16669
16681
  return true;
16670
16682
  }
16671
16683
  else {
16672
- if (wrap) {
16673
- return wrapIn(blockType, attrs)(state, dispatch);
16684
+ if (hasActiveWrap) {
16685
+ return lift(state, dispatch);
16686
+ }
16687
+ if (shouldWrap) {
16688
+ return wrapIn(nodeType, attrs)(state, dispatch);
16674
16689
  }
16675
16690
  else {
16676
- return setBlockType(blockType, attrs)(state, dispatch);
16691
+ return setBlockType(nodeType, attrs)(state, dispatch);
16677
16692
  }
16678
16693
  }
16679
16694
  }
@@ -16696,12 +16711,12 @@ const createSetNodeTypeCommand = (schema, nodeType, level) => {
16696
16711
  }
16697
16712
  let command;
16698
16713
  if (nodeType === LevelMapping.Heading && level) {
16699
- command = toggleBlockType(schema, LevelMapping.Heading, {
16714
+ command = toggleNodeType(schema, LevelMapping.Heading, {
16700
16715
  level: level,
16701
16716
  });
16702
16717
  }
16703
16718
  else if (nodeType === EditorMenuTypes.CodeBlock) {
16704
- command = toggleBlockType(schema, EditorMenuTypes.CodeBlock);
16719
+ command = toggleNodeType(schema, EditorMenuTypes.CodeBlock);
16705
16720
  }
16706
16721
  else {
16707
16722
  command = setBlockType(type);
@@ -16716,7 +16731,7 @@ const createWrapInCommand = (schema, nodeType) => {
16716
16731
  }
16717
16732
  let command;
16718
16733
  if (nodeType === EditorMenuTypes.Blockquote) {
16719
- command = toggleBlockType(schema, EditorMenuTypes.Blockquote, {}, true);
16734
+ command = toggleNodeType(schema, EditorMenuTypes.Blockquote, {}, true);
16720
16735
  }
16721
16736
  else {
16722
16737
  command = wrapIn(type);