-
Notifications
You must be signed in to change notification settings - Fork 15.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
23 changed files
with
528 additions
and
963 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 24 additions & 19 deletions
43
packages/editor-ui/src/components/CodeNodeEditor/constants.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,39 @@ | ||
import { STICKY_NODE_TYPE } from '@/constants'; | ||
import type { Diagnostic } from '@codemirror/lint'; | ||
import type { CodeExecutionMode, CodeNodeEditorLanguage } from 'n8n-workflow'; | ||
|
||
export const NODE_TYPES_EXCLUDED_FROM_AUTOCOMPLETION = [STICKY_NODE_TYPE]; | ||
|
||
export const DEFAULT_LINTER_SEVERITY: Diagnostic['severity'] = 'error'; | ||
|
||
export const DEFAULT_LINTER_DELAY_IN_MS = 300; | ||
|
||
/** | ||
* Length of the start of the script wrapper, used as offset for the linter to find a location in source text. | ||
*/ | ||
export const OFFSET_FOR_SCRIPT_WRAPPER = 'module.exports = async function() {'.length; | ||
|
||
export const ALL_ITEMS_PLACEHOLDER = ` | ||
// Loop over input items and add a new field | ||
// called 'myNewField' to the JSON of each one | ||
export const CODE_PLACEHOLDERS: Partial< | ||
Record<CodeNodeEditorLanguage, Record<CodeExecutionMode, string>> | ||
> = { | ||
javaScript: { | ||
runOnceForAllItems: ` | ||
// Loop over input items and add a new field called 'myNewField' to the JSON of each one | ||
for (const item of $input.all()) { | ||
item.json.myNewField = 1; | ||
} | ||
return $input.all(); | ||
`.trim(); | ||
|
||
export const EACH_ITEM_PLACEHOLDER = ` | ||
// Add a new field called 'myNewField' to the | ||
// JSON of the item | ||
return $input.all();`.trim(), | ||
runOnceForEachItem: ` | ||
// Add a new field called 'myNewField' to the JSON of the item | ||
$input.item.json.myNewField = 1; | ||
return $input.item; | ||
`.trim(); | ||
|
||
export const CODE_LANGUAGES = ['javaScript', 'json', 'python'] as const; | ||
export const CODE_MODES = ['runOnceForAllItems', 'runOnceForEachItem'] as const; | ||
return $input.item;`.trim(), | ||
}, | ||
python: { | ||
runOnceForAllItems: ` | ||
# Loop over input items and add a new field called 'myNewField' to the JSON of each one | ||
for item in _input.all(): | ||
item.json.myNewField = 1 | ||
return _input.all()`.trim(), | ||
runOnceForEachItem: ` | ||
# Add a new field called 'myNewField' to the JSON of the item | ||
_input.item.json.myNewField = 1 | ||
return _input.item`.trim(), | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
...s/editor-ui/src/components/CodeNodeEditor/javaScript/completions/variables.completions.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,15 @@ | ||
import type { EditorView } from '@codemirror/view'; | ||
import type { I18nClass } from '@/plugins/i18n'; | ||
import type { Workflow } from 'n8n-workflow'; | ||
import type { Workflow, CodeExecutionMode } from 'n8n-workflow'; | ||
import type { Node } from 'estree'; | ||
import type { CODE_LANGUAGES, CODE_MODES } from './constants'; | ||
|
||
export type CodeNodeEditorMixin = Vue.VueConstructor< | ||
Vue & { | ||
$locale: I18nClass; | ||
editor: EditorView | null; | ||
mode: 'runOnceForAllItems' | 'runOnceForEachItem'; | ||
mode: CodeExecutionMode; | ||
getCurrentWorkflow(): Workflow; | ||
} | ||
>; | ||
|
||
export type RangeNode = Node & { range: [number, number] }; | ||
|
||
export type CodeLanguage = (typeof CODE_LANGUAGES)[number]; | ||
export type CodeMode = (typeof CODE_MODES)[number]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.