draftjs_html 0.27.0 → 0.29.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9f3c2bb461481d4f338da121e4d8205369f6cba27ac5cf21bec8708de6fa738d
4
- data.tar.gz: ea42f19e6600c5a046ef8a04c5ac0a1bc3542460ecc9811a4cc5b61b32d1b6c4
3
+ metadata.gz: afb24dc172740e504b480688893e7501968871dc219e021b5d70885961b0fcde
4
+ data.tar.gz: ada9a89937ece511ff1c617e4e5e9754fd61be0980683b6eebe1b7a6afc64eb6
5
5
  SHA512:
6
- metadata.gz: 22d138ff6e137995205b14e9af4d66beb484e4509f87c5575fd870878e3fdf0212647c9312816e23014a520e5b9f4b2f6a4cd737604bde54bdc94af5e805b94c
7
- data.tar.gz: 312deef7985e5ad14740f595b03d5d758c19613283b01a7a710ab102cc40450fe0b07ba25949f9470aa5fbf16e0db5b9de232a98c5cb6011497ba204ed5e33b6
6
+ metadata.gz: ade3fb1e8447b4f275a8ba717d41f25c43f2e5f63051ca65abbb0e540a43363add8fe67baea81976d2d03ccc350e7e1b3da43fa978fb1a69e14c540c5b3872b2
7
+ data.tar.gz: 618448a98c1f9309d3a411aa180f95fc109fedc70e0f389b8c4673f06f8cfba43f19413528ebd1c6af291706974edaf4200debc52a0d6e7465169a7ac98343f4
@@ -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
 
@@ -61,7 +67,7 @@ module DraftjsHtml
61
67
  end
62
68
 
63
69
  def pop_parent
64
- @body.parent = @previous_parents.pop
70
+ @body.parent = @previous_parents.pop unless @previous_parents.empty?
65
71
  end
66
72
 
67
73
  def create_child(tagname)
@@ -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.29.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.29.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-05-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: nokogiri