Skip to content

Commit 24547c6

Browse files
feat(module:code-editor): support standalone component (#8268)
1 parent ae6ceeb commit 24547c6

4 files changed

Lines changed: 48 additions & 51 deletions

File tree

‎components/code-editor/code-editor.component.ts‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
*/
55

66
import { Platform } from '@angular/cdk/platform';
7+
import { NgIf, NgTemplateOutlet } from '@angular/common';
78
import {
89
AfterViewInit,
910
ChangeDetectionStrategy,
@@ -27,6 +28,7 @@ import type { editor, IDisposable } from 'monaco-editor';
2728
import { warn } from 'ng-zorro-antd/core/logger';
2829
import { BooleanInput, NzSafeAny, OnChangeType, OnTouchedType } from 'ng-zorro-antd/core/types';
2930
import { inNextTick, InputBoolean } from 'ng-zorro-antd/core/util';
31+
import { NzSpinComponent } from 'ng-zorro-antd/spin';
3032

3133
import { NzCodeEditorService } from './code-editor.service';
3234
import { DiffEditorOptions, EditorOptions, JoinedEditorOptions, NzEditorMode } from './typings';
@@ -58,7 +60,9 @@ declare const monaco: NzSafeAny;
5860
useExisting: forwardRef(() => NzCodeEditorComponent),
5961
multi: true
6062
}
61-
]
63+
],
64+
imports: [NgIf, NzSpinComponent, NgTemplateOutlet],
65+
standalone: true
6266
})
6367
export class NzCodeEditorComponent implements OnDestroy, AfterViewInit {
6468
static ngAcceptInputType_nzLoading: BooleanInput;

‎components/code-editor/code-editor.module.ts‎

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,12 @@
33
* found in the LICENSE file at https://github.com/NG-ZORRO/ng-zorro-antd/blob/master/LICENSE
44
*/
55

6-
import { CommonModule } from '@angular/common';
76
import { NgModule } from '@angular/core';
87

9-
import { NzIconModule } from 'ng-zorro-antd/icon';
10-
import { NzSpinModule } from 'ng-zorro-antd/spin';
11-
128
import { NzCodeEditorComponent } from './code-editor.component';
139

1410
@NgModule({
15-
declarations: [NzCodeEditorComponent],
16-
imports: [CommonModule, NzIconModule, NzSpinModule],
11+
imports: [NzCodeEditorComponent],
1712
exports: [NzCodeEditorComponent]
1813
})
1914
export class NzCodeEditorModule {}

‎components/code-editor/doc/index.en-US.md‎

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import { NzCodeEditorModule } from 'ng-zorro-antd/code-editor';
2424
### Import Style
2525

2626
```less
27-
@import "node_modules/ng-zorro-antd/code-editor/style/entry.less"
27+
@import 'node_modules/ng-zorro-antd/code-editor/style/entry.less';
2828
```
2929

3030
## API
@@ -65,22 +65,22 @@ With help of [monaco-editor-webpack-plguin](https://github.com/microsoft/monaco-
6565

6666
If you use static loading, you should not add assets of monaco editor to your project by modifying angular.json file.
6767

68-
### nz-code-editor
68+
### nz-code-editor:standalone
6969

70-
| Parameter | Description | Type | Default |
71-
| --- | --- | --- | --- |
72-
| `[nzEditorMode]` | Mode of monaco editor | `normal`\|`diff` | `normal` |
73-
| `[nzLoading]` | Show the loading spin | `boolean` | `false` |
74-
| `[nzOriginalText]` | The content of the left editor in `diff` mode | `boolean` | `false` |
75-
| `[nzFullControl]` | Enable full control mode. User should manage `TextModel` manually in this mode | `boolean` | `false` |
76-
| `[nzEditorOption]` | [Please refer to the doc of monaco editor](https://microsoft.github.io/monaco-editor/api/interfaces/monaco.editor.ieditorconstructionoptions.html) | `IEditorConstructionOptions` | `{}` |
77-
| `[nzToolkit]` | A placeholder for adding some quick actions | `TemplateRef<void>` | - |
78-
| `(nzEditorInitialized)` | The event that a code editor is initialized | `IStandaloneCodeEditor` \| `IStandaloneDiffEditor` | - |
70+
| Parameter | Description | Type | Default |
71+
| ----------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------- | -------- |
72+
| `[nzEditorMode]` | Mode of monaco editor | `normal`\|`diff` | `normal` |
73+
| `[nzLoading]` | Show the loading spin | `boolean` | `false` |
74+
| `[nzOriginalText]` | The content of the left editor in `diff` mode | `boolean` | `false` |
75+
| `[nzFullControl]` | Enable full control mode. User should manage `TextModel` manually in this mode | `boolean` | `false` |
76+
| `[nzEditorOption]` | [Please refer to the doc of monaco editor](https://microsoft.github.io/monaco-editor/api/interfaces/monaco.editor.ieditorconstructionoptions.html) | `IEditorConstructionOptions` | `{}` |
77+
| `[nzToolkit]` | A placeholder for adding some quick actions | `TemplateRef<void>` | - |
78+
| `(nzEditorInitialized)` | The event that a code editor is initialized | `IStandaloneCodeEditor` \| `IStandaloneDiffEditor` | - |
7979

8080
#### Methods
8181

82-
| Method | Description |
83-
| --- | --- |
82+
| Method | Description |
83+
| ---------- | --------------------------------------- |
8484
| `layout()` | Force monaco editor to re-render itself |
8585

8686
### Global Configuration
@@ -89,11 +89,11 @@ You can set the default configuration of the `CodeEditor` component through the
8989

9090
#### CodeEditorConfig
9191

92-
| Parameter | Description | Type | Default |
93-
| --- | --- | --- | --- |
94-
| `assetsRoot` | Where should the component load resource of monaco editor | `string` \| `SafeUrl` | - |
95-
| `defaultEditorOption` | Default options. [Please refer to the doc of monaco editor](https://microsoft.github.io/monaco-editor/api/interfaces/monaco.editor.IEditorOptions.html) | `IEditorConstructionOptions` | `{}` |
96-
| `onLoad` | The hook invoked when the resource of monaco editor is loaded. At this moment and afterwards the global variable `monaco` is usable (`window.MonacoEnvironment = { globalAP: true }` is required if monaco-editor's version is greater or equal to 0.22.0) | `() => void` | - |
97-
| `onFirstEditorInit` | The hook invoked when the first monaco editor is initialized | `() => void` | - |
98-
| `onInit` | The hook invoked every time a monaco editor is initialized | `() => void` | - |
99-
| `useStaticLoading` | Load monaco editor statically | `boolean` | `false` |
92+
| Parameter | Description | Type | Default |
93+
| --------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------- | ------- |
94+
| `assetsRoot` | Where should the component load resource of monaco editor | `string` \| `SafeUrl` | - |
95+
| `defaultEditorOption` | Default options. [Please refer to the doc of monaco editor](https://microsoft.github.io/monaco-editor/api/interfaces/monaco.editor.IEditorOptions.html) | `IEditorConstructionOptions` | `{}` |
96+
| `onLoad` | The hook invoked when the resource of monaco editor is loaded. At this moment and afterwards the global variable `monaco` is usable (`window.MonacoEnvironment = { globalAP: true }` is required if monaco-editor's version is greater or equal to 0.22.0) | `() => void` | - |
97+
| `onFirstEditorInit` | The hook invoked when the first monaco editor is initialized | `() => void` | - |
98+
| `onInit` | The hook invoked every time a monaco editor is initialized | `() => void` | - |
99+
| `useStaticLoading` | Load monaco editor statically | `boolean` | `false` |

‎components/code-editor/doc/index.zh-CN.md‎

Lines changed: 21 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ experimental: true
1212
<p>开发者或用户可以选择在正式发布前使用这些功能,但是每次发布版本时都可能存在 <strong>breaking changes</strong>。</p>
1313
</blockquote>
1414

15-
1615
## 何时使用
1716

1817
需要在网页上渲染 monaco editor 时使用。
@@ -26,10 +25,9 @@ import { NzCodeEditorModule } from 'ng-zorro-antd/code-editor';
2625
### 引入样式
2726

2827
```less
29-
@import "node_modules/ng-zorro-antd/code-editor/style/entry.less"
28+
@import 'node_modules/ng-zorro-antd/code-editor/style/entry.less';
3029
```
3130

32-
3331
## API
3432

3533
别忘记先安装 monaco editor:
@@ -72,22 +70,22 @@ npm install monaco-editor
7270

7371
使用静态加载时,你无需在 angular.json 文件中注册 monaco editor 的资源。
7472

75-
### nz-code-editor
73+
### nz-code-editor:standalone
7674

77-
| 参数 | 说明 | 类型 | 默认值 |
78-
| --- | --- | --- | --- |
79-
| `[nzEditorMode]` | 编辑器的模式 | `normal`\|`diff` | `normal` |
80-
| `[nzLoading]` | 加载中 | `boolean` | `false` |
81-
| `[nzOriginalText]` | Diff 模式下,左半边的文本内容 | `boolean` | `false` |
82-
| `[nzFullControl]` | 完全控制模式,此模式下组件不会帮助用户处理 `TextModel`,用户应当自行管理 monaco editor 实例 | `boolean` | `false` |
83-
| `[nzEditorOption]` | 编辑器选项,[参考 monaco editor 的定义](https://microsoft.github.io/monaco-editor/api/interfaces/monaco.editor.IEditorOptions.html) | `IEditorConstructionOptions` | `{}` |
84-
| `[nzToolkit]` | 暴露快捷操作 | `TemplateRef<void>` | - |
85-
| `(nzEditorInitialized)` | 当编辑器组件初始化完毕之后派发事件 | `IStandaloneCodeEditor` \| `IStandaloneDiffEditor` | - |
75+
| 参数 | 说明 | 类型 | 默认值 |
76+
| ----------------------- | ----------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------- | -------- |
77+
| `[nzEditorMode]` | 编辑器的模式 | `normal`\|`diff` | `normal` |
78+
| `[nzLoading]` | 加载中 | `boolean` | `false` |
79+
| `[nzOriginalText]` | Diff 模式下,左半边的文本内容 | `boolean` | `false` |
80+
| `[nzFullControl]` | 完全控制模式,此模式下组件不会帮助用户处理 `TextModel`,用户应当自行管理 monaco editor 实例 | `boolean` | `false` |
81+
| `[nzEditorOption]` | 编辑器选项,[参考 monaco editor 的定义](https://microsoft.github.io/monaco-editor/api/interfaces/monaco.editor.IEditorOptions.html) | `IEditorConstructionOptions` | `{}` |
82+
| `[nzToolkit]` | 暴露快捷操作 | `TemplateRef<void>` | - |
83+
| `(nzEditorInitialized)` | 当编辑器组件初始化完毕之后派发事件 | `IStandaloneCodeEditor` \| `IStandaloneDiffEditor` | - |
8684

8785
#### 方法
8886

89-
| 名称 | 描述 |
90-
| --- | --- |
87+
| 名称 | 描述 |
88+
| ---------- | ---------------- |
9189
| `layout()` | 强制组件重新渲染 |
9290

9391
### 全局配置
@@ -96,11 +94,11 @@ npm install monaco-editor
9694

9795
#### CodeEditorConfig
9896

99-
| 属性 | 说明 | 类型 | 默认值 |
100-
| --- | --- | --- | --- |
101-
| `assetsRoot` | 组件加载 monaco editor 资源文件的位置 | `string` \| `SafeUrl` | - |
102-
| `defaultEditorOption` | 默认的编辑器设置,[参考 monaco editor 的定义](https://microsoft.github.io/monaco-editor/api/interfaces/monaco.editor.ieditorconstructionoptions.html) | `IEditorConstructionOptions` | `{}` |
103-
| `onLoad` | 当 monaco editor 资源加载完毕时触发的钩子,此时全局对象 `monaco` 可用 (monaco-editor 版本不小于 0.22.0 时需定义 `window.MonacoEnvironment = { globalAP: true }`) | `() => void` | - |
104-
| `onFirstEditorInit` | 当第一个编辑器请求初始化时触发的钩子 | `() => void` | - |
105-
| `onInit` | 每个编辑器请求初始化时触发的钩子 | `() => void` | - |
106-
| `useStaticLoading` | 使用静态加载 | `boolean` | `false` |
97+
| 属性 | 说明 | 类型 | 默认值 |
98+
| --------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------- | ------- |
99+
| `assetsRoot` | 组件加载 monaco editor 资源文件的位置 | `string` \| `SafeUrl` | - |
100+
| `defaultEditorOption` | 默认的编辑器设置,[参考 monaco editor 的定义](https://microsoft.github.io/monaco-editor/api/interfaces/monaco.editor.ieditorconstructionoptions.html) | `IEditorConstructionOptions` | `{}` |
101+
| `onLoad` | 当 monaco editor 资源加载完毕时触发的钩子,此时全局对象 `monaco` 可用 (monaco-editor 版本不小于 0.22.0 时需定义 `window.MonacoEnvironment = { globalAP: true }`) | `() => void` | - |
102+
| `onFirstEditorInit` | 当第一个编辑器请求初始化时触发的钩子 | `() => void` | - |
103+
| `onInit` | 每个编辑器请求初始化时触发的钩子 | `() => void` | - |
104+
| `useStaticLoading` | 使用静态加载 | `boolean` | `false` |

0 commit comments

Comments
 (0)