Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"changes": [
{
"packageName": "@coze-editor/code-language-typescript",
"comment": "support jsx folding",
"type": "minor"
}
],
"packageName": "@coze-editor/code-language-typescript",
"email": "hanchayi@163.com"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"changes": [
{
"packageName": "@coze-editor/lang-javascript",
"comment": "support jsx folding",
"type": "minor"
}
],
"packageName": "@coze-editor/lang-javascript",
"email": "hanchayi@163.com"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"changes": [
{
"packageName": "@coze-editor/preset-code-languages",
"comment": "support jsx folding",
"type": "minor"
}
],
"packageName": "@coze-editor/preset-code-languages",
"email": "hanchayi@163.com"
}
57 changes: 50 additions & 7 deletions common/config/subspaces/default/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/text-editor/code-language-typescript/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"lint": "eslint && tsc --noEmit"
},
"dependencies": {
"@codemirror/lang-javascript": "^6.2.1",
"@coze-editor/lang-javascript": "workspace:*",
"@lukeed/uuid": "^2.0.1",
"@typescript/vfs": "^1.6.1",
"comlink": "^4.4.2",
Expand Down
2 changes: 1 addition & 1 deletion packages/text-editor/code-language-typescript/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) 2025 coze-dev
// SPDX-License-Identifier: MIT

import { typescriptLanguage } from '@codemirror/lang-javascript';
import { typescriptLanguage } from '@coze-editor/lang-javascript';

import {
TypeScriptLanguageService,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@
},
{
"path": "../eslint-config/tsconfig.build.json"
},
{
"path": "../lang-javascript/tsconfig.build.json"
}
]
}
2 changes: 1 addition & 1 deletion packages/text-editor/dev/src/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { createRoot } from 'react-dom/client';
import Page from './pages/chat';
import Page from './pages/highlight';
import './index.css';

createRoot(document.getElementById('app')!).render(<Page />);
15 changes: 11 additions & 4 deletions packages/text-editor/dev/src/pages/highlight/examples.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,17 @@ import React from 'react';

function App() {
return (
<div>
<h1>Hello World</h1>
{/* hello() */}
</div>
<>
<div
a="sdf"
>
<h1>Hello World</h1>
{/* hello() */}
</div>
<a
href="https://www.baidu.com"
/>
</>
);
}

Expand Down
1 change: 1 addition & 0 deletions packages/text-editor/lang-javascript/.npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
//registry.npmjs.org/:_authToken=${NPM_AUTH_TOKEN}
21 changes: 21 additions & 0 deletions packages/text-editor/lang-javascript/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2025 coze-dev

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
7 changes: 7 additions & 0 deletions packages/text-editor/lang-javascript/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
## @coze-editor/lang-javascript

This is a repo copy of [codemirror/lang-javascript](https://github.com/codemirror/lang-javascript/tree/78a85210d83c41bef23c222425f2ebf3d4353e2d).

We have added some features to the original repo, such as:

- JSX folding
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import { describe, it, expect } from 'vitest';
import { EditorState } from '@codemirror/state';
import { foldable } from '@codemirror/language';

import { javascript } from '../src';

function jsxState(doc: string) {
return EditorState.create({ doc, extensions: [javascript({ jsx: true })] });
}

function fold(doc: string) {
const state = jsxState(doc);
const firstLine = doc.slice(0, doc.indexOf('\n'));
const folded = foldable(state, 0, firstLine.length);
if (folded) {
doc = `${doc.slice(0, folded.from)} ... ${doc.slice(folded.to)}`;
}
return doc;
}

describe('JSX folding', () => {
it('should fold self-closing tags', () => {
expect(fold('<div \n />')).toBe('<div ... />');
});

it('should fold self-closing tags with attributes', () => {
expect(fold('<div a="1" \n />')).toBe('<div ... />');
});

it('should fold regular tags', () => {
expect(fold('<div>\n foo</div>')).toBe('<div ... </div>');
});

it('should fold regular tags with attributes', () => {
expect(fold('<div a="1" >\nfoo</div>')).toBe('<div ... </div>');
});

it('should fold regular tags with children', () => {
expect(fold('<div> \n<div>\nbar</div> </div>')).toBe('<div ... </div>');
});

it('should fold fragment tags', () => {
expect(fold('<> \nsdf </>')).toBe('<> ... </>');
});

it('should not fold inline tags', () => {
expect(fold('<div><div></div></div>')).toBe('<div><div></div></div>');
});
});
12 changes: 12 additions & 0 deletions packages/text-editor/lang-javascript/config/rush-project.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"operationSettings": [
{
"operationName": "build",
"outputFolderNames": ["dist"]
},
{
"operationName": "ts-check",
"outputFolderNames": ["./dist"]
}
]
}
8 changes: 8 additions & 0 deletions packages/text-editor/lang-javascript/eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// Copyright (c) 2025 coze-dev
// SPDX-License-Identifier: MIT

const { defineWebConfig } = require('@coze-editor/eslint-config');

module.exports = defineWebConfig({
packageRoot: __dirname,
});
41 changes: 41 additions & 0 deletions packages/text-editor/lang-javascript/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{
"name": "@coze-editor/lang-javascript",
"version": "0.1.0-alpha.3d5d0a",
"description": "lang-javascript",
"license": "MIT",
"author": "zhangyi",
"maintainers": [],
"main": "./dist/esm/index.js",
"module": "./dist/esm/index.js",
"types": "./dist/index.d.ts",
"files": [
"dist"
],
"scripts": {
"build": "tsup",
"lint": "eslint && tsc --noEmit",
"test": "vitest --run --passWithNoTests",
"test:cov": "npm run test -- --coverage"
},
"dependencies": {
"@codemirror/autocomplete": "^6.18.0",
"@codemirror/language": "^6.10.1",
"@codemirror/lint": "^6.0.0",
"@codemirror/state": "^6.4.1",
"@codemirror/view": "^6.26.1",
"@lezer/common": "^1.2.2",
"@lezer/javascript": "^1.4.19"
},
"devDependencies": {
"@coze-arch/vitest-config": "workspace:*",
"@coze-editor/eslint-config": "workspace:*",
"@lezer/lr": "^1.4.0",
"@vitest/coverage-v8": "^3.0.9",
"eslint": "9.14.0",
"vitest": "^3.0.9"
},
"publishConfig": {
"access": "public",
"registry": "https://registry.npmjs.org"
}
}
Loading
Loading