@stratusjs/angular 0.4.1 → 0.4.3

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.
@@ -1,5 +1,6 @@
1
1
  import {cookie} from '@stratusjs/core/environment'
2
2
  import {Stratus} from '@stratusjs/runtime/stratus'
3
+ import {extend} from 'lodash'
3
4
  // Universal Button
4
5
  import {
5
6
  InputButtonPlugin
@@ -18,18 +19,23 @@ const parentModuleName = 'froala/plugins'
18
19
  const min = !cookie('env') ? '.min' : ''
19
20
  const localDir = `${Stratus.BaseUrl}${boot.configuration.paths[`${systemDir}/*`].replace(/[^/]*$/, '')}`
20
21
 
21
- // Plugin Options
22
- FroalaEditor.DEFAULTS = Object.assign(FroalaEditor.DEFAULTS, {
23
- endpoint: '/Api/Content'
22
+ // Define toolbar template.
23
+ extend(FroalaEditor.POPUP_TEMPLATES,{
24
+ 'citationManager.toolbar': '[_BUTTONS_]'
24
25
  })
25
26
 
26
- /**
27
+ // Define toolbar buttons.
28
+ extend(FroalaEditor.DEFAULTS,{
29
+ citationToolbarButtons: ['citationEdit', 'citationDelete']
30
+ })
31
+
32
+ /*
27
33
  * @param editor The Froala instance
28
34
  */
29
- FroalaEditor.PLUGINS.citationManager = function citationManager (editor: any) {
35
+ FroalaEditor.PLUGINS.citationManager = function citationManager(editor: any) {
30
36
  let inputButton: InputButtonPlugin
31
37
 
32
- const debug = true // needs false
38
+ const debug = false
33
39
 
34
40
  // When the plugin is initialized,this will be called.
35
41
  function _init() {
@@ -45,7 +51,6 @@ FroalaEditor.PLUGINS.citationManager = function citationManager (editor: any) {
45
51
 
46
52
  if (debug) {
47
53
  console.log('initialized:', {
48
- options: editor.opts.endpoint,
49
54
  instance: this
50
55
  })
51
56
  }
@@ -54,7 +59,21 @@ FroalaEditor.PLUGINS.citationManager = function citationManager (editor: any) {
54
59
  // editor.methodName(params);
55
60
 
56
61
  // Event listeners
57
- // editor.events.add('contentChanged', function (params) {});
62
+ editor.events.on('click', (clickEvent: MouseEvent) => {
63
+ if (
64
+ clickEvent.hasOwnProperty('target') &&
65
+ // clickEvent.target.hasOwnProperty('nodeName') &&
66
+ (
67
+ (clickEvent.target as Element).nodeName === 'STRATUS-CITATION' ||
68
+ (clickEvent.target as Element).nodeName === 'STRATUS-CITATION-TITLE'
69
+ )
70
+ ) {
71
+ const citation = getSelectedCitation() // If citation isn't fully grabbed, will not attempt
72
+ if (citation) {
73
+ editor.citationManager.showToolbar(clickEvent, citation)
74
+ }
75
+ }
76
+ })
58
77
  }
59
78
 
60
79
  function onClick() {
@@ -65,19 +84,136 @@ FroalaEditor.PLUGINS.citationManager = function citationManager (editor: any) {
65
84
  inputButton.onClick(editor.el)
66
85
  }
67
86
 
87
+ function getSelectedCitation(): Element | null {
88
+ let containedElement = editor.selection.endElement()
89
+ if (containedElement.tagName === 'STRATUS-CITATION') {
90
+ // console.log('returning endElement', containedElement.tagName)
91
+ return containedElement
92
+ }
93
+
94
+ // console.log('endElement was a ', containedElement.tagName, containedElement)
95
+ containedElement = editor.selection.element()
96
+ if (containedElement.tagName === 'STRATUS-CITATION') {
97
+ // console.log('returning element', containedElement.tagName)
98
+ return containedElement
99
+ }
100
+
101
+ // console.log('element was a ', containedElement.tagName, containedElement)
102
+ // Check the parent just to be sure
103
+ containedElement = containedElement.parentElement
104
+ if (containedElement.tagName === 'STRATUS-CITATION') {
105
+ // console.log('returning parent element', containedElement.tagName)
106
+ return containedElement
107
+ }
108
+ // console.log('parent element was a ', containedElement.tagName, containedElement, 'returning nothing')
109
+
110
+ return null
111
+ }
112
+
113
+ function getLastKnownCitation() {
114
+ // console.log('returning last citation', editor.citationManager.lastCitation)
115
+ return editor.citationManager.lastCitation || null
116
+ }
117
+
118
+ function setLastKnownCitation(el: Element | null) {
119
+ // console.log('setting last citation to', el)
120
+ editor.citationManager.lastCitation = el
121
+ }
122
+
123
+ // Create custom inline toolbar.
124
+ function initToolbar() {
125
+ // Toolbar buttons.
126
+ let citationToolbarButtons = ''
127
+ // Create the list of buttons.
128
+ if (editor.opts.citationToolbarButtons.length > 1) {
129
+ citationToolbarButtons += '<div class="fr-buttons">'
130
+ citationToolbarButtons += editor.button.buildList(editor.opts.citationToolbarButtons)
131
+ citationToolbarButtons += '</div>'
132
+ }
133
+ // Load popup template.
134
+ const template = {
135
+ buttons: citationToolbarButtons
136
+ }
137
+ // Create popup.
138
+ return editor.popups.create('citationManager.toolbar', template)
139
+ }
140
+
141
+ // Show the toolbar
142
+ function showToolbar(clickEvent: MouseEvent, citation: Element) {
143
+ // Get the popup object defined above.
144
+ const popup = editor.popups.get('citationManager.toolbar')
145
+ // If popup doesn't exist then create it.
146
+ // To improve performance it is best to create the popup when it is first needed
147
+ // and not when the editor is initialized.
148
+ if (!popup) initToolbar()
149
+
150
+ // Set the editor toolbar as the popup's container.
151
+ editor.popups.setContainer('citationManager.toolbar', editor.$tb)
152
+ // This will trigger the refresh event assigned to the popup.
153
+ // editor.popups.refresh('citationManager.toolbar');
154
+ // This custom popup is opened by pressing a button from the editor's toolbar.
155
+ // Get the button's object in order to place the popup relative to it.
156
+ const btn = editor.$tb.find('.fr-command[data-cmd="myButton"]')
157
+ // Set the popup's position.
158
+ const left = clickEvent.pageX
159
+ const top = clickEvent.pageY
160
+ // Show the custom toolbar.
161
+ // The button's outerHeight is required in case the popup needs to be displayed above it.
162
+ editor.popups.show('citationManager.toolbar', left, top, btn.outerHeight())
163
+ // Hold onto this lastKnown for the dialog to use -this- element
164
+ editor.citationManager.setLastKnownCitation(citation)
165
+ }
166
+
167
+ // Hide the custom popup.
168
+ function hideToolbar() {
169
+ editor.citationManager.setLastKnownCitation(null)
170
+ editor.popups.hide('citationManager.toolbar')
171
+ }
172
+
68
173
  // Expose public methods.
69
174
  // Public methods can be accessed through the editor API:
70
175
  // editor.myPlugin.publicMethod();
71
176
  return {
72
177
  // If _init is not public then the plugin won't be initialized.
73
178
  _init,
74
- onClick
179
+ onClick,
180
+ showToolbar,
181
+ hideToolbar,
182
+ getSelectedCitation,
183
+ getLastKnownCitation,
184
+ setLastKnownCitation
75
185
  }
76
186
  }
187
+ export type CitationManager = {
188
+ hideToolbar(): void
189
+ showToolbar(): void
190
+ getSelectedCitation(): Element | null
191
+ getLastKnownCitation(): Element | null
192
+ setLastKnownCitation(el: Element | null): void
193
+ }
194
+
195
+ FroalaEditor.DefineIcon('citationDelete',{NAME: 'citationDelete', SVG_KEY: 'remove'})
196
+ FroalaEditor.RegisterCommand('citationDelete', {
197
+ title: 'Delete Citation',
198
+ undo: false,
199
+ focus: false,
200
+ callback() {
201
+ /// only grab the selectedCitation
202
+ const containedElement = this.citationManager.getSelectedCitation()
203
+ if (containedElement) {
204
+ (containedElement as Element).remove()
205
+ }
206
+ this.citationManager.hideToolbar()
207
+ }
208
+ })
77
209
 
78
- // Insert Plugin to Image Insert TODO will not in the end
79
- FroalaEditor.DEFAULTS.imageInsertButtons.push('citationManager')
80
- FroalaEditor.RegisterCommand('citationManager', {
210
+ // Define button icons
211
+ FroalaEditor.DefineIcon('citationManager', {NAME: 'citationManager', SVG_KEY: 'imageCaption'})
212
+ // See https://froala.com/wysiwyg-editor/docs/concepts/custom/icon/ for making new icons
213
+
214
+ // Define a insert button
215
+ FroalaEditor.RegisterCommand('citationInsert', {
216
+ icon: 'citationManager',
81
217
  title: 'Insert Citation',
82
218
  undo: false,
83
219
  focus: false,
@@ -95,9 +231,24 @@ FroalaEditor.RegisterCommand('citationManager', {
95
231
  plugin: 'citationManager',
96
232
  })
97
233
 
98
- // Define button icons
99
- FroalaEditor.DefineIcon('citationManager', {NAME: 'folder', SVG_KEY: 'imageCaption'})
100
- // See https://froala.com/wysiwyg-editor/docs/concepts/custom/icon/ for making new icons
234
+ // Define a edit button
235
+ FroalaEditor.RegisterCommand('citationEdit', {
236
+ icon: 'citationManager',
237
+ title: 'Edit Citation',
238
+ undo: false,
239
+ focus: false,
240
+ modal: true,
241
+ callback(cmd: unknown, _val: unknown, _params: unknown) {
242
+ const debug = false
243
+ if (debug) {
244
+ console.log('clicked:', this.citationManager)
245
+ }
246
+ this.citationManager.onClick()
247
+ },
248
+ plugin: 'citationManager',
249
+ })
250
+
251
+
101
252
 
102
253
  // Define a quick insert button
103
254
  FroalaEditor.RegisterQuickInsertButton('citation', {