-
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
- Loading branch information
1 parent
4ce8480
commit 5bcc782
Showing
16 changed files
with
213 additions
and
11 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
66 changes: 66 additions & 0 deletions
66
src/Sulu/Bundle/AdminBundle/Resources/js/stores/clipboardStore/clipboardStore.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,66 @@ | ||
// @flow | ||
import type {Observer} from './types'; | ||
|
||
class ClipboardStore { | ||
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); | ||
} | ||
} | ||
|
||
get(key: string): mixed { | ||
const serializedValue = window.localStorage.getItem(key); | ||
|
||
return serializedValue ? JSON.parse(serializedValue) : undefined; | ||
} | ||
|
||
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) { | ||
if (!this.observers[key]) { | ||
this.observers[key] = []; | ||
} | ||
this.observers[key].push(observer); | ||
this.updateStorageEventListener(); | ||
|
||
// 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 ClipboardStore(); |
4 changes: 4 additions & 0 deletions
4
src/Sulu/Bundle/AdminBundle/Resources/js/stores/clipboardStore/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 clipboardStore from './clipboardStore'; | ||
|
||
export default clipboardStore; |
12 changes: 12 additions & 0 deletions
12
src/Sulu/Bundle/AdminBundle/Resources/js/stores/clipboardStore/tests/clipboardStore.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,12 @@ | ||
// @flow | ||
import clipboardStore from '../clipboardStore'; | ||
|
||
test('Load item from localStorage', () => { | ||
const item = {key1: 'value1', key2: 1234}; | ||
const getItemSpy = jest.fn().mockReturnValue(JSON.stringify(item)); | ||
window.localStorage = {getItem: getItemSpy}; | ||
|
||
const result = clipboardStore.get('test-key'); | ||
expect(result).toEqual(item); | ||
expect(getItemSpy).toBeCalledWith('test-key'); | ||
}); |
2 changes: 2 additions & 0 deletions
2
src/Sulu/Bundle/AdminBundle/Resources/js/stores/clipboardStore/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