-
Notifications
You must be signed in to change notification settings - Fork 332
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement block action for copying and cutting a single block (#6630)
- Loading branch information
1 parent
8592d99
commit 75578fc
Showing
16 changed files
with
219 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+348 Bytes
(100%)
src/Sulu/Bundle/AdminBundle/Resources/js/components/Icon/fonts/sulu.ttf
Binary file not shown.
Binary file modified
BIN
+348 Bytes
(100%)
src/Sulu/Bundle/AdminBundle/Resources/js/components/Icon/fonts/sulu.woff
Binary file not shown.
2 changes: 1 addition & 1 deletion
2
src/Sulu/Bundle/AdminBundle/Resources/js/components/Icon/selection.json
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 65 additions & 0 deletions
65
src/Sulu/Bundle/AdminBundle/Resources/js/utils/clipboard/clipboard.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
// @flow | ||
import type {Observer} from './types'; | ||
|
||
class Clipboard { | ||
observers: {[key: string]: Array<Observer>} = {}; | ||
storageEventListener: ?(event: StorageEvent) => void; | ||
|
||
updateStorageEventListener(): void { | ||
const activeObservers = Object.values(this.observers).flat().length; | ||
|
||
// listen for "storage" events to notify observers if something is copied in another browser window | ||
if (activeObservers > 0 && !this.storageEventListener) { | ||
this.storageEventListener = (event: StorageEvent) => { | ||
if (event.key) { | ||
this.notifyObservers(event.key, event.newValue ? JSON.parse(event.newValue) : undefined); | ||
} | ||
}; | ||
window.addEventListener('storage', this.storageEventListener); | ||
} else if (activeObservers === 0 && this.storageEventListener) { | ||
window.removeEventListener('storage', this.storageEventListener); | ||
} | ||
} | ||
|
||
notifyObservers(key: string, value: mixed): void { | ||
const observers = this.observers[key] || []; | ||
|
||
for (const observer of observers) { | ||
observer(value); | ||
} | ||
} | ||
|
||
set(key: string, value: mixed) { | ||
if (value) { | ||
window.localStorage.setItem(key, JSON.stringify(value)); | ||
} else { | ||
window.localStorage.removeItem(key); | ||
} | ||
|
||
this.notifyObservers(key, value); | ||
} | ||
|
||
observe(key: string, observer: Observer, invokeImmediately?: boolean) { | ||
if (!this.observers[key]) { | ||
this.observers[key] = []; | ||
} | ||
this.observers[key].push(observer); | ||
this.updateStorageEventListener(); | ||
|
||
if (invokeImmediately) { | ||
const currentValue = window.localStorage.getItem(key); | ||
observer(currentValue ? JSON.parse(currentValue) : undefined); | ||
} | ||
|
||
// return disposer function that allows to remove the registered observer | ||
return () => { | ||
const index = this.observers[key]?.indexOf(observer); | ||
if (index > -1) { | ||
this.observers[key].splice(index, 1); | ||
} | ||
this.updateStorageEventListener(); | ||
}; | ||
} | ||
} | ||
|
||
export default new Clipboard(); |
4 changes: 4 additions & 0 deletions
4
src/Sulu/Bundle/AdminBundle/Resources/js/utils/clipboard/index.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
// @flow | ||
import clipboard from './clipboard'; | ||
|
||
export default clipboard; |
14 changes: 14 additions & 0 deletions
14
src/Sulu/Bundle/AdminBundle/Resources/js/utils/clipboard/tests/clipboard.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
// @flow | ||
import clipboard from '../clipboard'; | ||
|
||
test('Set item and observe item', () => { | ||
clipboard.set('test-key', 'test-value'); | ||
|
||
let item = null; | ||
|
||
clipboard.observe('test-key', (value) => { | ||
item = value; | ||
}, true); | ||
|
||
expect(item).toEqual('test-value'); | ||
}); |
2 changes: 2 additions & 0 deletions
2
src/Sulu/Bundle/AdminBundle/Resources/js/utils/clipboard/types.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
// @flow | ||
export type Observer = (value: mixed) => void; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 2 additions & 0 deletions
2
src/Sulu/Bundle/AdminBundle/Resources/translations/admin.de.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 2 additions & 0 deletions
2
src/Sulu/Bundle/AdminBundle/Resources/translations/admin.en.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters