draftjs_html 0.27.0 → 0.28.0

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9f3c2bb461481d4f338da121e4d8205369f6cba27ac5cf21bec8708de6fa738d
4
- data.tar.gz: ea42f19e6600c5a046ef8a04c5ac0a1bc3542460ecc9811a4cc5b61b32d1b6c4
3
+ metadata.gz: ee7df9bd0f6a54994b17925c487f2c824ec538e773abe2c56b5591e5cd846573
4
+ data.tar.gz: c874e8b188f77d2ffd7ade661ff5e61cea5c136b0d89e3a9bf022a5e87de142f
5
5
  SHA512:
6
- metadata.gz: 22d138ff6e137995205b14e9af4d66beb484e4509f87c5575fd870878e3fdf0212647c9312816e23014a520e5b9f4b2f6a4cd737604bde54bdc94af5e805b94c
7
- data.tar.gz: 312deef7985e5ad14740f595b03d5d758c19613283b01a7a710ab102cc40450fe0b07ba25949f9470aa5fbf16e0db5b9de232a98c5cb6011497ba204ed5e33b6
6
+ metadata.gz: 4f4dc0f13111d6a0424d24620810bb5ac928bade2a1ba29fee46baa182e91a67430909920b3c9be69f4836299fbc44953f4db8c20a4948431e33bfc496def6a0
7
+ data.tar.gz: 852986e0ce26c74d377bd8c202de3a898510b5ef5b20f594b65e035c3b25258a11375a4aed562aa62cbfcdd42388125316d9bef82cbf8ff670ba442a766ff926
@@ -19,7 +19,7 @@ module DraftjsHtml
19
19
  return unless nesting_root_changed?(block) || depth_changed?(block)
20
20
 
21
21
  if deepening?(block)
22
- deepen(block)
22
+ deepen(block, desired_depth_change: block.depth - @current_depth)
23
23
  elsif rising?(block) && still_nested?(block)
24
24
  rise(times: @current_depth - block.depth)
25
25
  elsif rising?(block)
@@ -36,11 +36,17 @@ module DraftjsHtml
36
36
 
37
37
  private
38
38
 
39
- def deepen(block)
40
- tagname = BLOCK_TYPE_TO_HTML_WRAPPER[block.type]
41
- @previous_parents << @body.parent
42
- @nesting_roots << tagname
43
- @body.parent = @body.parent.last_element_child
39
+ def deepen(block, desired_depth_change: 0)
40
+ if inside_valid_nesting_root?
41
+ set_previous_li_as_parent(block)
42
+ else
43
+ create_valid_nesting_root(block)
44
+ end
45
+
46
+ (desired_depth_change - 1).times do
47
+ create_valid_nesting_root(block)
48
+ end
49
+
44
50
  push_parent(block)
45
51
  end
46
52
 
@@ -91,5 +97,27 @@ module DraftjsHtml
91
97
  def deepening?(block)
92
98
  @current_depth < block.depth
93
99
  end
100
+
101
+ def create_valid_nesting_root(block)
102
+ parent_tagname = BLOCK_TYPE_TO_HTML_WRAPPER[block.type]
103
+ node = create_child(parent_tagname)
104
+ @previous_parents << node
105
+ @nesting_roots << parent_tagname
106
+ @body.parent = node
107
+
108
+ list_item = create_child('li')
109
+ @body.parent = list_item
110
+ end
111
+
112
+ def set_previous_li_as_parent(block)
113
+ tagname = BLOCK_TYPE_TO_HTML_WRAPPER[block.type]
114
+ @previous_parents << @body.parent
115
+ @nesting_roots << tagname
116
+ @body.parent = @body.parent.last_element_child
117
+ end
118
+
119
+ def inside_valid_nesting_root?
120
+ BLOCK_TYPE_TO_HTML_WRAPPER.values.include?(@body.parent.name)
121
+ end
94
122
  end
95
123
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module DraftjsHtml
4
- VERSION = "0.27.0"
4
+ VERSION = "0.28.0"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: draftjs_html
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.27.0
4
+ version: 0.28.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - TJ Taylor
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-01-10 00:00:00.000000000 Z
11
+ date: 2023-02-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: nokogiri