@actualwave/react-native-codeditor 1.0.0 → 1.2.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.
Files changed (63) hide show
  1. package/CHANGELOG.md +28 -0
  2. package/README.md +53 -3
  3. package/SKILL.md +469 -0
  4. package/THIRD_PARTY_NOTICES +120 -0
  5. package/app.plugin.js +1 -1
  6. package/lib/module/CodeEditor.js +73 -2
  7. package/lib/module/WebViewAPI.js +4 -0
  8. package/lib/typescript/src/CodeEditor.d.ts +21 -2
  9. package/lib/typescript/src/EditorAPI.d.ts +44 -1
  10. package/lib/typescript/src/WebViewAPI.d.ts +5 -1
  11. package/lib/typescript/src/index.d.ts +1 -1
  12. package/package.json +12 -4
  13. package/src/assets/codemirror/@actualwave_codemirror-lang-embed-core.js +39 -0
  14. package/src/assets/codemirror/@actualwave_codemirror-lang-embed-css.js +19 -0
  15. package/src/assets/codemirror/@actualwave_codemirror-lang-embed-glsl.js +1 -0
  16. package/src/assets/codemirror/@actualwave_codemirror-lang-embed-graphql.js +50 -0
  17. package/src/assets/codemirror/@actualwave_codemirror-lang-embed-icu-messageformat.js +1 -0
  18. package/src/assets/codemirror/@actualwave_codemirror-lang-embed-react-native.js +6 -0
  19. package/src/assets/codemirror/@actualwave_codemirror-lang-embed-sksl.js +7 -0
  20. package/src/assets/codemirror/@actualwave_codemirror-lang-embed-sql.js +5 -0
  21. package/src/assets/codemirror/@actualwave_codemirror-lang-embed-tailwind.js +63 -0
  22. package/src/assets/codemirror/@actualwave_codemirror-lang-glsl.js +20 -0
  23. package/src/assets/codemirror/@actualwave_codemirror-lang-icu-messageformat.js +11 -0
  24. package/src/assets/codemirror/@actualwave_codemirror-lang-react-native.js +71 -0
  25. package/src/assets/codemirror/@actualwave_codemirror-lang-sksl.js +7 -2
  26. package/src/assets/codemirror/@codemirror_autocomplete.js +9 -9
  27. package/src/assets/codemirror/@codemirror_commands.js +86 -86
  28. package/src/assets/codemirror/@codemirror_lang-css.js +2 -2
  29. package/src/assets/codemirror/@codemirror_lang-go.js +1 -1
  30. package/src/assets/codemirror/@codemirror_lang-html.js +1 -1
  31. package/src/assets/codemirror/@codemirror_lang-javascript.js +4 -4
  32. package/src/assets/codemirror/@codemirror_lang-jinja.js +1 -1
  33. package/src/assets/codemirror/@codemirror_lang-json.js +1 -1
  34. package/src/assets/codemirror/@codemirror_lang-less.js +1 -1
  35. package/src/assets/codemirror/@codemirror_lang-liquid.js +1 -1
  36. package/src/assets/codemirror/@codemirror_lang-markdown.js +2 -2
  37. package/src/assets/codemirror/@codemirror_lang-python.js +1 -1
  38. package/src/assets/codemirror/@codemirror_lang-sql.js +4 -4
  39. package/src/assets/codemirror/@codemirror_lang-xml.js +1 -1
  40. package/src/assets/codemirror/@codemirror_language.js +11 -11
  41. package/src/assets/codemirror/@codemirror_legacy-modes_mode_clike.js +1 -1
  42. package/src/assets/codemirror/@codemirror_legacy-modes_mode_mathematica.js +1 -1
  43. package/src/assets/codemirror/@codemirror_legacy-modes_mode_oz.js +1 -1
  44. package/src/assets/codemirror/@codemirror_legacy-modes_mode_verilog.js +1 -1
  45. package/src/assets/codemirror/@codemirror_lint.js +5 -5
  46. package/src/assets/codemirror/@codemirror_merge.js +4 -4
  47. package/src/assets/codemirror/@codemirror_search.js +8 -8
  48. package/src/assets/codemirror/@codemirror_state.js +1 -1
  49. package/src/assets/codemirror/@codemirror_theme-one-dark.js +3 -3
  50. package/src/assets/codemirror/@codemirror_view.js +6 -6
  51. package/src/assets/codemirror/@lezer_common.js +2 -2
  52. package/src/assets/codemirror/@lezer_css.js +1 -1
  53. package/src/assets/codemirror/@lezer_javascript.js +1 -1
  54. package/src/assets/codemirror/@lezer_lr.js +1 -1
  55. package/src/assets/codemirror/@lezer_markdown.js +4 -4
  56. package/src/assets/codemirror/@lezer_sass.js +1 -1
  57. package/src/assets/codemirror/_core.js +129 -129
  58. package/src/assets/codemirror-editor.umd.js +130 -17
  59. package/src/assets/editor.html +49 -2
  60. package/lib/typescript/app.plugin.d.ts +0 -3
  61. package/lib/typescript/babel.config.d.ts +0 -10
  62. package/lib/typescript/react-native.config.d.ts +0 -2
  63. package/lib/typescript/scripts/copy-assets.d.ts +0 -2
@@ -0,0 +1,120 @@
1
+ THIRD PARTY NOTICES
2
+ ===================
3
+
4
+ This package distributes compiled browser assets built from the following
5
+ open-source libraries. Their licenses and copyright notices are reproduced
6
+ below as required by the MIT License.
7
+
8
+
9
+ -------------------------------------------------------------------------------
10
+ CodeMirror, @codemirror/*, @lezer/*, crelt, style-mod, w3c-keyname,
11
+ @marijn/find-cluster-break
12
+ -------------------------------------------------------------------------------
13
+ MIT License
14
+
15
+ Copyright (C) 2018-2024 by Marijn Haverbeke <marijn@haverbeke.berlin> and others
16
+
17
+ Permission is hereby granted, free of charge, to any person obtaining a copy
18
+ of this software and associated documentation files (the "Software"), to deal
19
+ in the Software without restriction, including without limitation the rights
20
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
21
+ copies of the Software, and to permit persons to whom the Software is
22
+ furnished to do so, subject to the following conditions:
23
+
24
+ The above copyright notice and this permission notice shall be included in all
25
+ copies or substantial portions of the Software.
26
+
27
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
28
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
29
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
30
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
31
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
32
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
33
+ SOFTWARE.
34
+
35
+ https://codemirror.net/
36
+
37
+
38
+ -------------------------------------------------------------------------------
39
+ @uiw/codemirror-themes, @uiw/codemirror-theme-*
40
+ -------------------------------------------------------------------------------
41
+ MIT License
42
+
43
+ Copyright (c) 2022 kenny wong <wowohoo@qq.com>
44
+
45
+ Permission is hereby granted, free of charge, to any person obtaining a copy
46
+ of this software and associated documentation files (the "Software"), to deal
47
+ in the Software without restriction, including without limitation the rights
48
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
49
+ copies of the Software, and to permit persons to whom the Software is
50
+ furnished to do so, subject to the following conditions:
51
+
52
+ The above copyright notice and this permission notice shall be included in all
53
+ copies or substantial portions of the Software.
54
+
55
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
56
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
57
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
58
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
59
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
60
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
61
+ SOFTWARE.
62
+
63
+ https://github.com/uiwjs/react-codemirror
64
+
65
+
66
+ -------------------------------------------------------------------------------
67
+ cm6-graphql, graphql, graphql-language-service
68
+ -------------------------------------------------------------------------------
69
+ MIT License
70
+
71
+ Copyright (c) 2021 GraphQL Contributors
72
+
73
+ Permission is hereby granted, free of charge, to any person obtaining a copy
74
+ of this software and associated documentation files (the "Software"), to deal
75
+ in the Software without restriction, including without limitation the rights
76
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
77
+ copies of the Software, and to permit persons to whom the Software is
78
+ furnished to do so, subject to the following conditions:
79
+
80
+ The above copyright notice and this permission notice shall be included in all
81
+ copies or substantial portions of the Software.
82
+
83
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
84
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
85
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
86
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
87
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
88
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
89
+ SOFTWARE.
90
+
91
+ https://github.com/graphql/graphiql
92
+ https://github.com/graphql/graphql-js
93
+
94
+
95
+ -------------------------------------------------------------------------------
96
+ @babel/runtime
97
+ -------------------------------------------------------------------------------
98
+ MIT License
99
+
100
+ Copyright (c) 2014-present Sebastian McKenzie and other contributors
101
+
102
+ Permission is hereby granted, free of charge, to any person obtaining a copy
103
+ of this software and associated documentation files (the "Software"), to deal
104
+ in the Software without restriction, including without limitation the rights
105
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
106
+ copies of the Software, and to permit persons to whom the Software is
107
+ furnished to do so, subject to the following conditions:
108
+
109
+ The above copyright notice and this permission notice shall be included in all
110
+ copies or substantial portions of the Software.
111
+
112
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
113
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
114
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
115
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
116
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
117
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
118
+ SOFTWARE.
119
+
120
+ https://babel.dev
package/app.plugin.js CHANGED
@@ -1,4 +1,4 @@
1
- const { withDangerousMod, withXcodeProject } = require("@expo/config-plugins");
1
+ const { withDangerousMod, withXcodeProject } = require("expo/config-plugins");
2
2
  const fs = require("fs");
3
3
  const path = require("path");
4
4
 
@@ -38,6 +38,7 @@ const CodeEditor = ({
38
38
  onError,
39
39
  onContentUpdate,
40
40
  onSelectionChange,
41
+ onShortcut,
41
42
  onWebViewRefUpdated,
42
43
  onLoad,
43
44
  onLoadStart,
@@ -46,6 +47,9 @@ const CodeEditor = ({
46
47
  onNavigationStateChange,
47
48
  renderBlockingView = () => /*#__PURE__*/_jsx(BlockingView, {}),
48
49
  language,
50
+ languageConfig,
51
+ embeds,
52
+ languages,
49
53
  extensions = DEFAULT_EXTENSIONS,
50
54
  theme,
51
55
  content = "",
@@ -63,6 +67,7 @@ const CodeEditor = ({
63
67
  onInitialized,
64
68
  onContentUpdate,
65
69
  onSelectionChange,
70
+ onShortcut,
66
71
  onHistorySizeUpdate,
67
72
  onLog,
68
73
  onError,
@@ -72,6 +77,7 @@ const CodeEditor = ({
72
77
  onInitialized,
73
78
  onContentUpdate,
74
79
  onSelectionChange,
80
+ onShortcut,
75
81
  onHistorySizeUpdate,
76
82
  onLog,
77
83
  onError,
@@ -80,6 +86,9 @@ const CodeEditor = ({
80
86
  const propsRef = useRef({
81
87
  content,
82
88
  language,
89
+ languageConfig,
90
+ embeds,
91
+ languages,
83
92
  extensions,
84
93
  theme,
85
94
  viewport
@@ -87,6 +96,9 @@ const CodeEditor = ({
87
96
  propsRef.current = {
88
97
  content,
89
98
  language,
99
+ languageConfig,
100
+ embeds,
101
+ languages,
90
102
  extensions,
91
103
  theme,
92
104
  viewport
@@ -103,6 +115,7 @@ const CodeEditor = ({
103
115
  callbacksRef.current.onContentUpdate(value);
104
116
  },
105
117
  onSelectionChange: text => callbacksRef.current.onSelectionChange?.(text),
118
+ onShortcut: name => callbacksRef.current.onShortcut?.(name),
106
119
  onHistorySizeUpdate: size => callbacksRef.current.onHistorySizeUpdate(size),
107
120
  onLog: (...args) => callbacksRef.current.onLog(...args),
108
121
  onError: error => callbacksRef.current.onError(error)
@@ -135,7 +148,10 @@ const CodeEditor = ({
135
148
  }
136
149
  }, [content]);
137
150
 
138
- // Push language changes to live editor
151
+ // Push language changes to live editor. Reads languageConfig/embeds from propsRef
152
+ // (rather than depending on them) so a language switch always carries the current
153
+ // embeds along — otherwise switching away from and back to 'javascript' would silently
154
+ // drop any previously-configured tagged-template embeddings/support extensions.
139
155
  const prevLanguageRef = useRef(null);
140
156
  useEffect(() => {
141
157
  if (prevLanguageRef.current === null) {
@@ -144,9 +160,58 @@ const CodeEditor = ({
144
160
  }
145
161
  if (prevLanguageRef.current === language) return;
146
162
  prevLanguageRef.current = language;
147
- if (language) callEditor(e => e.setLanguage(language));
163
+ if (language) {
164
+ const {
165
+ languageConfig: lc,
166
+ embeds: em
167
+ } = propsRef.current;
168
+ callEditor(e => e.setLanguage(language, lc, em));
169
+ }
148
170
  }, [language]);
149
171
 
172
+ // Push embeds changes to live editor — re-resolves the current language with the new
173
+ // embeds, since tagged-template embeddings/support extensions are baked into the
174
+ // 'javascript' LanguageSupport at resolution time rather than being separately
175
+ // reconfigurable. No-op for any language other than 'javascript'.
176
+ const prevEmbedsRef = useRef(null);
177
+ useEffect(() => {
178
+ if (prevEmbedsRef.current === null) {
179
+ prevEmbedsRef.current = embeds;
180
+ return;
181
+ }
182
+ if (prevEmbedsRef.current === embeds) return;
183
+ prevEmbedsRef.current = embeds;
184
+ const {
185
+ language: l,
186
+ languageConfig: lc
187
+ } = propsRef.current;
188
+ if (l) callEditor(e => e.setLanguage(l, lc, embeds));
189
+ }, [embeds]);
190
+
191
+ // Push languages changes to live editor — registers the new mappings, then re-resolves
192
+ // the current language, since it may be one that was previously unresolvable.
193
+ const prevLanguagesRef = useRef(null);
194
+ useEffect(() => {
195
+ if (prevLanguagesRef.current === null) {
196
+ prevLanguagesRef.current = languages;
197
+ return;
198
+ }
199
+ if (prevLanguagesRef.current === languages) return;
200
+ prevLanguagesRef.current = languages;
201
+ if (!languages) return;
202
+ const {
203
+ language: l,
204
+ languageConfig: lc,
205
+ embeds: em
206
+ } = propsRef.current;
207
+ callEditor(async e => {
208
+ for (const [name, packageName] of Object.entries(languages)) {
209
+ await e.registerLanguage(name, packageName);
210
+ }
211
+ if (l) await e.setLanguage(l, lc, em);
212
+ });
213
+ }, [languages]);
214
+
150
215
  // Push theme changes to live editor
151
216
  const prevThemeRef = useRef(null);
152
217
  useEffect(() => {
@@ -189,6 +254,9 @@ const CodeEditor = ({
189
254
  const {
190
255
  content: c,
191
256
  language: l,
257
+ languageConfig: lc,
258
+ embeds: em,
259
+ languages: lg,
192
260
  extensions: e,
193
261
  theme: t,
194
262
  viewport: v
@@ -197,6 +265,9 @@ const CodeEditor = ({
197
265
  apiRef.current.setInitialConfig({
198
266
  content: c,
199
267
  language: l,
268
+ languageConfig: lc,
269
+ embeds: em,
270
+ languages: lg,
200
271
  extensions: e,
201
272
  theme: t,
202
273
  viewport: v
@@ -99,6 +99,10 @@ class WebViewAPI {
99
99
  this.handlers.onSelectionChange?.(typeof parsed.data === 'string' ? parsed.data : '');
100
100
  return;
101
101
  }
102
+ if (parsed?.type === '__shortcut__') {
103
+ this.handlers.onShortcut?.(typeof parsed.data === 'string' ? parsed.data : '');
104
+ return;
105
+ }
102
106
  } catch {
103
107
  // not JSON — fall through to DDA
104
108
  }
@@ -1,7 +1,7 @@
1
1
  import React from "react";
2
2
  import WebView from "react-native-webview";
3
3
  import WebViewAPI from "./WebViewAPI";
4
- import type { ExtensionSpec, HistorySize, ViewportSettings } from "./EditorAPI";
4
+ import type { EmbedsConfig, ExtensionSpec, HistorySize, ViewportSettings } from "./EditorAPI";
5
5
  export interface CodeEditorProps {
6
6
  onInitialized: (api: WebViewAPI) => void;
7
7
  onHistorySizeUpdate: (size: HistorySize) => void;
@@ -9,6 +9,7 @@ export interface CodeEditorProps {
9
9
  onError: (error: unknown) => void;
10
10
  onContentUpdate: (content: string) => void;
11
11
  onSelectionChange?: (text: string) => void;
12
+ onShortcut?: (name: string) => void;
12
13
  onWebViewRefUpdated?: (webView: WebView | null) => void;
13
14
  onLoad?: (event: unknown) => void;
14
15
  onLoadStart?: (event: unknown) => void;
@@ -18,6 +19,24 @@ export interface CodeEditorProps {
18
19
  renderBlockingView?: () => React.ReactNode;
19
20
  /** Language name for syntax highlighting, e.g. 'javascript', 'python'. */
20
21
  language?: string;
22
+ /** Options passed to the language factory, e.g. { jsx: true, typescript: true } for 'javascript'. */
23
+ languageConfig?: Record<string, unknown>;
24
+ /**
25
+ * Tagged-template DSL embeddings (e.g. `` sql`...` ``) and javascript support
26
+ * extensions (e.g. completion-only DSLs with no grammar) to mix into the
27
+ * 'javascript' language. Alternative to calling api.registerTaggedTemplate() /
28
+ * api.registerSupportExtension() imperatively — use whichever fits: this prop
29
+ * for "known up front, declarative," the imperative calls for "registered once,
30
+ * dynamically, from app code after init."
31
+ */
32
+ embeds?: EmbedsConfig;
33
+ /**
34
+ * Custom language packages as `{ name: packageName }`, for languages that don't follow
35
+ * the `@codemirror/lang-{name}` convention, e.g. `{ sksl: '@actualwave/codemirror-lang-sksl' }`.
36
+ * Registered before the initial `language` is resolved. Alternative to calling
37
+ * api.registerLanguage() imperatively.
38
+ */
39
+ languages?: Record<string, string>;
21
40
  /** Additional CodeMirror extension specs loaded on top of the language. */
22
41
  extensions?: ExtensionSpec[];
23
42
  /** Theme name from the @uiw/codemirror-themes collection, e.g. 'darcula', 'monokai'. */
@@ -28,6 +47,6 @@ export interface CodeEditorProps {
28
47
  /** Override the default editor HTML URI (useful on iOS where the bundle path varies). */
29
48
  editorUri?: string;
30
49
  }
31
- declare const CodeEditor: ({ onInitialized, onHistorySizeUpdate, onLog, onError, onContentUpdate, onSelectionChange, onWebViewRefUpdated, onLoad, onLoadStart, onLoadProgress, onLoadEnd, onNavigationStateChange, renderBlockingView, language, extensions, theme, content, viewport, allowFileAccess, editorUri, }: CodeEditorProps) => import("react/jsx-runtime").JSX.Element;
50
+ declare const CodeEditor: ({ onInitialized, onHistorySizeUpdate, onLog, onError, onContentUpdate, onSelectionChange, onShortcut, onWebViewRefUpdated, onLoad, onLoadStart, onLoadProgress, onLoadEnd, onNavigationStateChange, renderBlockingView, language, languageConfig, embeds, languages, extensions, theme, content, viewport, allowFileAccess, editorUri, }: CodeEditorProps) => import("react/jsx-runtime").JSX.Element;
32
51
  export default CodeEditor;
33
52
  //# sourceMappingURL=CodeEditor.d.ts.map
@@ -28,11 +28,27 @@ export interface CompletionItem {
28
28
  detail?: string;
29
29
  info?: string;
30
30
  }
31
+ /**
32
+ * Tagged-template DSL embedding config for the 'javascript' language (e.g.
33
+ * `` sql`...` ``, `` gql`...` ``), passed per-call to setLanguage/createEditor
34
+ * and merged with whatever's been registered globally via
35
+ * registerTaggedTemplate/registerSupportExtension.
36
+ * - taggedTemplates: package names exporting createEmbedding(), e.g.
37
+ * '@actualwave/codemirror-lang-embed-sql'.
38
+ * - supportExtensions: package names (or [name, config] tuples) exporting
39
+ * createSupportExtension(), e.g. '@actualwave/codemirror-lang-embed-tailwind',
40
+ * or ['@actualwave/codemirror-lang-embed-react-native', { modules }]. Not
41
+ * JS-specific by name or contract — currently only mixed into 'javascript'.
42
+ */
43
+ export interface EmbedsConfig {
44
+ taggedTemplates?: string[];
45
+ supportExtensions?: Array<string | [string, Record<string, unknown>]>;
46
+ }
31
47
  export interface EditorAPI {
32
48
  getValue(): Promise<string>;
33
49
  setValue(value: string): Promise<void>;
34
50
  resetValue(value?: string): Promise<void>;
35
- setLanguage(name: string): Promise<void>;
51
+ setLanguage(name: string, config?: Record<string, unknown>, embeds?: EmbedsConfig): Promise<void>;
36
52
  setExtensions(specs: ExtensionSpec[]): Promise<void>;
37
53
  setTheme(themeName?: string): Promise<void>;
38
54
  setFontSize(size: number): Promise<void>;
@@ -60,6 +76,33 @@ export interface EditorAPI {
60
76
  startCompletion(): Promise<void>;
61
77
  setCompletions(items: CompletionItem[]): Promise<void>;
62
78
  setSoftKeyboard(enabled: boolean): Promise<void>;
79
+ registerShortcut(key: string, name: string): Promise<void>;
80
+ unregisterShortcut(key: string): Promise<void>;
81
+ /**
82
+ * Maps a language name to an npm package that doesn't follow the
83
+ * `@codemirror/lang-{name}` convention (e.g. `'sksl'` → `'@actualwave/codemirror-lang-sksl'`),
84
+ * for the lifetime of this editor page. The package must be one bundled in the
85
+ * WebView assets. Takes effect on the next setLanguage() call — follow it with
86
+ * setLanguage(name) to apply. Alternative to the `languages` prop on CodeEditor,
87
+ * which registers before the initial language is resolved.
88
+ */
89
+ registerLanguage(name: string, packageName: string): Promise<void>;
90
+ /**
91
+ * Registers a tagged-template DSL embedding package globally, for the lifetime of
92
+ * this editor page — picked up by any subsequent setLanguage('javascript', ...) call
93
+ * (including the one already resolved at createEditor time, so call this before the
94
+ * language is first set to 'javascript' if you want it included immediately, or follow
95
+ * it with setLanguage('javascript', ...) to re-resolve). Alternative to passing
96
+ * `embeds.taggedTemplates` per-call.
97
+ */
98
+ registerTaggedTemplate(packageName: string): Promise<void>;
99
+ /**
100
+ * Registers a support-extension package (e.g. a completion source with no nested
101
+ * grammar) globally — same timing/re-resolve caveat as registerTaggedTemplate.
102
+ * Alternative to passing `embeds.supportExtensions` per-call. Not JS-specific by
103
+ * name or contract — currently only mixed into the 'javascript' language.
104
+ */
105
+ registerSupportExtension(packageName: string, config?: Record<string, unknown>): Promise<void>;
63
106
  loadExtension(moduleName: string): Promise<object>;
64
107
  destroy(): Promise<void>;
65
108
  }
@@ -1,9 +1,10 @@
1
- import type { EditorAPI, ExtensionSpec, HistorySize, ViewportSettings } from './EditorAPI';
1
+ import type { EditorAPI, EmbedsConfig, ExtensionSpec, HistorySize, ViewportSettings } from './EditorAPI';
2
2
  export interface WebViewAPIHandlers {
3
3
  onInitialized: (api: WebViewAPI) => void;
4
4
  onHistorySizeUpdate: (size: HistorySize) => void;
5
5
  onContentUpdate: (content: string) => void;
6
6
  onSelectionChange?: (text: string) => void;
7
+ onShortcut?: (name: string) => void;
7
8
  onLog: (...args: unknown[]) => void;
8
9
  onError: (error: unknown) => void;
9
10
  }
@@ -14,6 +15,9 @@ export interface WebViewRef {
14
15
  export interface InitialConfig {
15
16
  content?: string;
16
17
  language?: string;
18
+ languageConfig?: Record<string, unknown>;
19
+ embeds?: EmbedsConfig;
20
+ languages?: Record<string, string>;
17
21
  extensions?: ExtensionSpec[];
18
22
  theme?: string;
19
23
  viewport?: ViewportSettings;
@@ -3,5 +3,5 @@ export { default as CodeEditor } from './CodeEditor';
3
3
  export type { CodeEditorProps } from './CodeEditor';
4
4
  export { default as WebViewAPI } from './WebViewAPI';
5
5
  export type { WebViewAPIHandlers, WebViewRef, InitialConfig } from './WebViewAPI';
6
- export type { EditorAPI, ExtensionSpec, ViewportSettings, CursorPosition, HistorySize, } from './EditorAPI';
6
+ export type { EditorAPI, ExtensionSpec, ViewportSettings, CursorPosition, HistorySize, CompletionItem, EmbedsConfig, } from './EditorAPI';
7
7
  //# sourceMappingURL=index.d.ts.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@actualwave/react-native-codeditor",
3
- "version": "1.0.0",
3
+ "version": "1.2.0",
4
4
  "description": "CodeMirror 6 code editor for React Native, embedded in a WebView with a full bidirectional RPC bridge. Offline, no CDN required.",
5
5
  "main": "./lib/module/index.js",
6
6
  "types": "./lib/typescript/src/index.d.ts",
@@ -19,6 +19,9 @@
19
19
  "lib",
20
20
  "app.plugin.js",
21
21
  "react-native.config.js",
22
+ "SKILL.md",
23
+ "CHANGELOG.md",
24
+ "THIRD_PARTY_NOTICES",
22
25
  "!lib/module/assets",
23
26
  "!lib/typescript/src/assets",
24
27
  "!**/*.map",
@@ -36,7 +39,13 @@
36
39
  "keywords": [
37
40
  "react-native",
38
41
  "ios",
39
- "android"
42
+ "android",
43
+ "codemirror",
44
+ "codemirror6",
45
+ "code-editor",
46
+ "editor",
47
+ "webview",
48
+ "expo"
40
49
  ],
41
50
  "repository": {
42
51
  "type": "git",
@@ -52,7 +61,7 @@
52
61
  "registry": "https://registry.npmjs.org/"
53
62
  },
54
63
  "devDependencies": {
55
- "@actualwave/codemirror-package": "^0.1.0",
64
+ "@actualwave/codemirror-package": "^0.1.4",
56
65
  "@react-native/assets-registry": "^0.85.3",
57
66
  "@react-native/babel-preset": "0.85.0",
58
67
  "@react-native/js-polyfills": "^0.85.3",
@@ -78,7 +87,6 @@
78
87
  "workspaces": [
79
88
  "example"
80
89
  ],
81
- "packageManager": "yarn@4.11.0",
82
90
  "react-native-builder-bob": {
83
91
  "source": "src",
84
92
  "output": "lib",
@@ -0,0 +1,39 @@
1
+ async function moduleInitFunction(requireAsyncModule,exports={}){function requireCodemirrorLangEmbedCore(){// A registry of (tagPath -> Language) matchers, tried in registration order.
2
+ // `tagPath` is the array produced by readIdentifierPath below, e.g. ['sql'],
3
+ // ['gql'], ['styled', 'View'] (for `styled.View` tags), or ['styled'] (for
4
+ // `styled(Component)` — the call collapses to its callee's own path).
5
+ function createTagRegistry(){const entries=[];return{register(matcher,language){entries.push({matcher,language})},resolve(tagPath){for(const{matcher,language}of entries)if(matcher(tagPath))return language;return null}}}// Walks a tag expression's SyntaxNode down to a flat identifier path.
6
+ // Only VariableName / MemberExpression(.prop) / CallExpression(callee) shapes
7
+ // are recognized — anything else (bracket access, computed member, etc.)
8
+ // is rejected by returning null, since tag-name matching is purely textual
9
+ // (see SINGLE_FILE_PROTOTYPES.md open question 2).
10
+ function readIdentifierPath(node,input){switch(node.name){case"VariableName":return[input.read(node.from,node.to)];case"MemberExpression":{const object=node.firstChild,property=node.lastChild;if(!object||!property)return null;if("PropertyName"!==property.name&&"PrivatePropertyName"!==property.name)// bracket-access form (styled['View']) — not a supported tag shape
11
+ return null;const objectPath=readIdentifierPath(object,input);return objectPath?[...objectPath,input.read(property.from,property.to)]:null}case"CallExpression":{// styled(Component)`...` collapses to the callee's own path, so
12
+ // `styled(Foo)` and bare `styled` both match a matcher for ['styled'].
13
+ const callee=node.firstChild;return callee?readIdentifierPath(callee,input):null}default:return null}}// Given a `TemplateString` node (materialized SyntaxNode, i.e. already
14
+ // `.node`), finds its tag identifier path if it's the template of a
15
+ // TaggedTemplateExpression, or null otherwise (plain, untagged templates).
16
+ function getTaggedTemplateTagPath(templateStringNode,input){const tagged=templateStringNode.parent;if(!tagged||"TaggedTemplateExpression"!==tagged.name)return null;// SyntaxNode accessors (.lastChild etc.) don't return reference-stable
17
+ // objects — compare by range instead of `===` to check this is really
18
+ // the tagged expression's own template (not, in principle, some other
19
+ // child at the same tree position).
20
+ const last=tagged.lastChild;if(!last||last.from!==templateStringNode.from||last.to!==templateStringNode.to)return null;const tagNode=tagged.firstChild;return tagNode?readIdentifierPath(tagNode,input):null}// A `TemplateString` node's own range spans the opening and closing backtick
21
+ // characters, and any `${...}` interpolations appear as `Interpolation` child
22
+ // nodes interleaved with the literal text. Nested DSL parsers only understand
23
+ // the literal text, so the overlay must exclude both the delimiters and any
24
+ // interpolation ranges — otherwise the nested parser sees stray backtick/`${`
25
+ // characters it doesn't recognize and produces spurious error nodes.
26
+ function templateContentRanges(templateStringNode){const ranges=[];let pos=templateStringNode.from+1;// skip opening backtick
27
+ for(let child=templateStringNode.firstChild;child;child=child.nextSibling)"Interpolation"===child.name&&(child.from>pos&&ranges.push({from:pos,to:child.from}),pos=child.to);const end=templateStringNode.to-1;// exclude closing backtick
28
+ return end>pos&&ranges.push({from:pos,to:end}),ranges}// Wraps a JS/TSX LanguageSupport (as returned by @codemirror/lang-javascript's
29
+ // javascript()) so that TaggedTemplateExpression templates whose tag matches
30
+ // an entry in `registry` get parsed by that entry's nested Language.
31
+ function embedTaggedTemplates(languageSupport,registry){const wrappedLanguage=languageSupport.language.configure({wrap:parseMixed((node,input)=>{if("TemplateString"!==node.name)return null;const tagPath=getTaggedTemplateTagPath(node.node,input);if(!tagPath)return null;const language=registry.resolve(tagPath);return language?{parser:language.parser,overlay:templateContentRanges(node.node)}:null})});return new LanguageSupport(wrappedLanguage,languageSupport.support)}// Convenience matcher factory for the common case: a bare identifier tag
32
+ // (e.g. `sql`, `gql`, `css`) with no member/call wrapping.
33
+ function matchTagName(name){return tagPath=>1===tagPath.length&&tagPath[0]===name}// Adapts a CM6 `Text` (`state.doc`) to the minimal Lezer `Input` shape
34
+ // (`.read(from, to)`) that readIdentifierPath/getTaggedTemplateTagPath need.
35
+ // Inside a `parseMixed` callback (embedTaggedTemplates above), Lezer already
36
+ // supplies a real Input, so this isn't needed there — it's for call sites
37
+ // walking an already-built tree directly against `state.doc`, e.g. a
38
+ // CompletionSource or a decoration ViewPlugin (see embed-tailwind).
39
+ function docAsInput(doc){return{read:(from,to)=>doc.sliceString(from,to)}}if(hasRequiredCodemirrorLangEmbedCore)return codemirrorLangEmbedCore;hasRequiredCodemirrorLangEmbedCore=1;const{parseMixed}=require$$0,{LanguageSupport}=require$$1;return codemirrorLangEmbedCore={createTagRegistry,readIdentifierPath,getTaggedTemplateTagPath,templateContentRanges,embedTaggedTemplates,matchTagName,docAsInput},codemirrorLangEmbedCore}const module={exports:exports};var codemirrorLangEmbedCore,hasRequiredCodemirrorLangEmbedCore,require$$0=await requireAsyncModule("@lezer/common"),require$$1=await requireAsyncModule("@codemirror/language"),codemirrorLangEmbedCoreExports=requireCodemirrorLangEmbedCore(),index=/*@__PURE__*/function getDefaultExportFromCjs(x){return x}(codemirrorLangEmbedCoreExports);return module.exports=index,module.exports}
@@ -0,0 +1,19 @@
1
+ async function moduleInitFunction(requireAsyncModule,exports={}){function requireCodemirrorLangEmbedCss(){// Matches the bare `css` tag as well as any styled-components-shaped tag:
2
+ // `styled.View`/`styled.Text`/... (MemberExpression) and `styled(Component)`
3
+ // (CallExpression, which readIdentifierPath collapses to the callee's own
4
+ // path, so it also resolves to a `['styled', ...]` path).
5
+ function matchCssTag(tagPath){return"css"===tagPath[0]||"styled"===tagPath[0]}// css`...`/styled`...` content is a bare declaration list (`color: #fff;
6
+ // padding: 12px;`), not a full stylesheet with a `selector { ... }` wrapper.
7
+ // Parsed with cssLanguage's default "StyleSheet" top rule, the parser treats
8
+ // that content as sitting *before* any rule block, so cssCompletionSource
9
+ // (which only offers property names when the cursor's ancestor is "Block" or
10
+ // "Styles" — see @codemirror/lang-css's completion.js) falls back to
11
+ // selector/tag-name completion instead (hence "main"/"small"/"summary").
12
+ // @codemirror/lang-html hits this exact same shape for `style="..."`
13
+ // attribute values and fixes it by reparsing with the grammar's alternate
14
+ // "Styles" top rule (see its dist: `cssLanguage.parser.configure({top:
15
+ // "Styles"})`) — same grammar, same NodeSet, so the languageDataProp
16
+ // (autocomplete source) attached at cssLanguage's original definition still
17
+ // resolves correctly off the "Styles" top node. Only `.parser` is used here;
18
+ // embed-core's registry never touches other Language fields (see resolve()).
19
+ function createEmbedding(){return{matcher:matchCssTag,language:{parser:stylesParser},extension:css().support}}if(hasRequiredCodemirrorLangEmbedCss)return codemirrorLangEmbedCss;hasRequiredCodemirrorLangEmbedCss=1;const{cssLanguage,css}=require$$0,stylesParser=cssLanguage.parser.configure({top:"Styles"});return codemirrorLangEmbedCss={createEmbedding},codemirrorLangEmbedCss}const module={exports:exports};var codemirrorLangEmbedCss,hasRequiredCodemirrorLangEmbedCss,require$$0=await requireAsyncModule("@codemirror/lang-css"),codemirrorLangEmbedCssExports=requireCodemirrorLangEmbedCss(),index=/*@__PURE__*/function getDefaultExportFromCjs(x){return x}(codemirrorLangEmbedCssExports);return module.exports=index,module.exports}
@@ -0,0 +1 @@
1
+ async function moduleInitFunction(requireAsyncModule,exports={}){function requireCodemirrorLangEmbedGlsl(){function createEmbedding(){return{matcher:matchTagName("glsl"),language:glslLanguage,extension:glsl().support}}if(hasRequiredCodemirrorLangEmbedGlsl)return codemirrorLangEmbedGlsl;hasRequiredCodemirrorLangEmbedGlsl=1;const{glslLanguage,glsl}=require$$0,{matchTagName}=require$$1;return codemirrorLangEmbedGlsl={createEmbedding},codemirrorLangEmbedGlsl}const module={exports:exports};var codemirrorLangEmbedGlsl,hasRequiredCodemirrorLangEmbedGlsl,require$$0=await requireAsyncModule("@actualwave/codemirror-lang-glsl"),require$$1=await requireAsyncModule("@actualwave/codemirror-lang-embed-core"),codemirrorLangEmbedGlslExports=requireCodemirrorLangEmbedGlsl(),index=/*@__PURE__*/function getDefaultExportFromCjs(x){return x}(codemirrorLangEmbedGlslExports);return module.exports=index,module.exports}