@difizen/libro-code-editor 0.1.0 → 0.1.2

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.
Files changed (42) hide show
  1. package/es/code-editor-info-manager.d.ts +7 -0
  2. package/es/code-editor-info-manager.d.ts.map +1 -0
  3. package/es/code-editor-info-manager.js +32 -0
  4. package/es/code-editor-manager.d.ts +67 -0
  5. package/es/code-editor-manager.d.ts.map +1 -0
  6. package/es/code-editor-manager.js +130 -0
  7. package/es/{model.d.ts → code-editor-model.d.ts} +2 -2
  8. package/es/code-editor-model.d.ts.map +1 -0
  9. package/es/{model.js → code-editor-model.js} +1 -3
  10. package/es/{code-editor.d.ts → code-editor-protocol.d.ts} +70 -145
  11. package/es/code-editor-protocol.d.ts.map +1 -0
  12. package/es/{code-editor.js → code-editor-protocol.js} +17 -15
  13. package/es/code-editor-settings.d.ts +34 -0
  14. package/es/code-editor-settings.d.ts.map +1 -0
  15. package/es/code-editor-settings.js +225 -0
  16. package/es/code-editor-view.d.ts +26 -14
  17. package/es/code-editor-view.d.ts.map +1 -1
  18. package/es/code-editor-view.js +108 -72
  19. package/es/index.d.ts +5 -3
  20. package/es/index.d.ts.map +1 -1
  21. package/es/index.js +6 -4
  22. package/es/mimetype.d.ts.map +1 -1
  23. package/es/mimetype.js +3 -0
  24. package/es/module.d.ts.map +1 -1
  25. package/es/module.js +5 -2
  26. package/package.json +4 -5
  27. package/src/code-editor-info-manager.ts +25 -0
  28. package/src/code-editor-manager.ts +86 -0
  29. package/src/{model.ts → code-editor-model.ts} +4 -4
  30. package/src/{code-editor.ts → code-editor-protocol.ts} +136 -189
  31. package/src/code-editor-settings.ts +214 -0
  32. package/src/code-editor-view.tsx +93 -49
  33. package/src/index.spec.ts +1 -3
  34. package/src/index.ts +5 -3
  35. package/src/mimetype.ts +3 -0
  36. package/src/module.ts +13 -2
  37. package/es/code-editor.d.ts.map +0 -1
  38. package/es/completer/completer-protocol.d.ts +0 -210
  39. package/es/completer/completer-protocol.d.ts.map +0 -1
  40. package/es/completer/completer-protocol.js +0 -34
  41. package/es/model.d.ts.map +0 -1
  42. package/src/completer/completer-protocol.ts +0 -259
@@ -1,259 +0,0 @@
1
- import type { SourceChange } from '@difizen/libro-shared-model';
2
- import { Syringe } from '@difizen/mana-app';
3
- import type { View } from '@difizen/mana-app';
4
- import type { Event } from '@difizen/mana-app';
5
- import type React from 'react';
6
-
7
- import type { IEditor } from '../code-editor.js';
8
-
9
- /**
10
- * The context which will be passed to the `fetch` function
11
- * of a provider.
12
- */
13
- export interface CompletionContext {
14
- /**
15
- * The widget (notebook, console, code editor) which invoked
16
- * the completer
17
- */
18
- widget: View;
19
-
20
- /**
21
- * The current editor.
22
- */
23
- editor?: IEditor | null;
24
-
25
- /**
26
- * The session extracted from widget for convenience.
27
- */
28
- // session?: ISessionConnection | null;
29
- }
30
-
31
- /**
32
- * An object describing a completion option injection into text.
33
- */
34
- export interface IPatch {
35
- /**
36
- * The start of the range to be patched.
37
- */
38
- start: number;
39
-
40
- /**
41
- * The end of the range to be patched.
42
- */
43
- end: number;
44
-
45
- /**
46
- * The value to be patched in.
47
- */
48
- value: string;
49
- }
50
-
51
- /**
52
- * Completion item object based off of LSP CompletionItem.
53
- * Compared to the old kernel completions interface, this enhances the completions UI to support:
54
- * - differentiation between inserted text and user facing text
55
- * - documentation for each completion item to be displayed adjacently
56
- * - deprecation styling
57
- * - custom icons
58
- * and other potential new features.
59
- */
60
- export interface ICompletionItem {
61
- /**
62
- * User facing completion.
63
- * If insertText is not set, this will be inserted.
64
- */
65
- label: string;
66
-
67
- /**
68
- * Completion to be inserted.
69
- */
70
- insertText?: string;
71
-
72
- /**
73
- * Type of this completion item.
74
- */
75
- type?: string;
76
-
77
- /**
78
- * LabIcon object for icon to be rendered with completion type.
79
- */
80
- icon?: React.ReactNode;
81
-
82
- /**
83
- * A human-readable string with additional information
84
- * about this item, like type or symbol information.
85
- */
86
- documentation?: string;
87
-
88
- /**
89
- * Indicates if the item is deprecated.
90
- */
91
- deprecated?: boolean;
92
-
93
- resolve?: (patch?: IPatch) => Promise<ICompletionItem>;
94
- }
95
-
96
- /**
97
- * A reply to a completion items fetch request.
98
- */
99
- export interface ICompletionItemsReply<T extends ICompletionItem = ICompletionItem> {
100
- /**
101
- * The starting index for the substring being replaced by completion.
102
- */
103
- start: number;
104
- /**
105
- * The end index for the substring being replaced by completion.
106
- */
107
- end: number;
108
- /**
109
- * A list of completion items. default to CompletionHandler.ICompletionItems
110
- */
111
- items: T[];
112
- }
113
-
114
- /**
115
- * The details of a completion request.
116
- */
117
- export interface IRequest {
118
- /**
119
- * The cursor offset position within the text being completed.
120
- */
121
- offset: number;
122
-
123
- /**
124
- * The text being completed.
125
- */
126
- text: string;
127
- }
128
-
129
- export const CompletionProvider = new Syringe.DefinedToken('CompletionProvider');
130
-
131
- /**
132
- * The interface to implement a completer provider.
133
- */
134
- export interface CompletionProvider<T extends ICompletionItem = ICompletionItem> {
135
- /**
136
- * Unique identifier of the provider
137
- */
138
- readonly identifier: string;
139
-
140
- /**
141
- * Renderer for provider's completions (optional).
142
- */
143
- // readonly renderer?: Completer.IRenderer | null;
144
-
145
- /**
146
- * Is completion provider applicable to specified context?
147
- * @param request - the completion request text and details
148
- * @param context - additional information about context of completion request
149
- */
150
- isApplicable: (context: CompletionContext) => Promise<boolean>;
151
-
152
- /**
153
- * Fetch completion requests.
154
- *
155
- * @param request - the completion request text and details
156
- * @param context - additional information about context of completion request
157
- */
158
- fetch: (
159
- request: IRequest,
160
- context: CompletionContext,
161
- ) => Promise<ICompletionItemsReply<T>>;
162
-
163
- /**
164
- * This method is called to customize the model of a completer widget.
165
- * If it is not provided, the default model will be used.
166
- *
167
- * @param context - additional information about context of completion request
168
- * @returns The completer model
169
- */
170
- modelFactory?: (context: CompletionContext) => Promise<Record<string, any>>;
171
-
172
- /**
173
- * Given an incomplete (unresolved) completion item, resolve it by adding
174
- * all missing details, such as lazy-fetched documentation.
175
- *
176
- * @param completion - the completion item to resolve
177
- * @param context - The context of the completer
178
- * @param patch - The text which will be injected if the completion item is
179
- * selected.
180
- */
181
- resolve?: (
182
- completionItem: T,
183
- context: CompletionContext,
184
- patch?: IPatch | null,
185
- ) => Promise<T>;
186
-
187
- /**
188
- * If users enable `autoCompletion` in setting, this method is
189
- * called on text changed event of `CodeMirror` to check if the
190
- * completion items should be shown.
191
- *
192
- * @param completerIsVisible - Current visibility status of the
193
- * completer widget0
194
- * @param changed - changed text.
195
- */
196
- shouldShowContinuousHint?: (
197
- completerIsVisible: boolean,
198
- changed: SourceChange,
199
- ) => boolean;
200
- }
201
-
202
- export interface ICompletionProviderManager {
203
- /**
204
- * Register a completer provider with the manager.
205
- *
206
- * @param {CompletionProvider} provider - the provider to be registered.
207
- */
208
- registerProvider: (provider: CompletionProvider) => void;
209
-
210
- /**
211
- * Invoke the completer in the widget with provided id.
212
- *
213
- * @param {string} id - the id of notebook panel, console panel or code editor.
214
- */
215
- invoke: (id: string) => void;
216
-
217
- /**
218
- * Activate `select` command in the widget with provided id.
219
- *
220
- * @param {string} id - the id of notebook panel, console panel or code editor.
221
- */
222
- select: (id: string) => void;
223
-
224
- /**
225
- * Update completer handler of a widget with new context.
226
- *
227
- * @param newCompleterContext - The completion context.
228
- */
229
- updateCompleter: (newCompleterContext: CompletionContext) => Promise<void>;
230
-
231
- /**
232
- * Signal emitted when active providers list is changed.
233
- */
234
- activeProvidersChanged: Event<void>;
235
- }
236
-
237
- export interface IConnectorProxy {
238
- /**
239
- * Fetch response from multiple providers, If a provider can not return
240
- * the response for a completer request before timeout,
241
- * the result of this provider will be ignore.
242
- *
243
- * @param {CompletionHandler.IRequest} request - The completion request.
244
- */
245
- fetch: (request: IRequest) => Promise<(ICompletionItemsReply | null)[]>;
246
-
247
- /**
248
- * Check if completer should make request to fetch completion responses
249
- * on user typing. If the provider with highest rank does not have
250
- * `shouldShowContinuousHint` method, a default one will be used.
251
- *
252
- * @param completerIsVisible - The visible status of completer widget.
253
- * @param changed - CodeMirror changed argument.
254
- */
255
- shouldShowContinuousHint: (
256
- completerIsVisible: boolean,
257
- changed: SourceChange,
258
- ) => boolean;
259
- }