dante2-editor 0.2.0 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (144) hide show
  1. checksums.yaml +4 -4
  2. data/.babelrc +20 -0
  3. data/.eslint +13 -0
  4. data/.gitignore +15 -0
  5. data/README.md +5 -1
  6. data/dante2.gemspec +2 -4
  7. data/{app → demo}/assets/index.html +2 -2
  8. data/{app → demo}/assets/license.html +1 -1
  9. data/{app → demo}/assets/options.html +1 -5
  10. data/{app → demo}/assets/store.json +0 -0
  11. data/demo/data/poc.js +9 -0
  12. data/demo/demo.js +9 -0
  13. data/demo/initialize.js +7 -0
  14. data/{app → demo}/styles/layout/layout.scss +0 -0
  15. data/{app → demo}/styles/layout/normalize.css +0 -0
  16. data/{app → demo}/styles/layout/scaffold.scss +0 -0
  17. data/{app → demo}/styles/layout/tooltips.scss +0 -0
  18. data/dist/Dante2.js +2995 -0
  19. data/dist/Dante2.min.js +3 -0
  20. data/dist/Dante2.min.js.map +1 -0
  21. data/dist/DanteStyles.css +2 -0
  22. data/dist/DanteStyles.css.map +1 -0
  23. data/dist/DanteStyles.js +102 -0
  24. data/dist/DanteStyles.min.js +2 -0
  25. data/dist/DanteStyles.min.js.map +1 -0
  26. data/dist/dante-vendors.js +48316 -0
  27. data/dist/dante-vendors.min.js +29 -0
  28. data/dist/dante-vendors.min.js.map +1 -0
  29. data/{app/styles/fonts/dante → dist/fonts}/dante.eot +0 -0
  30. data/{app/styles/fonts/dante → dist/fonts}/dante.svg +0 -0
  31. data/{app/styles/fonts/dante → dist/fonts}/dante.ttf +0 -0
  32. data/{app/styles/fonts/dante → dist/fonts}/dante.woff +0 -0
  33. data/{app/styles/fonts/dante → dist/fonts}/fontello.eot +0 -0
  34. data/{app/styles/fonts/dante → dist/fonts}/fontello.svg +0 -0
  35. data/{app/styles/fonts/dante → dist/fonts}/fontello.ttf +0 -0
  36. data/{app/styles/fonts/dante → dist/fonts}/fontello.woff +0 -0
  37. data/docs/app.css +430 -1
  38. data/docs/app.css.map +1 -1
  39. data/docs/app.js +62 -2
  40. data/docs/app.js.map +1 -1
  41. data/docs/dante-vendors.js +49513 -22
  42. data/docs/dante-vendors.js.map +1 -1
  43. data/docs/dante.css +1602 -1
  44. data/docs/dante.css.map +1 -1
  45. data/docs/dante.js +3310 -3
  46. data/docs/dante.js.map +1 -1
  47. data/docs/doc.html +3 -7
  48. data/docs/index.html +4 -4
  49. data/docs/license.html +3 -3
  50. data/docs/options.html +53 -0
  51. data/package.json +47 -17
  52. data/rb_lib/dante2-editor/rails.rb +15 -0
  53. data/{lib → rb_lib}/dante2-editor/version.rb +1 -1
  54. data/{lib → rb_lib}/dante2-editor.rb +0 -0
  55. data/src/components/blocks/embed.js +126 -0
  56. data/src/components/blocks/image.js +377 -0
  57. data/src/components/blocks/placeholder.js +68 -0
  58. data/src/components/blocks/video.js +80 -0
  59. data/src/components/dante.js +291 -0
  60. data/src/components/dante_editor.js +928 -0
  61. data/src/components/debug.js +104 -0
  62. data/src/components/decorators/link.js +64 -0
  63. data/src/components/popovers/addButton.js +318 -0
  64. data/src/components/popovers/image.js +188 -0
  65. data/src/components/popovers/link.js +107 -0
  66. data/src/components/popovers/toolTip.js +402 -0
  67. data/{app/utils/logger.coffee → src/components/wrapper.js} +0 -0
  68. data/{app → src}/images/dante/media-loading-placeholder.png +0 -0
  69. data/{app → src}/images/site/dante-demo.png +0 -0
  70. data/{app → src}/images/site/dante-editor-logo.png +0 -0
  71. data/{app → src}/images/site/github-logo.png +0 -0
  72. data/src/index.js +9 -0
  73. data/{app → src}/model/index.js +0 -0
  74. data/src/style.js +3 -0
  75. data/{app → src}/styles/dante/_animations.scss +0 -0
  76. data/{app → src}/styles/dante/_caption.scss +0 -0
  77. data/{app → src}/styles/dante/_debug.scss +0 -0
  78. data/{app → src}/styles/dante/_fonts.scss +0 -0
  79. data/{app → src}/styles/dante/_graf.scss +0 -0
  80. data/{app → src}/styles/dante/_icons.scss +0 -0
  81. data/{app → src}/styles/dante/_media.scss +0 -0
  82. data/{app → src}/styles/dante/_menu.scss +0 -0
  83. data/{app → src}/styles/dante/_needsorder.scss +0 -0
  84. data/{app → src}/styles/dante/_popover.scss +0 -0
  85. data/{app → src}/styles/dante/_post.scss +0 -0
  86. data/{app → src}/styles/dante/_scaffold.scss +0 -0
  87. data/{app → src}/styles/dante/_tooltip.scss +0 -0
  88. data/{app → src}/styles/dante/_utilities.scss +0 -0
  89. data/{app → src}/styles/dante/_variables.scss +0 -0
  90. data/{app → src}/styles/dante/blame.scss +0 -0
  91. data/{app → src}/styles/dante.scss +0 -0
  92. data/{app → src}/styles/draft.css +0 -0
  93. data/src/styles/fonts/dante/dante.eot +0 -0
  94. data/src/styles/fonts/dante/dante.svg +18 -0
  95. data/src/styles/fonts/dante/dante.ttf +0 -0
  96. data/src/styles/fonts/dante/dante.woff +0 -0
  97. data/src/styles/fonts/dante/fontello.eot +0 -0
  98. data/src/styles/fonts/dante/fontello.svg +36 -0
  99. data/src/styles/fonts/dante/fontello.ttf +0 -0
  100. data/src/styles/fonts/dante/fontello.woff +0 -0
  101. data/src/utils/find_entities.js +17 -0
  102. data/src/utils/html2content.js +127 -0
  103. data/src/utils/save_content.js +80 -0
  104. data/{app → src}/utils/selection.js +0 -0
  105. data/tools/.eslintrc +9 -0
  106. data/tools/amd/README.md +7 -0
  107. data/tools/amd/bower.json +19 -0
  108. data/tools/amd/build.js +36 -0
  109. data/tools/build-cli.js +46 -0
  110. data/tools/build.js +30 -0
  111. data/tools/buildBabel.js +32 -0
  112. data/tools/constants.js +10 -0
  113. data/tools/dist/build.js +13 -0
  114. data/tools/docs/build.js +12 -0
  115. data/tools/es/build.js +27 -0
  116. data/tools/exec.js +50 -0
  117. data/tools/fs-utils.js +35 -0
  118. data/tools/lib/build.js +14 -0
  119. data/tools/promisify.js +14 -0
  120. data/webpack/base.config.js +89 -0
  121. data/webpack/docs.config.js +147 -0
  122. data/webpack/webpack.config.js +78 -0
  123. data/webpack.config-doc.js +5 -0
  124. data/webpack.config.js +3 -147
  125. data/yarn.lock +973 -718
  126. metadata +108 -64
  127. data/app/components/App.cjsx +0 -1083
  128. data/app/components/blocks/embed.cjsx +0 -109
  129. data/app/components/blocks/image.cjsx +0 -316
  130. data/app/components/blocks/placeholder.cjsx +0 -60
  131. data/app/components/blocks/video.cjsx +0 -75
  132. data/app/components/debug.cjsx +0 -96
  133. data/app/components/decorators/link.cjsx +0 -61
  134. data/app/components/popovers/addButton.cjsx +0 -247
  135. data/app/components/popovers/image.cjsx +0 -160
  136. data/app/components/popovers/link.cjsx +0 -87
  137. data/app/components/popovers/toolTip.cjsx +0 -326
  138. data/app/data/poc.js +0 -15
  139. data/app/demo.js +0 -7
  140. data/app/initialize.js +0 -4
  141. data/app/utils/find_entities.coffee +0 -20
  142. data/app/utils/html2content.coffee +0 -120
  143. data/app/utils/save_content.coffee +0 -63
  144. data/lib/dante2-editor/rails.rb +0 -16
@@ -1,326 +0,0 @@
1
- React = require('react')
2
- ReactDOM = require('react-dom')
3
-
4
- {
5
- convertToRaw,
6
- CompositeDecorator,
7
- getVisibleSelectionRect,
8
- getDefaultKeyBinding,
9
- getSelectionOffsetKeyForNode,
10
- KeyBindingUtil,
11
- ContentState,
12
- Editor,
13
- EditorState,
14
- Entity,
15
- RichUtils
16
- } = require('draft-js')
17
-
18
- {
19
- getSelectionRect
20
- getSelection
21
- } = require("../../utils/selection.js")
22
-
23
- {
24
- getCurrentBlock
25
- } = require('../../model/index.js')
26
-
27
-
28
- class DanteTooltip extends React.Component
29
-
30
- constructor: (props) ->
31
- super props
32
- @getVisibleSelectionRect = getVisibleSelectionRect
33
- @state =
34
- link_mode: false
35
- show: false
36
- position: {}
37
-
38
- _clickInlineHandler: (ev, style)=>
39
- ev.preventDefault()
40
-
41
- @props.onChange(
42
- RichUtils.toggleInlineStyle(@props.editorState, style)
43
- )
44
-
45
- setTimeout ()=>
46
- @relocate()
47
- , 0
48
-
49
- display: (b)=>
50
- if b then @show() else @hide()
51
-
52
- show: =>
53
- @setState
54
- show: true
55
-
56
- hide: =>
57
- @setState
58
- link_mode: false
59
- show: false
60
-
61
- setPosition: (coords)->
62
- @setState
63
- position: coords
64
-
65
-
66
- isDescendant: (parent, child)->
67
- node = child.parentNode
68
- while node != null
69
- if (node is parent)
70
- return true
71
- node = node.parentNode
72
- return false
73
-
74
- relocate: ()=>
75
-
76
- currentBlock = getCurrentBlock(@props.editorState);
77
- blockType = currentBlock.getType()
78
- # display tooltip only for unstyled
79
-
80
- if @.props.configTooltip.selectionElements.indexOf(blockType) < 0
81
- @hide()
82
- return
83
-
84
- return if @state.link_mode
85
- return if !@state.show
86
-
87
-
88
- el = @refs.dante_menu
89
- padd = el.offsetWidth / 2
90
-
91
- nativeSelection = getSelection(window);
92
- if !nativeSelection.rangeCount
93
- return
94
-
95
- selectionBoundary = getSelectionRect(nativeSelection);
96
-
97
- parent = ReactDOM.findDOMNode(@props.editor);
98
- parentBoundary = parent.getBoundingClientRect();
99
-
100
- # hide if selected node is not in editor
101
- if !@isDescendant(parent, nativeSelection.anchorNode)
102
- @hide()
103
- return
104
-
105
-
106
- top = selectionBoundary.top - parentBoundary.top - -90 - 5
107
- left = selectionBoundary.left + (selectionBoundary.width / 2) - padd
108
-
109
- if !top or !left
110
- return
111
-
112
- # console.log "SET SHOW FOR TOOLTIP INSERT MENU"
113
- @setState
114
- show: true
115
- position:
116
- left: left
117
- top: top
118
-
119
- _clickBlockHandler: (ev, style)=>
120
- ev.preventDefault()
121
-
122
- @props.onChange(
123
- RichUtils.toggleBlockType(@props.editorState, style)
124
- )
125
-
126
- setTimeout ()=>
127
- @relocate()
128
- , 0
129
-
130
- displayLinkMode: =>
131
- if @state.link_mode then "dante-menu--linkmode" else ""
132
-
133
- displayActiveMenu: =>
134
- if @state.show then "dante-menu--active" else ""
135
-
136
- _enableLinkMode: (ev)=>
137
- ev.preventDefault()
138
- @setState
139
- link_mode: true
140
-
141
- _disableLinkMode: (ev)=>
142
- ev.preventDefault()
143
- @setState
144
- link_mode: false
145
- url: ""
146
-
147
- hideMenu: ->
148
- @hide()
149
-
150
- handleInputEnter: (e)=>
151
- if (e.which is 13)
152
- return @confirmLink(e)
153
-
154
- confirmLink: (e)=>
155
- e.preventDefault()
156
- editorState = @.props.editorState
157
- urlValue = e.currentTarget.value
158
- contentState = editorState.getCurrentContent()
159
- selection = editorState.getSelection()
160
-
161
- opts = {
162
- url: urlValue
163
- showPopLinkOver: @props.showPopLinkOver
164
- hidePopLinkOver: @props.hidePopLinkOver
165
- }
166
-
167
- entityKey = Entity.create('LINK', 'MUTABLE', opts);
168
-
169
- if selection.isCollapsed()
170
- console.log "COLLAPSED SKIPPING LINK"
171
- return
172
-
173
- @props.onChange(
174
- RichUtils.toggleLink(
175
- editorState,
176
- selection,
177
- entityKey
178
- )
179
- )
180
-
181
- @_disableLinkMode(e)
182
-
183
- getPosition: ->
184
- pos = @state.position
185
- pos
186
-
187
- inlineItems: =>
188
- @props.widget_options.block_types.filter (o)=>
189
- o.type is "inline"
190
-
191
- blockItems: =>
192
- @props.widget_options.block_types.filter (o)=>
193
- o.type is "block"
194
-
195
- getDefaultValue: =>
196
- @refs.dante_menu_input.value = "" if @refs.dante_menu_input
197
-
198
- currentBlock = getCurrentBlock(@props.editorState);
199
- blockType = currentBlock.getType()
200
- selection = @props.editor.state.editorState.getSelection()
201
- selectedEntity = null
202
- defaultUrl = null
203
- currentBlock.findEntityRanges (character) =>
204
- entityKey = character.getEntity()
205
- selectedEntity = entityKey
206
- return entityKey isnt null && Entity.get(entityKey).getType() is 'LINK'
207
- , (start, end) =>
208
- selStart = selection.getAnchorOffset()
209
- selEnd = selection.getFocusOffset()
210
- if selection.getIsBackward()
211
- selStart = selection.getFocusOffset()
212
- selEnd = selection.getAnchorOffset()
213
-
214
- if start is selStart && end is selEnd
215
- defaultUrl = Entity.get(selectedEntity).getData().url
216
- @refs.dante_menu_input.value = defaultUrl
217
-
218
- render: ->
219
- return (
220
- <div id="dante-menu"
221
- ref="dante_menu"
222
- className="dante-menu #{@displayActiveMenu()} #{@displayLinkMode()}"
223
- style={@getPosition()}>
224
-
225
- <div className="dante-menu-linkinput">
226
- <input className="dante-menu-input"
227
- ref="dante_menu_input"
228
- placeholder="Paste or type a link"
229
- onKeyPress={@handleInputEnter}
230
- defaultValue={@getDefaultValue()}
231
- />
232
-
233
- <div className="dante-menu-button"
234
- onMouseDown={@_disableLinkMode}>
235
- x
236
- </div>
237
- </div>
238
-
239
- <ul className="dante-menu-buttons">
240
- {
241
- @blockItems().map (item, i)=>
242
- <DanteTooltipItem
243
- key={i}
244
- item={item}
245
- handleClick={@_clickBlockHandler}
246
- editorState={@props.editorState}
247
- type={"block"}
248
- currentStyle={@props.editorState.getCurrentInlineStyle}
249
- />
250
- }
251
- {
252
- <DanteTooltipLink
253
- editorState={@props.editorState}
254
- enableLinkMode={@_enableLinkMode}
255
- />
256
- }
257
- {
258
- @inlineItems().map (item, i)=>
259
- <DanteTooltipItem
260
- key={i}
261
- item={item}
262
- type={"inline"}
263
- editorState={@props.editorState}
264
- handleClick={@_clickInlineHandler}
265
- />
266
- }
267
- </ul>
268
- </div>
269
- )
270
-
271
- class DanteTooltipItem extends React.Component
272
-
273
- handleClick: (ev)=>
274
- @props.handleClick(ev, @props.item.style)
275
-
276
- activeClass: =>
277
- if @isActive() then "active" else ""
278
-
279
- isActive: =>
280
- if @props.type is "block"
281
- @activeClassBlock()
282
- else
283
- @activeClassInline()
284
-
285
- activeClassInline: =>
286
- return unless @props.editorState
287
- #console.log @props.item
288
- @props.editorState.getCurrentInlineStyle().has(@props.item.style)
289
-
290
- activeClassBlock: =>
291
- #console.log "EDITOR STATE", @props.editorState
292
- return unless @props.editorState
293
- selection = @props.editorState.getSelection()
294
- blockType = @props.editorState
295
- .getCurrentContent()
296
- .getBlockForKey(selection.getStartKey())
297
- .getType()
298
- @props.item.style is blockType
299
-
300
- render: =>
301
- return (
302
- <li className="dante-menu-button #{@activeClass()}"
303
- onMouseDown={@handleClick}>
304
- <i className="dante-icon dante-icon-#{@props.item.label}"
305
- data-action="bold"></i>
306
- </li>
307
- )
308
-
309
- class DanteTooltipLink extends React.Component
310
-
311
- promptForLink: (ev)=>
312
- selection = @props.editorState.getSelection()
313
- if (!selection.isCollapsed())
314
- @props.enableLinkMode(ev)
315
-
316
- render: ->
317
- return (
318
- <li className="dante-menu-button"
319
- onMouseDown={@.promptForLink}>
320
- <i className="dante-icon icon-createlink"
321
- data-action="createlink">link</i>
322
- </li>
323
- )
324
-
325
-
326
- module.exports = DanteTooltip