villebro commented on code in PR #37499:
URL: https://github.com/apache/superset/pull/37499#discussion_r2734865421
##########
superset-frontend/packages/superset-core/src/api/contributions.ts:
##########
@@ -74,7 +74,34 @@ export interface ViewContribution {
}
/**
- * Aggregates all contributions (commands, menus, and views) provided by an
extension or module.
+ * Describes an editor that can be contributed to the application.
+ * Extensions declare editor contributions in their extension.json manifest.
+ */
+export interface EditorContribution {
+ /** Unique identifier for the editor (e.g., "acme.monaco-sql") */
+ id: string;
+ /** Display name of the editor */
+ name: string;
+ /** Languages this editor supports */
+ languages: EditorLanguage[];
+ /** Optional description of the editor */
+ description?: string;
+}
+
+/**
+ * Supported editor languages.
+ */
+export type EditorLanguage =
+ | 'sql'
+ | 'json'
+ | 'yaml'
+ | 'markdown'
+ | 'css'
+ | 'html'
+ | 'javascript';
Review Comment:
Not sure if this is in-scope, but for non-code text boxes, should we have a
"human language", too? In other words, should we make the default text box also
replaceable? There could be use cases where we the same features (autocomplete
etc) could make sense.
##########
superset-frontend/packages/superset-core/src/api/editors.ts:
##########
@@ -0,0 +1,381 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+/**
+ * @fileoverview Editors API for Superset extension editor contributions.
+ *
+ * This module defines the interfaces and types for editor contributions to the
+ * Superset platform. Extensions can register custom text editor
implementations
+ * (e.g., Monaco, CodeMirror) through the extension manifest, replacing the
+ * default Ace editor for specific languages.
+ */
+
+import { ForwardRefExoticComponent, RefAttributes } from 'react';
+import { EditorContribution, EditorLanguage } from './contributions';
+import { Disposable, Event } from './core';
+import type { SupersetTheme } from '../ui';
+
+// Re-export contribution types for convenience
+export type { EditorContribution, EditorLanguage };
+
+/**
+ * Represents a position in the editor (line and column).
+ */
+export interface Position {
+ /** Zero-based line number */
+ line: number;
+ /** Zero-based column number */
+ column: number;
+}
+
+/**
+ * Represents a range in the editor with start and end positions.
+ */
+export interface Range {
+ /** Start position of the range */
+ start: Position;
+ /** End position of the range */
+ end: Position;
+}
+
+/**
+ * Represents a selection in the editor.
+ */
+export interface Selection extends Range {
+ /** Direction of the selection */
+ direction?: 'ltr' | 'rtl';
Review Comment:
Is `rtl` already something we can support? I was assuming this may be
something that could require more extensive rearchitecting.
##########
superset-frontend/src/core/editors/AceEditorProvider.tsx:
##########
@@ -0,0 +1,322 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+/**
+ * @fileoverview Default Ace Editor provider implementation.
+ *
+ * This module wraps the existing Ace editor components to implement the
+ * standard EditorProps interface, serving as the default editor when no
+ * extension provides a custom implementation.
+ */
+
+import {
+ useRef,
+ useEffect,
+ useCallback,
+ useImperativeHandle,
+ forwardRef,
+ type Ref,
+} from 'react';
+import type AceEditor from 'react-ace';
+import type { editors } from '@apache-superset/core';
+import {
+ FullSQLEditor,
+ JsonEditor,
+ MarkdownEditor,
+ CssEditor,
+ ConfigEditor,
+ type AceCompleterKeyword,
+} from '@superset-ui/core/components';
+import { Disposable } from '../models';
+
+type EditorKeyword = editors.EditorKeyword;
+type EditorProps = editors.EditorProps;
+type EditorHandle = editors.EditorHandle;
+type Position = editors.Position;
+type Range = editors.Range;
+type Selection = editors.Selection;
+type EditorAnnotation = editors.EditorAnnotation;
+type CompletionProvider = editors.CompletionProvider;
+
+/**
+ * Maps EditorLanguage to the corresponding Ace editor component.
+ */
+const getEditorComponent = (language: string) => {
+ switch (language) {
+ case 'sql':
+ return FullSQLEditor;
+ case 'json':
+ return JsonEditor;
+ case 'markdown':
+ return MarkdownEditor;
+ case 'css':
+ return CssEditor;
+ case 'yaml':
+ return ConfigEditor;
+ default:
+ return FullSQLEditor;
Review Comment:
I noticed we have JS and TS editors as options in `EditorLanguage` - is
`FullSQLEditor` a good default option for those? If not should we consider
removing those for now from `EditorLanguage` until we have good default editors
for them?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]