@difizen/libro-code-editor 0.0.2-alpha.0

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.
@@ -0,0 +1,210 @@
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
+ import type { IEditor } from '../code-editor.js';
7
+ /**
8
+ * The context which will be passed to the `fetch` function
9
+ * of a provider.
10
+ */
11
+ export interface CompletionContext {
12
+ /**
13
+ * The widget (notebook, console, code editor) which invoked
14
+ * the completer
15
+ */
16
+ widget: View;
17
+ /**
18
+ * The current editor.
19
+ */
20
+ editor?: IEditor | null;
21
+ }
22
+ /**
23
+ * An object describing a completion option injection into text.
24
+ */
25
+ export interface IPatch {
26
+ /**
27
+ * The start of the range to be patched.
28
+ */
29
+ start: number;
30
+ /**
31
+ * The end of the range to be patched.
32
+ */
33
+ end: number;
34
+ /**
35
+ * The value to be patched in.
36
+ */
37
+ value: string;
38
+ }
39
+ /**
40
+ * Completion item object based off of LSP CompletionItem.
41
+ * Compared to the old kernel completions interface, this enhances the completions UI to support:
42
+ * - differentiation between inserted text and user facing text
43
+ * - documentation for each completion item to be displayed adjacently
44
+ * - deprecation styling
45
+ * - custom icons
46
+ * and other potential new features.
47
+ */
48
+ export interface ICompletionItem {
49
+ /**
50
+ * User facing completion.
51
+ * If insertText is not set, this will be inserted.
52
+ */
53
+ label: string;
54
+ /**
55
+ * Completion to be inserted.
56
+ */
57
+ insertText?: string;
58
+ /**
59
+ * Type of this completion item.
60
+ */
61
+ type?: string;
62
+ /**
63
+ * LabIcon object for icon to be rendered with completion type.
64
+ */
65
+ icon?: React.ReactNode;
66
+ /**
67
+ * A human-readable string with additional information
68
+ * about this item, like type or symbol information.
69
+ */
70
+ documentation?: string;
71
+ /**
72
+ * Indicates if the item is deprecated.
73
+ */
74
+ deprecated?: boolean;
75
+ resolve?: (patch?: IPatch) => Promise<ICompletionItem>;
76
+ }
77
+ /**
78
+ * A reply to a completion items fetch request.
79
+ */
80
+ export interface ICompletionItemsReply<T extends ICompletionItem = ICompletionItem> {
81
+ /**
82
+ * The starting index for the substring being replaced by completion.
83
+ */
84
+ start: number;
85
+ /**
86
+ * The end index for the substring being replaced by completion.
87
+ */
88
+ end: number;
89
+ /**
90
+ * A list of completion items. default to CompletionHandler.ICompletionItems
91
+ */
92
+ items: T[];
93
+ }
94
+ /**
95
+ * The details of a completion request.
96
+ */
97
+ export interface IRequest {
98
+ /**
99
+ * The cursor offset position within the text being completed.
100
+ */
101
+ offset: number;
102
+ /**
103
+ * The text being completed.
104
+ */
105
+ text: string;
106
+ }
107
+ export declare const CompletionProvider: Syringe.DefinedToken;
108
+ /**
109
+ * The interface to implement a completer provider.
110
+ */
111
+ export interface CompletionProvider<T extends ICompletionItem = ICompletionItem> {
112
+ /**
113
+ * Unique identifier of the provider
114
+ */
115
+ readonly identifier: string;
116
+ /**
117
+ * Renderer for provider's completions (optional).
118
+ */
119
+ /**
120
+ * Is completion provider applicable to specified context?
121
+ * @param request - the completion request text and details
122
+ * @param context - additional information about context of completion request
123
+ */
124
+ isApplicable: (context: CompletionContext) => Promise<boolean>;
125
+ /**
126
+ * Fetch completion requests.
127
+ *
128
+ * @param request - the completion request text and details
129
+ * @param context - additional information about context of completion request
130
+ */
131
+ fetch: (request: IRequest, context: CompletionContext) => Promise<ICompletionItemsReply<T>>;
132
+ /**
133
+ * This method is called to customize the model of a completer widget.
134
+ * If it is not provided, the default model will be used.
135
+ *
136
+ * @param context - additional information about context of completion request
137
+ * @returns The completer model
138
+ */
139
+ modelFactory?: (context: CompletionContext) => Promise<Record<string, any>>;
140
+ /**
141
+ * Given an incomplete (unresolved) completion item, resolve it by adding
142
+ * all missing details, such as lazy-fetched documentation.
143
+ *
144
+ * @param completion - the completion item to resolve
145
+ * @param context - The context of the completer
146
+ * @param patch - The text which will be injected if the completion item is
147
+ * selected.
148
+ */
149
+ resolve?: (completionItem: T, context: CompletionContext, patch?: IPatch | null) => Promise<T>;
150
+ /**
151
+ * If users enable `autoCompletion` in setting, this method is
152
+ * called on text changed event of `CodeMirror` to check if the
153
+ * completion items should be shown.
154
+ *
155
+ * @param completerIsVisible - Current visibility status of the
156
+ * completer widget0
157
+ * @param changed - changed text.
158
+ */
159
+ shouldShowContinuousHint?: (completerIsVisible: boolean, changed: SourceChange) => boolean;
160
+ }
161
+ export interface ICompletionProviderManager {
162
+ /**
163
+ * Register a completer provider with the manager.
164
+ *
165
+ * @param {CompletionProvider} provider - the provider to be registered.
166
+ */
167
+ registerProvider: (provider: CompletionProvider) => void;
168
+ /**
169
+ * Invoke the completer in the widget with provided id.
170
+ *
171
+ * @param {string} id - the id of notebook panel, console panel or code editor.
172
+ */
173
+ invoke: (id: string) => void;
174
+ /**
175
+ * Activate `select` command in the widget with provided id.
176
+ *
177
+ * @param {string} id - the id of notebook panel, console panel or code editor.
178
+ */
179
+ select: (id: string) => void;
180
+ /**
181
+ * Update completer handler of a widget with new context.
182
+ *
183
+ * @param newCompleterContext - The completion context.
184
+ */
185
+ updateCompleter: (newCompleterContext: CompletionContext) => Promise<void>;
186
+ /**
187
+ * Signal emitted when active providers list is changed.
188
+ */
189
+ activeProvidersChanged: Event<void>;
190
+ }
191
+ export interface IConnectorProxy {
192
+ /**
193
+ * Fetch response from multiple providers, If a provider can not return
194
+ * the response for a completer request before timeout,
195
+ * the result of this provider will be ignore.
196
+ *
197
+ * @param {CompletionHandler.IRequest} request - The completion request.
198
+ */
199
+ fetch: (request: IRequest) => Promise<(ICompletionItemsReply | null)[]>;
200
+ /**
201
+ * Check if completer should make request to fetch completion responses
202
+ * on user typing. If the provider with highest rank does not have
203
+ * `shouldShowContinuousHint` method, a default one will be used.
204
+ *
205
+ * @param completerIsVisible - The visible status of completer widget.
206
+ * @param changed - CodeMirror changed argument.
207
+ */
208
+ shouldShowContinuousHint: (completerIsVisible: boolean, changed: SourceChange) => boolean;
209
+ }
210
+ //# sourceMappingURL=completer-protocol.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"completer-protocol.d.ts","sourceRoot":"","sources":["../../src/completer/completer-protocol.ts"],"names":[],"mappings":"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"}
@@ -0,0 +1,34 @@
1
+ import { Syringe } from '@difizen/mana-app';
2
+
3
+ /**
4
+ * The context which will be passed to the `fetch` function
5
+ * of a provider.
6
+ */
7
+
8
+ /**
9
+ * An object describing a completion option injection into text.
10
+ */
11
+
12
+ /**
13
+ * Completion item object based off of LSP CompletionItem.
14
+ * Compared to the old kernel completions interface, this enhances the completions UI to support:
15
+ * - differentiation between inserted text and user facing text
16
+ * - documentation for each completion item to be displayed adjacently
17
+ * - deprecation styling
18
+ * - custom icons
19
+ * and other potential new features.
20
+ */
21
+
22
+ /**
23
+ * A reply to a completion items fetch request.
24
+ */
25
+
26
+ /**
27
+ * The details of a completion request.
28
+ */
29
+
30
+ export var CompletionProvider = new Syringe.DefinedToken('CompletionProvider');
31
+
32
+ /**
33
+ * The interface to implement a completer provider.
34
+ */
package/es/index.d.ts ADDED
@@ -0,0 +1,6 @@
1
+ export * from './code-editor.js';
2
+ export * from './mimetype.js';
3
+ export * from './code-editor-view.js';
4
+ export * from './module.js';
5
+ export * from './model.js';
6
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,kBAAkB,CAAC;AACjC,cAAc,eAAe,CAAC;AAC9B,cAAc,uBAAuB,CAAC;AACtC,cAAc,aAAa,CAAC;AAC5B,cAAc,YAAY,CAAC"}
package/es/index.js ADDED
@@ -0,0 +1,5 @@
1
+ export * from "./code-editor.js";
2
+ export * from "./mimetype.js";
3
+ export * from "./code-editor-view.js";
4
+ export * from "./module.js";
5
+ export * from "./model.js";
@@ -0,0 +1,33 @@
1
+ import type { ILanguageInfoMetadata } from '@difizen/libro-common';
2
+ /**
3
+ * The mime type service of a code editor.
4
+ */
5
+ export interface IEditorMimeTypeService {
6
+ /**
7
+ * Get a mime type for the given language info.
8
+ *
9
+ * @param info - The language information.
10
+ *
11
+ * @returns A valid mimetype.
12
+ *
13
+ * #### Notes
14
+ * If a mime type cannot be found returns the default mime type `text/plain`, never `null`.
15
+ */
16
+ getMimeTypeByLanguage: (info: ILanguageInfoMetadata) => string;
17
+ /**
18
+ * Get a mime type for the given file path.
19
+ *
20
+ * @param filePath - The full path to the file.
21
+ *
22
+ * @returns A valid mimetype.
23
+ *
24
+ * #### Notes
25
+ * If a mime type cannot be found returns the default mime type `text/plain`, never `null`.
26
+ */
27
+ getMimeTypeByFilePath: (filePath: string) => string;
28
+ }
29
+ /**
30
+ * The default mime type.
31
+ */
32
+ export declare const defaultMimeType = "text/plain";
33
+ //# sourceMappingURL=mimetype.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mimetype.d.ts","sourceRoot":"","sources":["../src/mimetype.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,uBAAuB,CAAC;AAEnE;;GAEG;AACH,MAAM,WAAW,sBAAsB;IACrC;;;;;;;;;OASG;IACH,qBAAqB,EAAE,CAAC,IAAI,EAAE,qBAAqB,KAAK,MAAM,CAAC;IAC/D;;;;;;;;;OASG;IACH,qBAAqB,EAAE,CAAC,QAAQ,EAAE,MAAM,KAAK,MAAM,CAAC;CACrD;AAED;;GAEG;AACH,eAAO,MAAM,eAAe,eAAe,CAAC"}
package/es/mimetype.js ADDED
@@ -0,0 +1,8 @@
1
+ /**
2
+ * The mime type service of a code editor.
3
+ */
4
+
5
+ /**
6
+ * The default mime type.
7
+ */
8
+ export var defaultMimeType = 'text/plain';
package/es/model.d.ts ADDED
@@ -0,0 +1,80 @@
1
+ import type { CellType } from '@difizen/libro-common';
2
+ import type { Disposable, Event } from '@difizen/mana-app';
3
+ import { Emitter } from '@difizen/mana-app';
4
+ import type { ITextSelection } from './code-editor.js';
5
+ export interface IModelOptions {
6
+ /**
7
+ * A unique identifier for the model.
8
+ */
9
+ id?: string;
10
+ /**
11
+ * The initial value of the model.
12
+ */
13
+ value?: string;
14
+ /**
15
+ * The mimetype of the model.
16
+ */
17
+ mimeType?: string;
18
+ }
19
+ /**
20
+ * An editor model.
21
+ */
22
+ export interface IModel extends Disposable {
23
+ /**
24
+ * The text stored in the model.
25
+ */
26
+ value: string;
27
+ /**
28
+ * A mime type of the model.
29
+ *
30
+ * #### Notes
31
+ * It is never `null`, the default mime type is `text/plain`.
32
+ */
33
+ mimeType: string;
34
+ /**
35
+ * The currently selected code.
36
+ */
37
+ selections: ITextSelection[];
38
+ }
39
+ /**
40
+ * The default implementation of the editor model.
41
+ */
42
+ export declare class Model implements IModel {
43
+ id: string;
44
+ /**
45
+ * The text stored in the model.
46
+ */
47
+ value: string;
48
+ /**
49
+ * A mime type of the model.
50
+ *
51
+ * #### Notes
52
+ * It is never `null`, the default mime type is `text/plain`.
53
+ */
54
+ mimeType: string;
55
+ type: CellType;
56
+ /**
57
+ * The currently selected code.
58
+ */
59
+ selections: ITextSelection[];
60
+ /**
61
+ * Construct a new Model.
62
+ */
63
+ constructor(options?: IModelOptions);
64
+ /**
65
+ * A signal emitted when the shared model was switched.
66
+ */
67
+ get sharedModelSwitched(): Event<boolean>;
68
+ /**
69
+ * Whether the model is disposed.
70
+ */
71
+ get isDisposed(): boolean;
72
+ /**
73
+ * Dispose of the resources used by the model.
74
+ */
75
+ dispose(): void;
76
+ protected _isDisposed: boolean;
77
+ protected _sharedModelSwitchedEmitter: Emitter<boolean>;
78
+ protected _sharedModelSwitched: Event<boolean>;
79
+ }
80
+ //# sourceMappingURL=model.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"model.d.ts","sourceRoot":"","sources":["../src/model.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AACtD,OAAO,KAAK,EAAE,UAAU,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAE3D,OAAO,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAI5C,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAEvD,MAAM,WAAW,aAAa;IAC5B;;OAEG;IACH,EAAE,CAAC,EAAE,MAAM,CAAC;IAEZ;;OAEG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;IAEf;;OAEG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED;;GAEG;AACH,MAAM,WAAW,MAAO,SAAQ,UAAU;IACxC;;OAEG;IACH,KAAK,EAAE,MAAM,CAAC;IAEd;;;;;OAKG;IACH,QAAQ,EAAE,MAAM,CAAC;IAEjB;;OAEG;IACH,UAAU,EAAE,cAAc,EAAE,CAAC;CAC9B;AAED;;GAEG;AACH,qBACa,KAAM,YAAW,MAAM;IAClC,EAAE,EAAE,MAAM,CAAC;IACX;;OAEG;IAEH,KAAK,EAAE,MAAM,CAAC;IAEd;;;;;OAKG;IAEH,QAAQ,EAAE,MAAM,CAAC;IAGjB,IAAI,EAAE,QAAQ,CAAU;IAExB;;OAEG;IAEH,UAAU,EAAE,cAAc,EAAE,CAAC;IAE7B;;OAEG;gBACS,OAAO,CAAC,EAAE,aAAa;IASnC;;OAEG;IACH,IAAI,mBAAmB,IAAI,KAAK,CAAC,OAAO,CAAC,CAExC;IAED;;OAEG;IACH,IAAI,UAAU,IAAI,OAAO,CAExB;IAED;;OAEG;IACH,OAAO,IAAI,IAAI;IAOf,SAAS,CAAC,WAAW,UAAS;IAE9B,SAAS,CAAC,2BAA2B,mBAA0B;IAC/D,SAAS,CAAC,oBAAoB,iBAA0C;CACzE"}
package/es/model.js ADDED
@@ -0,0 +1,110 @@
1
+ function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
2
+ var _dec, _dec2, _dec3, _dec4, _dec5, _class, _class2, _descriptor, _descriptor2, _descriptor3, _descriptor4;
3
+ function _initializerDefineProperty(target, property, descriptor, context) { if (!descriptor) return; Object.defineProperty(target, property, { enumerable: descriptor.enumerable, configurable: descriptor.configurable, writable: descriptor.writable, value: descriptor.initializer ? descriptor.initializer.call(context) : void 0 }); }
4
+ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
5
+ function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
6
+ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
7
+ function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
8
+ function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
9
+ function _applyDecoratedDescriptor(target, property, decorators, descriptor, context) { var desc = {}; Object.keys(descriptor).forEach(function (key) { desc[key] = descriptor[key]; }); desc.enumerable = !!desc.enumerable; desc.configurable = !!desc.configurable; if ('value' in desc || desc.initializer) { desc.writable = true; } desc = decorators.slice().reverse().reduce(function (desc, decorator) { return decorator(target, property, desc) || desc; }, desc); if (context && desc.initializer !== void 0) { desc.value = desc.initializer ? desc.initializer.call(context) : void 0; desc.initializer = undefined; } if (desc.initializer === void 0) { Object.defineProperty(target, property, desc); desc = null; } return desc; }
10
+ function _initializerWarningHelper(descriptor, context) { throw new Error('Decorating class property failed. Please ensure that ' + 'transform-class-properties is enabled and runs after the decorators transform.'); }
11
+ import { prop } from '@difizen/mana-app';
12
+ import { Emitter } from '@difizen/mana-app';
13
+ import { transient } from '@difizen/mana-app';
14
+ import { v4 } from 'uuid';
15
+
16
+ /**
17
+ * An editor model.
18
+ */
19
+
20
+ /**
21
+ * The default implementation of the editor model.
22
+ */
23
+ export var Model = (_dec = transient(), _dec2 = prop(), _dec3 = prop(), _dec4 = prop(), _dec5 = prop(), _dec(_class = (_class2 = /*#__PURE__*/function () {
24
+ /**
25
+ * Construct a new Model.
26
+ */
27
+ function Model(options) {
28
+ var _options$id, _options$value, _options$mimeType;
29
+ _classCallCheck(this, Model);
30
+ /**
31
+ * The text stored in the model.
32
+ */
33
+ _initializerDefineProperty(this, "value", _descriptor, this);
34
+ /**
35
+ * A mime type of the model.
36
+ *
37
+ * #### Notes
38
+ * It is never `null`, the default mime type is `text/plain`.
39
+ */
40
+ _initializerDefineProperty(this, "mimeType", _descriptor2, this);
41
+ _initializerDefineProperty(this, "type", _descriptor3, this);
42
+ /**
43
+ * The currently selected code.
44
+ */
45
+ _initializerDefineProperty(this, "selections", _descriptor4, this);
46
+ this._isDisposed = false;
47
+ this._sharedModelSwitchedEmitter = new Emitter();
48
+ this._sharedModelSwitched = this._sharedModelSwitchedEmitter.event;
49
+ // this.sharedModel = models.createStandaloneCell(this.type, options.id) as models.ISharedText;
50
+ // this.sharedModel.changed.connect(this._onSharedModelChanged, this);
51
+ this.id = (_options$id = options === null || options === void 0 ? void 0 : options.id) !== null && _options$id !== void 0 ? _options$id : v4();
52
+ this.value = (_options$value = options === null || options === void 0 ? void 0 : options.value) !== null && _options$value !== void 0 ? _options$value : '';
53
+ this.mimeType = (_options$mimeType = options === null || options === void 0 ? void 0 : options.mimeType) !== null && _options$mimeType !== void 0 ? _options$mimeType : 'text/plain';
54
+ this.selections = [];
55
+ }
56
+
57
+ /**
58
+ * A signal emitted when the shared model was switched.
59
+ */
60
+ _createClass(Model, [{
61
+ key: "sharedModelSwitched",
62
+ get: function get() {
63
+ return this._sharedModelSwitched;
64
+ }
65
+
66
+ /**
67
+ * Whether the model is disposed.
68
+ */
69
+ }, {
70
+ key: "isDisposed",
71
+ get: function get() {
72
+ return this._isDisposed;
73
+ }
74
+
75
+ /**
76
+ * Dispose of the resources used by the model.
77
+ */
78
+ }, {
79
+ key: "dispose",
80
+ value: function dispose() {
81
+ if (this._isDisposed) {
82
+ return;
83
+ }
84
+ this._isDisposed = true;
85
+ }
86
+ }]);
87
+ return Model;
88
+ }(), (_descriptor = _applyDecoratedDescriptor(_class2.prototype, "value", [_dec2], {
89
+ configurable: true,
90
+ enumerable: true,
91
+ writable: true,
92
+ initializer: null
93
+ }), _descriptor2 = _applyDecoratedDescriptor(_class2.prototype, "mimeType", [_dec3], {
94
+ configurable: true,
95
+ enumerable: true,
96
+ writable: true,
97
+ initializer: null
98
+ }), _descriptor3 = _applyDecoratedDescriptor(_class2.prototype, "type", [_dec4], {
99
+ configurable: true,
100
+ enumerable: true,
101
+ writable: true,
102
+ initializer: function initializer() {
103
+ return 'code';
104
+ }
105
+ }), _descriptor4 = _applyDecoratedDescriptor(_class2.prototype, "selections", [_dec5], {
106
+ configurable: true,
107
+ enumerable: true,
108
+ writable: true,
109
+ initializer: null
110
+ })), _class2)) || _class);
package/es/module.d.ts ADDED
@@ -0,0 +1,3 @@
1
+ import { ManaModule } from '@difizen/mana-app';
2
+ export declare const CodeEditorModule: ManaModule;
3
+ //# sourceMappingURL=module.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"module.d.ts","sourceRoot":"","sources":["../src/module.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAK/C,eAAO,MAAM,gBAAgB,YAAsD,CAAC"}
package/es/module.js ADDED
@@ -0,0 +1,4 @@
1
+ import { ManaModule } from '@difizen/mana-app';
2
+ import { CodeEditorView } from "./code-editor-view.js";
3
+ import { Model } from "./model.js";
4
+ export var CodeEditorModule = ManaModule.create().register(CodeEditorView, Model);
package/package.json ADDED
@@ -0,0 +1,61 @@
1
+ {
2
+ "name": "@difizen/libro-code-editor",
3
+ "version": "0.0.2-alpha.0",
4
+ "description": "",
5
+ "keywords": [
6
+ "libro",
7
+ "notebook"
8
+ ],
9
+ "repository": "git@github.com:difizen/libro.git",
10
+ "license": "MIT",
11
+ "type": "module",
12
+ "exports": {
13
+ ".": {
14
+ "typings": "./es/index.d.ts",
15
+ "default": "./es/index.js"
16
+ },
17
+ "./mock": {
18
+ "typings": "./es/mock/index.d.ts",
19
+ "default": "./es/mock/index.js"
20
+ },
21
+ "./es/mock": {
22
+ "typings": "./es/mock/index.d.ts",
23
+ "default": "./es/mock/index.js"
24
+ },
25
+ "./package.json": "./package.json"
26
+ },
27
+ "main": "es/index.js",
28
+ "module": "es/index.js",
29
+ "typings": "es/index.d.ts",
30
+ "files": [
31
+ "es",
32
+ "src"
33
+ ],
34
+ "dependencies": {
35
+ "@difizen/mana-app": "alpha",
36
+ "@difizen/libro-common": "^0.0.2-alpha.0",
37
+ "@difizen/libro-shared-model": "^0.0.2-alpha.0",
38
+ "uuid": "^9.0.0",
39
+ "vscode-languageserver-protocol": "^3.17.0"
40
+ },
41
+ "peerDependencies": {
42
+ "react": "^18.2.0"
43
+ },
44
+ "devDependencies": {
45
+ "@types/react": "^18.2.25",
46
+ "@types/uuid": "^8.3.4"
47
+ },
48
+ "scripts": {
49
+ "setup": "father build",
50
+ "build": "father build",
51
+ "test": ": Note: lint task is delegated to test:* scripts",
52
+ "test:vitest": "vitest run",
53
+ "test:jest": "jest",
54
+ "coverage": ": Note: lint task is delegated to coverage:* scripts",
55
+ "coverage:vitest": "vitest run --coverage",
56
+ "coverage:jest": "jest --coverage",
57
+ "lint": ": Note: lint task is delegated to lint:* scripts",
58
+ "lint:eslint": "eslint src",
59
+ "lint:tsc": "tsc --noEmit"
60
+ }
61
+ }