draftjs_html 0.13.0 → 0.14.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 +4 -4
- data/lib/draftjs_html/draftjs/raw_builder.rb +65 -0
- data/lib/draftjs_html/draftjs.rb +1 -0
- data/lib/draftjs_html/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b708c9dfd4a3d4b6cdf22de377edd9a271e6eb527c70648d11337c1d090613e5
|
4
|
+
data.tar.gz: e472de0d6b79d5b7cf7380d6ed89f8c85aedf79d30d329a42550b1cf94eb7dd7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6511068eab5eb7c99f7815c85bb6b40bd998f80cee7ed8b41a418d9295bf467f4ed4a1de47049342aa27ec02e0e29207031f1f3cfa9e853da13acc79d98e21b1
|
7
|
+
data.tar.gz: bd939bb048b11692d520cfef3202b7e9d7106f36cac901cd4171f82991ccf24981b8cc610f0e61626231c463c84202d5dbb80b26221cecf1f68b9f48b435b32a
|
@@ -0,0 +1,65 @@
|
|
1
|
+
require 'securerandom'
|
2
|
+
|
3
|
+
module DraftjsHtml
|
4
|
+
module Draftjs
|
5
|
+
class RawBuilder
|
6
|
+
def self.build(&block)
|
7
|
+
instance = new
|
8
|
+
instance.instance_eval(&block)
|
9
|
+
instance.to_h
|
10
|
+
end
|
11
|
+
|
12
|
+
def initialize
|
13
|
+
@blocks = []
|
14
|
+
@entity_map = {}
|
15
|
+
end
|
16
|
+
|
17
|
+
def text_block(text)
|
18
|
+
typed_block('unstyled', text)
|
19
|
+
end
|
20
|
+
|
21
|
+
def typed_block(type, text, depth: 0)
|
22
|
+
@blocks << { 'key' => SecureRandom.urlsafe_base64(10), 'text' => text, 'type' => type, 'depth' => depth }
|
23
|
+
end
|
24
|
+
|
25
|
+
def inline_style(style_name, range)
|
26
|
+
(@blocks.last['inlineStyleRanges'] ||= []) << { 'style' => style_name, 'offset' => range.begin, 'length' => range.size }
|
27
|
+
end
|
28
|
+
|
29
|
+
def entity_range(key, range)
|
30
|
+
(@blocks.last['entityRanges'] ||= []) << { 'key' => key, 'offset' => range.begin, 'length' => range.size }
|
31
|
+
end
|
32
|
+
|
33
|
+
def apply_entity(type, range, data: {}, mutability: 'IMMUTABLE', key: SecureRandom.uuid)
|
34
|
+
@entity_map[key] = {
|
35
|
+
'type' => type,
|
36
|
+
'mutability' => mutability,
|
37
|
+
'data' => deep_stringify_keys(data),
|
38
|
+
}
|
39
|
+
|
40
|
+
entity_range(key, range)
|
41
|
+
end
|
42
|
+
|
43
|
+
def to_h
|
44
|
+
{
|
45
|
+
'blocks' => @blocks,
|
46
|
+
'entityMap' => @entity_map,
|
47
|
+
}
|
48
|
+
end
|
49
|
+
|
50
|
+
private
|
51
|
+
|
52
|
+
def deep_stringify_keys(object)
|
53
|
+
case object
|
54
|
+
when Hash
|
55
|
+
object.each_with_object({}) do |(key, value), result|
|
56
|
+
result[key.to_s] = deep_stringify_keys(value)
|
57
|
+
end
|
58
|
+
when Array then object.map { |e| deep_stringify_keys(e) }
|
59
|
+
else
|
60
|
+
object
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
data/lib/draftjs_html/draftjs.rb
CHANGED
data/lib/draftjs_html/version.rb
CHANGED
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.
|
4
|
+
version: 0.14.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: 2022-10-
|
11
|
+
date: 2022-10-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: nokogiri
|
@@ -64,6 +64,7 @@ files:
|
|
64
64
|
- lib/draftjs_html/draftjs/content.rb
|
65
65
|
- lib/draftjs_html/draftjs/entity.rb
|
66
66
|
- lib/draftjs_html/draftjs/entity_map.rb
|
67
|
+
- lib/draftjs_html/draftjs/raw_builder.rb
|
67
68
|
- lib/draftjs_html/draftjs/to_raw.rb
|
68
69
|
- lib/draftjs_html/html_defaults.rb
|
69
70
|
- lib/draftjs_html/html_depth.rb
|