@jupyterlab/apputils 0.19.1-alpha.0 → 0.19.1

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,33 +1,33 @@
1
- import { MimeData } from '@phosphor/coreutils';
2
- /**
3
- * The clipboard interface.
4
- */
5
- export declare namespace Clipboard {
6
- /**
7
- * Get the application clipboard instance.
8
- */
9
- function getInstance(): MimeData;
10
- /**
11
- * Set the application clipboard instance.
12
- */
13
- function setInstance(value: MimeData): void;
14
- /**
15
- * Copy text to the system clipboard.
16
- *
17
- * #### Notes
18
- * This can only be called in response to a user input event.
19
- */
20
- function copyToSystem(text: string): void;
21
- /**
22
- * Generate a clipboard event on a node.
23
- *
24
- * @param node - The element on which to generate the event.
25
- *
26
- * @param type - The type of event to generate.
27
- * `'paste'` events cannot be programmatically generated.
28
- *
29
- * #### Notes
30
- * This can only be called in response to a user input event.
31
- */
32
- function generateEvent(node: HTMLElement, type?: 'copy' | 'cut'): void;
33
- }
1
+ import { MimeData } from '@phosphor/coreutils';
2
+ /**
3
+ * The clipboard interface.
4
+ */
5
+ export declare namespace Clipboard {
6
+ /**
7
+ * Get the application clipboard instance.
8
+ */
9
+ function getInstance(): MimeData;
10
+ /**
11
+ * Set the application clipboard instance.
12
+ */
13
+ function setInstance(value: MimeData): void;
14
+ /**
15
+ * Copy text to the system clipboard.
16
+ *
17
+ * #### Notes
18
+ * This can only be called in response to a user input event.
19
+ */
20
+ function copyToSystem(text: string): void;
21
+ /**
22
+ * Generate a clipboard event on a node.
23
+ *
24
+ * @param node - The element on which to generate the event.
25
+ *
26
+ * @param type - The type of event to generate.
27
+ * `'paste'` events cannot be programmatically generated.
28
+ *
29
+ * #### Notes
30
+ * This can only be called in response to a user input event.
31
+ */
32
+ function generateEvent(node: HTMLElement, type?: 'copy' | 'cut'): void;
33
+ }
package/lib/clipboard.js CHANGED
@@ -1,88 +1,88 @@
1
- "use strict";
2
- // Copyright (c) Jupyter Development Team.
3
- // Distributed under the terms of the Modified BSD License.
4
- Object.defineProperty(exports, "__esModule", { value: true });
5
- const coreutils_1 = require("@phosphor/coreutils");
6
- /**
7
- * The clipboard interface.
8
- */
9
- var Clipboard;
10
- (function (Clipboard) {
11
- /**
12
- * Get the application clipboard instance.
13
- */
14
- function getInstance() {
15
- return Private.instance;
16
- }
17
- Clipboard.getInstance = getInstance;
18
- /**
19
- * Set the application clipboard instance.
20
- */
21
- function setInstance(value) {
22
- Private.instance = value;
23
- }
24
- Clipboard.setInstance = setInstance;
25
- /**
26
- * Copy text to the system clipboard.
27
- *
28
- * #### Notes
29
- * This can only be called in response to a user input event.
30
- */
31
- function copyToSystem(text) {
32
- let node = document.body;
33
- let handler = (event) => {
34
- let data = event.clipboardData || window.clipboardData;
35
- data.setData('text', text);
36
- event.preventDefault();
37
- node.removeEventListener('copy', handler);
38
- };
39
- node.addEventListener('copy', handler);
40
- generateEvent(node);
41
- }
42
- Clipboard.copyToSystem = copyToSystem;
43
- /**
44
- * Generate a clipboard event on a node.
45
- *
46
- * @param node - The element on which to generate the event.
47
- *
48
- * @param type - The type of event to generate.
49
- * `'paste'` events cannot be programmatically generated.
50
- *
51
- * #### Notes
52
- * This can only be called in response to a user input event.
53
- */
54
- function generateEvent(node, type = 'copy') {
55
- // http://stackoverflow.com/a/5210367
56
- // Identify selected text.
57
- let sel = window.getSelection();
58
- // Save the current selection.
59
- let savedRanges = [];
60
- for (let i = 0, len = sel.rangeCount; i < len; ++i) {
61
- savedRanges[i] = sel.getRangeAt(i).cloneRange();
62
- }
63
- // Select the node content.
64
- let range = document.createRange();
65
- range.selectNodeContents(node);
66
- sel.removeAllRanges();
67
- sel.addRange(range);
68
- // Execute the command.
69
- document.execCommand(type);
70
- // Restore the previous selection.
71
- sel = window.getSelection();
72
- sel.removeAllRanges();
73
- for (let i = 0, len = savedRanges.length; i < len; ++i) {
74
- sel.addRange(savedRanges[i]);
75
- }
76
- }
77
- Clipboard.generateEvent = generateEvent;
78
- })(Clipboard = exports.Clipboard || (exports.Clipboard = {}));
79
- /**
80
- * The namespace for module private data.
81
- */
82
- var Private;
83
- (function (Private) {
84
- /**
85
- * The application clipboard instance.
86
- */
87
- Private.instance = new coreutils_1.MimeData();
88
- })(Private || (Private = {}));
1
+ "use strict";
2
+ // Copyright (c) Jupyter Development Team.
3
+ // Distributed under the terms of the Modified BSD License.
4
+ Object.defineProperty(exports, "__esModule", { value: true });
5
+ const coreutils_1 = require("@phosphor/coreutils");
6
+ /**
7
+ * The clipboard interface.
8
+ */
9
+ var Clipboard;
10
+ (function (Clipboard) {
11
+ /**
12
+ * Get the application clipboard instance.
13
+ */
14
+ function getInstance() {
15
+ return Private.instance;
16
+ }
17
+ Clipboard.getInstance = getInstance;
18
+ /**
19
+ * Set the application clipboard instance.
20
+ */
21
+ function setInstance(value) {
22
+ Private.instance = value;
23
+ }
24
+ Clipboard.setInstance = setInstance;
25
+ /**
26
+ * Copy text to the system clipboard.
27
+ *
28
+ * #### Notes
29
+ * This can only be called in response to a user input event.
30
+ */
31
+ function copyToSystem(text) {
32
+ let node = document.body;
33
+ let handler = (event) => {
34
+ let data = event.clipboardData || window.clipboardData;
35
+ data.setData('text', text);
36
+ event.preventDefault();
37
+ node.removeEventListener('copy', handler);
38
+ };
39
+ node.addEventListener('copy', handler);
40
+ generateEvent(node);
41
+ }
42
+ Clipboard.copyToSystem = copyToSystem;
43
+ /**
44
+ * Generate a clipboard event on a node.
45
+ *
46
+ * @param node - The element on which to generate the event.
47
+ *
48
+ * @param type - The type of event to generate.
49
+ * `'paste'` events cannot be programmatically generated.
50
+ *
51
+ * #### Notes
52
+ * This can only be called in response to a user input event.
53
+ */
54
+ function generateEvent(node, type = 'copy') {
55
+ // http://stackoverflow.com/a/5210367
56
+ // Identify selected text.
57
+ let sel = window.getSelection();
58
+ // Save the current selection.
59
+ let savedRanges = [];
60
+ for (let i = 0, len = sel.rangeCount; i < len; ++i) {
61
+ savedRanges[i] = sel.getRangeAt(i).cloneRange();
62
+ }
63
+ // Select the node content.
64
+ let range = document.createRange();
65
+ range.selectNodeContents(node);
66
+ sel.removeAllRanges();
67
+ sel.addRange(range);
68
+ // Execute the command.
69
+ document.execCommand(type);
70
+ // Restore the previous selection.
71
+ sel = window.getSelection();
72
+ sel.removeAllRanges();
73
+ for (let i = 0, len = savedRanges.length; i < len; ++i) {
74
+ sel.addRange(savedRanges[i]);
75
+ }
76
+ }
77
+ Clipboard.generateEvent = generateEvent;
78
+ })(Clipboard = exports.Clipboard || (exports.Clipboard = {}));
79
+ /**
80
+ * The namespace for module private data.
81
+ */
82
+ var Private;
83
+ (function (Private) {
84
+ /**
85
+ * The application clipboard instance.
86
+ */
87
+ Private.instance = new coreutils_1.MimeData();
88
+ })(Private || (Private = {}));
@@ -1,121 +1,121 @@
1
- import { JSONObject } from '@phosphor/coreutils';
2
- import { IDisposable } from '@phosphor/disposable';
3
- import { CommandRegistry } from '@phosphor/commands';
4
- import { ElementDataset } from '@phosphor/virtualdom';
5
- /**
6
- * A static class that provides helper methods to generate clickable nodes that
7
- * execute registered commands with pre-populated arguments.
8
- */
9
- export declare class CommandLinker implements IDisposable {
10
- /**
11
- * Instantiate a new command linker.
12
- */
13
- constructor(options: CommandLinker.IOptions);
14
- /**
15
- * Test whether the linker is disposed.
16
- */
17
- readonly isDisposed: boolean;
18
- /**
19
- * Dispose of the resources held by the linker.
20
- */
21
- dispose(): void;
22
- /**
23
- * Connect a command/argument pair to a given node so that when it is clicked,
24
- * the command will execute.
25
- *
26
- * @param node - The node being connected.
27
- *
28
- * @param command - The command ID to execute upon click.
29
- *
30
- * @param args - The arguments with which to invoke the command.
31
- *
32
- * @returns The same node that was passed in, after it has been connected.
33
- *
34
- * #### Notes
35
- * Only `click` events will execute the command on a connected node. So, there
36
- * are two considerations that are relevant:
37
- * 1. If a node is connected, the default click action will be prevented.
38
- * 2. The `HTMLElement` passed in should be clickable.
39
- */
40
- connectNode(node: HTMLElement, command: string, args?: JSONObject): HTMLElement;
41
- /**
42
- * Disconnect a node that has been connected to execute a command on click.
43
- *
44
- * @param node - The node being disconnected.
45
- *
46
- * @returns The same node that was passed in, after it has been disconnected.
47
- *
48
- * #### Notes
49
- * This method is safe to call multiple times and is safe to call on nodes
50
- * that were never connected.
51
- *
52
- * This method can be called on rendered virtual DOM nodes that were populated
53
- * using the `populateVNodeDataset` method in order to disconnect them from
54
- * executing their command/argument pair.
55
- */
56
- disconnectNode(node: HTMLElement): HTMLElement;
57
- /**
58
- * Handle the DOM events for the command linker helper class.
59
- *
60
- * @param event - The DOM event sent to the class.
61
- *
62
- * #### Notes
63
- * This method implements the DOM `EventListener` interface and is
64
- * called in response to events on the panel's DOM node. It should
65
- * not be called directly by user code.
66
- */
67
- handleEvent(event: Event): void;
68
- /**
69
- * Populate the `dataset` attribute within the collection of attributes used
70
- * to instantiate a virtual DOM node with the values necessary for its
71
- * rendered DOM node to respond to clicks by executing a command/argument
72
- * pair.
73
- *
74
- * @param command - The command ID to execute upon click.
75
- *
76
- * @param args - The arguments with which to invoke the command.
77
- *
78
- * @returns A `dataset` collection for use within virtual node attributes.
79
- *
80
- * #### Notes
81
- * The return value can be used on its own as the value for the `dataset`
82
- * attribute of a virtual element, or it can be added to an existing `dataset`
83
- * as in the example below.
84
- *
85
- * #### Example
86
- * ```typescript
87
- * let command = 'some:command-id';
88
- * let args = { alpha: 'beta' };
89
- * let anchor = h.a({
90
- * className: 'some-class',
91
- * dataset: {
92
- * foo: '1',
93
- * bar: '2',
94
- * ../...linker.populateVNodeDataset(command, args)
95
- * }
96
- * }, 'some text');
97
- * ```
98
- */
99
- populateVNodeDataset(command: string, args?: JSONObject): ElementDataset;
100
- /**
101
- * The global click handler that deploys commands/argument pairs that are
102
- * attached to the node being clicked.
103
- */
104
- private _evtClick;
105
- private _commands;
106
- private _isDisposed;
107
- }
108
- /**
109
- * A namespace for command linker statics.
110
- */
111
- export declare namespace CommandLinker {
112
- /**
113
- * The instantiation options for a command linker.
114
- */
115
- interface IOptions {
116
- /**
117
- * The command registry instance that all linked commands will use.
118
- */
119
- commands: CommandRegistry;
120
- }
121
- }
1
+ import { JSONObject } from '@phosphor/coreutils';
2
+ import { IDisposable } from '@phosphor/disposable';
3
+ import { CommandRegistry } from '@phosphor/commands';
4
+ import { ElementDataset } from '@phosphor/virtualdom';
5
+ /**
6
+ * A static class that provides helper methods to generate clickable nodes that
7
+ * execute registered commands with pre-populated arguments.
8
+ */
9
+ export declare class CommandLinker implements IDisposable {
10
+ /**
11
+ * Instantiate a new command linker.
12
+ */
13
+ constructor(options: CommandLinker.IOptions);
14
+ /**
15
+ * Test whether the linker is disposed.
16
+ */
17
+ readonly isDisposed: boolean;
18
+ /**
19
+ * Dispose of the resources held by the linker.
20
+ */
21
+ dispose(): void;
22
+ /**
23
+ * Connect a command/argument pair to a given node so that when it is clicked,
24
+ * the command will execute.
25
+ *
26
+ * @param node - The node being connected.
27
+ *
28
+ * @param command - The command ID to execute upon click.
29
+ *
30
+ * @param args - The arguments with which to invoke the command.
31
+ *
32
+ * @returns The same node that was passed in, after it has been connected.
33
+ *
34
+ * #### Notes
35
+ * Only `click` events will execute the command on a connected node. So, there
36
+ * are two considerations that are relevant:
37
+ * 1. If a node is connected, the default click action will be prevented.
38
+ * 2. The `HTMLElement` passed in should be clickable.
39
+ */
40
+ connectNode(node: HTMLElement, command: string, args?: JSONObject): HTMLElement;
41
+ /**
42
+ * Disconnect a node that has been connected to execute a command on click.
43
+ *
44
+ * @param node - The node being disconnected.
45
+ *
46
+ * @returns The same node that was passed in, after it has been disconnected.
47
+ *
48
+ * #### Notes
49
+ * This method is safe to call multiple times and is safe to call on nodes
50
+ * that were never connected.
51
+ *
52
+ * This method can be called on rendered virtual DOM nodes that were populated
53
+ * using the `populateVNodeDataset` method in order to disconnect them from
54
+ * executing their command/argument pair.
55
+ */
56
+ disconnectNode(node: HTMLElement): HTMLElement;
57
+ /**
58
+ * Handle the DOM events for the command linker helper class.
59
+ *
60
+ * @param event - The DOM event sent to the class.
61
+ *
62
+ * #### Notes
63
+ * This method implements the DOM `EventListener` interface and is
64
+ * called in response to events on the panel's DOM node. It should
65
+ * not be called directly by user code.
66
+ */
67
+ handleEvent(event: Event): void;
68
+ /**
69
+ * Populate the `dataset` attribute within the collection of attributes used
70
+ * to instantiate a virtual DOM node with the values necessary for its
71
+ * rendered DOM node to respond to clicks by executing a command/argument
72
+ * pair.
73
+ *
74
+ * @param command - The command ID to execute upon click.
75
+ *
76
+ * @param args - The arguments with which to invoke the command.
77
+ *
78
+ * @returns A `dataset` collection for use within virtual node attributes.
79
+ *
80
+ * #### Notes
81
+ * The return value can be used on its own as the value for the `dataset`
82
+ * attribute of a virtual element, or it can be added to an existing `dataset`
83
+ * as in the example below.
84
+ *
85
+ * #### Example
86
+ * ```typescript
87
+ * let command = 'some:command-id';
88
+ * let args = { alpha: 'beta' };
89
+ * let anchor = h.a({
90
+ * className: 'some-class',
91
+ * dataset: {
92
+ * foo: '1',
93
+ * bar: '2',
94
+ * ../...linker.populateVNodeDataset(command, args)
95
+ * }
96
+ * }, 'some text');
97
+ * ```
98
+ */
99
+ populateVNodeDataset(command: string, args?: JSONObject): ElementDataset;
100
+ /**
101
+ * The global click handler that deploys commands/argument pairs that are
102
+ * attached to the node being clicked.
103
+ */
104
+ private _evtClick;
105
+ private _commands;
106
+ private _isDisposed;
107
+ }
108
+ /**
109
+ * A namespace for command linker statics.
110
+ */
111
+ export declare namespace CommandLinker {
112
+ /**
113
+ * The instantiation options for a command linker.
114
+ */
115
+ interface IOptions {
116
+ /**
117
+ * The command registry instance that all linked commands will use.
118
+ */
119
+ commands: CommandRegistry;
120
+ }
121
+ }