@knime/kds-code-editor 2.6.3

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.
package/README.md ADDED
@@ -0,0 +1,133 @@
1
+ # KNIME® Design System – Code Editor
2
+
3
+ This is part of the [KNIME Design System](https://github.com/knime/knime-designsystem) maintained by the [UI Core Team](mailto:team-ui-core@knime.com).
4
+
5
+ This package contains the `KdsCodeEditor` component, a code editor that follows the KNIME Design System. It is based on the [Vue] JavaScript framework and powered by the [Monaco editor][Monaco].
6
+
7
+ It's published as npm package: [@knime/kds-code-editor]
8
+
9
+ ## Why a separate package?
10
+
11
+ Monaco is a large dependency (the editor core plus language workers) that is irrelevant to most consumers of `@knime/kds-components`. Keeping the code editor in its own package keeps that dependency, bundle, and security-audit/SBOM surface **opt-in** — only apps that install this package pull it in.
12
+
13
+ `monaco-editor` is declared as a peer dependency and is **externalized** in the build (see [`vite.config.ts`](vite.config.ts)): Monaco holds global state (language registry, `MonacoEnvironment`, models), so the host app controls the single shared instance and can pull CVE-patched versions via its own lockfile without waiting on a republish.
14
+
15
+ ## Setup in consuming repositories
16
+
17
+ ### Peer dependency
18
+
19
+ `monaco-editor` is a peer dependency (see [Why a separate package?](#why-a-separate-package)). Install a version matching the peer range declared in [package.json](package.json).
20
+
21
+ ### Monaco shadow-DOM patch (required inside KNIME UI extensions)
22
+
23
+ Monaco's hover, suggest, and action widgets mis-position and mis-detect mouse
24
+ leave when the editor is rendered inside a shadow root — which is how KNIME
25
+ embeds UI extensions (AP-25740). The fix is a
26
+ [pnpm patch](https://pnpm.io/settings#patcheddependencies) that ships with this
27
+ package under [`patches/`](patches/).
28
+
29
+ Because pnpm applies patches in the installing workspace (a package cannot
30
+ patch its consumer's dependencies), every consuming repository must apply it
31
+ to its own `monaco-editor` install:
32
+
33
+ 1. Copy `node_modules/@knime/kds-code-editor/patches/monaco-editor@<version>.patch`
34
+ into your repository (e.g. a `patches/` folder). Do not reference the file
35
+ inside `node_modules` directly — on a cold install pnpm needs the patch
36
+ before the package providing it is extracted.
37
+ 2. Register it in your `pnpm-workspace.yaml`:
38
+
39
+ ```yaml
40
+ patchedDependencies:
41
+ monaco-editor@0.55.1: patches/monaco-editor@0.55.1.patch
42
+ ```
43
+
44
+ When this package bumps its `monaco-editor` peer range, the bundled patch is
45
+ updated with it — re-copy the patch file when you bump Monaco.
46
+
47
+ ### Monaco state is global
48
+
49
+ Standalone Monaco keeps page-global state, and `KdsCodeEditor` participates
50
+ in it:
51
+
52
+ - **Theme:** the component switches Monaco's built-in `vs-light` / `vs-dark`
53
+ theme to follow the KDS dark-mode setting — once at mount and again on every
54
+ dark-mode change. Monaco's theme applies to **every** standalone editor on
55
+ the page, so the host app's own Monaco editors switch along with it, and a
56
+ custom theme set by the host is overridden while a `KdsCodeEditor` is
57
+ mounted. If your app defines its own Monaco editors, expect them to render
58
+ with `vs-light` / `vs-dark` alongside this component.
59
+ - **Worker environment and languages:** `setupMonacoEnvironment` installs a
60
+ `MonacoEnvironment` only when the host app has not already defined one, and
61
+ the custom language grammars shipped with this package (e.g. `toml`) are
62
+ registered in Monaco's global language registry at import time — they are
63
+ also available to the host app's own editors.
64
+
65
+ ## Using the editor in a Vue application
66
+
67
+ Install the [@knime/kds-code-editor] npm package as a dependency. It requires `@knime/kds-components`, `monaco-editor`, and `vue` as peer dependencies:
68
+
69
+ ```sh
70
+ pnpm add @knime/kds-code-editor @knime/kds-components @knime/kds-styles monaco-editor
71
+ ```
72
+
73
+ ```vue
74
+ <script setup lang="ts">
75
+ import { ref } from "vue";
76
+
77
+ import { KdsCodeEditor } from "@knime/kds-code-editor";
78
+
79
+ const value = ref('key = "value"');
80
+ </script>
81
+
82
+ <template>
83
+ <KdsCodeEditor v-model="value" language="toml" :min-rows="5" />
84
+ </template>
85
+ ```
86
+
87
+ ### Public exports
88
+
89
+ All public symbols follow the KDS `Kds` prefix convention:
90
+
91
+ | Export | Kind | Description |
92
+ | --------------------------------- | --------- | ------------------------------------------------------------- |
93
+ | `KdsCodeEditor` | component | The code editor (with header, copy button, and sub-text) |
94
+ | `setupMonacoEnvironment` | function | Installs the Monaco worker environment (no-op if already set) |
95
+ | `kdsCodeEditorState` | const | Editor states (`default` / `error` / `warning`) |
96
+ | `kdsCodeEditorStates` | const | Array of all editor states |
97
+ | `KdsCodeEditorProps` | type | Props of `KdsCodeEditor` |
98
+ | `KdsCodeEditorState` | type | Union of the editor states |
99
+ | `KdsCodeEditorAction` | type | Union of the header action types below |
100
+ | `KdsCodeEditorButtonAction` | type | Header action rendered as `KdsButton` |
101
+ | `KdsCodeEditorToggleButtonAction` | type | Header action rendered as `KdsToggleButton` |
102
+ | `KdsCodeEditorMenuButtonAction` | type | Header action rendered as `KdsMenuButton` |
103
+
104
+ ### Using with Vitest, Nuxt, or Vite SSR
105
+
106
+ The published JavaScript imports its CSS as a side effect (e.g.
107
+ `import "./index.css"`), which bundlers handle automatically. When the package
108
+ is instead evaluated by Node's native ESM loader — as **Vitest** and
109
+ **Vite/Nuxt SSR** do by default, since they externalize `node_modules` — Node
110
+ has no `.css` loader and throws `Unknown file extension ".css"`. Configure the
111
+ consuming project once so `@knime/*` packages are processed instead of
112
+ externalized:
113
+
114
+ ```ts
115
+ // Vitest — vitest.config.ts
116
+ export default defineConfig({
117
+ test: { server: { deps: { inline: [/@knime\//] } } },
118
+ });
119
+ ```
120
+
121
+ ```ts
122
+ // Vite SSR — vite.config.ts
123
+ export default defineConfig({ ssr: { noExternal: [/@knime\//] } });
124
+ ```
125
+
126
+ ```ts
127
+ // Nuxt — nuxt.config.ts
128
+ export default defineNuxtConfig({ build: { transpile: [/@knime\//] } });
129
+ ```
130
+
131
+ [Vue]: https://vuejs.org/
132
+ [Monaco]: https://microsoft.github.io/monaco-editor/
133
+ [@knime/kds-code-editor]: https://www.npmjs.com/package/@knime/kds-code-editor