@takeshape/util 8.16.0 → 8.20.2

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/es/common.js CHANGED
@@ -11,4 +11,7 @@ export * from './predicate';
11
11
  export * from './tracing';
12
12
  export * from './merge';
13
13
  export * from './map';
14
- export * from './visit';
14
+ export * from './visit';
15
+ export * from './draftjs';
16
+ export * from './templates';
17
+ export * from './highlight-code';
@@ -0,0 +1,148 @@
1
+ /* eslint-disable camelcase */
2
+
3
+ /*
4
+ * The intention is to move all this to the client package in the end, but right now it's here
5
+ * to be shared between the draftjs / mdx implementations, which span the client / server differently.
6
+ */
7
+ import shortid from 'shortid';
8
+ export const getDraftjsImage = params => {
9
+ const {
10
+ captionText,
11
+ creditText,
12
+ alignment,
13
+ size,
14
+ assetId,
15
+ linkUrl,
16
+ linkIsExternal,
17
+ depth,
18
+ key,
19
+ path
20
+ } = params;
21
+ const blockKey = shortid.generate();
22
+ return {
23
+ contentBlock: {
24
+ key: shortid.generate(),
25
+ text: ' ',
26
+ type: 'atomic',
27
+ depth,
28
+ inlineStyleRanges: [],
29
+ entityRanges: [{
30
+ offset: 0,
31
+ length: 1,
32
+ key
33
+ }],
34
+ data: {}
35
+ },
36
+ entities: {
37
+ [key]: {
38
+ type: 'image',
39
+ mutability: 'IMMUTABLE',
40
+ data: {
41
+ id: assetId,
42
+ path,
43
+ caption: {
44
+ blocks: [{
45
+ key: blockKey,
46
+ text: captionText,
47
+ type: 'unstyled',
48
+ depth,
49
+ inlineStyleRanges: [],
50
+ entityRanges: [],
51
+ data: {}
52
+ }],
53
+ entityMap: {}
54
+ },
55
+ credit: {
56
+ blocks: [{
57
+ key: blockKey,
58
+ text: creditText,
59
+ type: 'unstyled',
60
+ depth,
61
+ inlineStyleRanges: [],
62
+ entityRanges: [],
63
+ data: {}
64
+ }],
65
+ entityMap: {}
66
+ },
67
+ link: {
68
+ url: linkUrl,
69
+ external: linkIsExternal
70
+ },
71
+ alignment,
72
+ size,
73
+ contentTypeId: 'ASSET'
74
+ }
75
+ }
76
+ }
77
+ };
78
+ };
79
+ export const getDraftjsPullquote = params => {
80
+ const {
81
+ text,
82
+ depth
83
+ } = params;
84
+ return {
85
+ contentBlock: {
86
+ key: shortid.generate(),
87
+ text,
88
+ type: 'pullquote',
89
+ depth,
90
+ inlineStyleRanges: [],
91
+ entityRanges: [],
92
+ data: {}
93
+ },
94
+ entities: {}
95
+ };
96
+ };
97
+ export const getDraftjsOembed = params => {
98
+ const {
99
+ key,
100
+ depth,
101
+ html,
102
+ width = 550,
103
+ height = undefined,
104
+ url = undefined,
105
+ author_name = undefined,
106
+ author_url = undefined,
107
+ type = undefined,
108
+ cache_age = undefined,
109
+ provider_name = undefined,
110
+ provider_url = undefined,
111
+ version = undefined
112
+ } = params;
113
+ return {
114
+ contentBlock: {
115
+ key: shortid.generate(),
116
+ text: ' ',
117
+ type: 'atomic',
118
+ depth,
119
+ inlineStyleRanges: [],
120
+ entityRanges: [{
121
+ offset: 0,
122
+ length: 1,
123
+ key
124
+ }],
125
+ data: {}
126
+ },
127
+ // Only html is required
128
+ entities: {
129
+ [key]: {
130
+ type: 'oembed',
131
+ mutability: 'IMMUTABLE',
132
+ data: {
133
+ url,
134
+ author_name,
135
+ author_url,
136
+ html,
137
+ width,
138
+ height,
139
+ type,
140
+ cache_age,
141
+ provider_name,
142
+ provider_url,
143
+ version
144
+ }
145
+ }
146
+ }
147
+ };
148
+ };