Skip to content

Commit 8f6464a

Browse files
committed
feat(vue-to-horizon): 仅还原 dev 工具目录用于 PR
1 parent c51aee9 commit 8f6464a

File tree

193 files changed

+18801
-70994
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

193 files changed

+18801
-70994
lines changed

packages/vue-to-horizon/ep.json

Lines changed: 0 additions & 12 deletions
This file was deleted.

packages/vue-to-horizon/eslint.config.js

Lines changed: 0 additions & 23 deletions
This file was deleted.

packages/vue-to-horizon/libs/horizon-vue/adapters/component.jsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@ export {
1111
* import a from './a.jsx'
1212
* registerComponent('a', a)
1313
*/
14-
registerComponent,
14+
registerComponent,
1515
/**
1616
* 全局加载组件
1717
* import GlobalComponent from 'adapters/component'
1818
* <GlobalComponent componentName={'You Registered component'} {...props} />
1919
*/
20-
GlobalComponent,
20+
GlobalComponent
2121
};
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1+
12
export * from '@cloudsop/horizon-adapter/pinia';
Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1+
12
export function reactiveAssign(reactive, obj = {}) {
23
Object.keys(obj).forEach(key => {
34
reactive[key] = obj[key];
4-
});
5+
})
56
}
67

78
export function vForNumber(n, callback) {
@@ -10,5 +11,27 @@ export function vForNumber(n, callback) {
1011
}
1112
return Array.from(new Array(n).keys()).map(i => {
1213
return callback(i + 1, i);
13-
});
14+
})
15+
}
16+
17+
export function classnames(...args) {
18+
const styleClass = [];
19+
for (let index = 0; index < args.length; index++) {
20+
const item = args[index];
21+
if (item) {
22+
const type = typeof item;
23+
if (Array.isArray(item)) {
24+
styleClass.push(classnames.apply(this, item));
25+
} else if (type === 'object') {
26+
Object.keys(item).forEach(k => {
27+
if (item[k]) {
28+
styleClass.push(this && this[k] || k);
29+
}
30+
});
31+
} else if (type === 'string' || type === 'number') {
32+
styleClass.push(this && this[item] || item);
33+
}
34+
}
35+
}
36+
return styleClass.join(' ');
1437
}

packages/vue-to-horizon/libs/horizon-vue/adapters/vueAdapter.js

Lines changed: 0 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -28,66 +28,4 @@ export const useInstance = vueReactive.useInstance;
2828
export const toInstance = vueReactive.toInstance;
2929
export const markRaw = vueReactive.markRaw;
3030

31-
export function Teleport({ to, children }) {
32-
const container = window.horizon.useState(() => {
33-
document.createElement('div');
34-
});
35-
36-
window.horizon.useEffect(() => {
37-
to.appendChild(container);
38-
39-
return () => {
40-
to.removeChild(container);
41-
};
42-
}, [to, container]);
43-
44-
return window.horizon.createPortal(children, container);
45-
}
46-
47-
export function useWindowSize(options = {}) {
48-
const {
49-
initialWidth = Number.POSITIVE_INFINITY,
50-
initialHeight = Number.POSITIVE_INFINITY,
51-
listenOrientation = true,
52-
includeScrollbar = true,
53-
} = options;
54-
55-
const width = ref(initialWidth);
56-
const height = ref(initialHeight);
57-
58-
function update() {
59-
if (window) {
60-
if (includeScrollbar) {
61-
width.value = window.innerWidth;
62-
height.value = window.innerHeight;
63-
} else {
64-
width.value = window.document.documentElement.clientWidth;
65-
height.value = window.document.documentElement.clientHeight;
66-
}
67-
}
68-
}
69-
70-
update();
71-
72-
window.horizon.useEffect(() => {
73-
window.addEventListener('resize', update);
74-
if (listenOrientation) window.addEventListener('orientationchange', update);
75-
76-
return () => {
77-
window.removeEventListener('resize', update);
78-
if (listenOrientation) window.removeEventListener('orientationchange', update);
79-
};
80-
});
81-
82-
return { width: width.value, height: height.value };
83-
}
84-
85-
export function createVNode(component, props) {
86-
return window.horizon.createElement(component, props, props.children);
87-
}
88-
89-
export function render(vnode, target) {
90-
window.horizon.render(vnode, target);
91-
}
92-
9331
export * from '@cloudsop/horizon-adapter';

packages/vue-to-horizon/libs/horizon-vue/babel.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ module.exports = {
1717
presets: ['@babel/preset-typescript', ['@babel/preset-env', { targets: { node: 'current' } }]],
1818
// 确保启用实验性语法
1919
experimental: {
20-
async: true,
20+
async: true
2121
},
2222
plugins: [
2323
'@babel/plugin-syntax-jsx',

packages/vue-to-horizon/libs/horizon-vue/cli.js

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -221,17 +221,18 @@ function convert(options) {
221221
});
222222
log(handle);
223223

224-
const configPathSrc = _resolve(options.src, '..');
224+
const configPathSrc = _resolve(options.src,'..');
225225
const configPathOut = _resolve(options.out);
226-
console.log('should replace config:', {
227-
path: _resolve(configPathSrc, 'webpackConfig.js'),
228-
target: _resolve(configPathOut, 'webpack.config.js'),
229-
shouldChange: existsSync(_resolve(configPathSrc, 'webpackConfig.js')),
230-
targetExists: existsSync(_resolve(configPathOut, 'webpack.config.js')),
231-
});
232-
if (existsSync(_resolve(configPathSrc, 'webpackConfig.js'))) {
233-
rmSync(_resolve(configPathOut, 'webpack.config.js'));
234-
copyFileSync(_resolve(configPathSrc, 'webpackConfig.js'), _resolve(configPathOut, 'webpack.config.js'));
226+
console.log(
227+
"should replace config:",
228+
{path:_resolve(configPathSrc,'webpackConfig.js'),
229+
target:_resolve(configPathOut,'webpack.config.js'),
230+
shouldChange:existsSync(_resolve(configPathSrc,'webpackConfig.js')),
231+
targetExists: existsSync(_resolve(configPathOut,'webpack.config.js'))}
232+
)
233+
if(existsSync(_resolve(configPathSrc,'webpackConfig.js'))){
234+
rmSync(_resolve(configPathOut,'webpack.config.js'));
235+
copyFileSync(_resolve(configPathSrc,'webpackConfig.js'),_resolve(configPathOut,'webpack.config.js'))
235236
}
236237
}
237238

packages/vue-to-horizon/libs/horizon-vue/src/compileFiles.js

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -72,11 +72,7 @@ function scanPath(vuePath, whitelist, blacklist) {
7272
};
7373
}
7474

75-
function compileFiles(
76-
vueSrcPath,
77-
out,
78-
{ clean = true, jsx = true, whitelist, blacklist, lastBuild, configPath, componentConfigPath }
79-
) {
75+
function compileFiles(vueSrcPath, out, { clean = true, jsx = true, whitelist, blacklist, lastBuild, configPath, componentConfigPath }) {
8076
console.log({ vueSrcPath });
8177
const successLog = [];
8278
const errorLog = [];
@@ -117,7 +113,7 @@ function compileFiles(
117113
keys.forEach(key => {
118114
item.attributesMap[convertToCamelCase(key)] = item.attributesMap[key];
119115
});
120-
});
116+
})
121117
}
122118
} catch (e) {
123119
LOG.error('read component config file failed');

packages/vue-to-horizon/libs/horizon-vue/src/next/convert/baseCovertHandler.js

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@ import { traverse } from '@babel/core';
44
import t from '@babel/types';
55
import SourceCodeContext from './sourceCodeContext.js';
66
import { globalLibPaths } from './defaultConfig.js';
7-
import { INSTANCE } from './jsx/consts.js';
8-
import { addInstance } from './jsx/handlers/instanceHandler.js';
7+
import { INSTANCE } from './jsx/consts.js'
8+
import { addInstance } from './jsx/handlers/instanceHandler.js'
9+
910

1011
export default class BaseCovertHandler {
1112
targetAst = null;
@@ -246,7 +247,10 @@ export default class BaseCovertHandler {
246247
// 检查 targetAst 是否为数组
247248
if (Array.isArray(this.targetAst)) {
248249
this.targetAst.push(exportDefaultStatement);
249-
} else if (this.targetAst.program && Array.isArray(this.targetAst.program.body)) {
250+
} else if (
251+
this.targetAst.program &&
252+
Array.isArray(this.targetAst.program.body)
253+
) {
250254
this.targetAst.program.body.push(exportDefaultStatement);
251255
} else {
252256
console.warn('Unable to add export default statement: unexpected AST structure');
@@ -296,7 +300,10 @@ export default class BaseCovertHandler {
296300

297301
this.addCodeAstToHorizonForOnce('$i18n', () => {
298302
return t.variableDeclaration('const', [
299-
t.variableDeclarator(t.identifier('$i18n'), t.callExpression(t.identifier('useI18n'), [])),
303+
t.variableDeclarator(
304+
t.identifier('$i18n'),
305+
t.callExpression(t.identifier('useI18n'), [])
306+
)
300307
]);
301308
});
302309
}
@@ -328,7 +335,10 @@ export default class BaseCovertHandler {
328335
}
329336

330337
return t.variableDeclaration('const', [
331-
t.variableDeclarator(t.objectPattern(properties), t.callExpression(t.identifier(useMethod), callArgs)),
338+
t.variableDeclarator(
339+
t.objectPattern(properties),
340+
t.callExpression(t.identifier(useMethod), callArgs)
341+
)
332342
]);
333343
}
334344

@@ -340,19 +350,15 @@ export default class BaseCovertHandler {
340350
}
341351

342352
function createBlankReactStr(name, css = [], template = '') {
343-
// 将连字符转换为驼峰命名,确保函数名合法
344-
const validFunctionName = name.replace(/-([a-z])/g, (match, letter) => letter.toUpperCase());
345-
346353
const cssStr = css.map(c => `import './${name}${c.scoped ? '.scoped' : ''}.${c.lang}';`).join('\r\n');
347354
const componentBody = template.trim() ? 'return <TEMPLATE/>;' : 'return <Fragment />;';
348-
const reactImport = template.trim()
349-
? "import React from '@cloudsop/horizon';"
350-
: "import React, { Fragment } from '@cloudsop/horizon';";
355+
const reactImport = template.trim() ?
356+
'import React from \'@cloudsop/horizon\';' : 'import React, { Fragment } from \'@cloudsop/horizon\';';
351357

352358
return `
353359
${reactImport}
354360
${cssStr}
355-
function ${validFunctionName}(rawProps){
361+
function ${name}(rawProps){
356362
${componentBody}
357363
}
358364
`;
@@ -364,9 +370,6 @@ function createBlankReactStr(name, css = [], template = '') {
364370
* @returns
365371
*/
366372
function getAstExportDefaultFunction(ast, name) {
367-
// 将连字符转换为驼峰命名,确保函数名匹配
368-
const validFunctionName = name.replace(/-([a-z])/g, (match, letter) => letter.toUpperCase());
369-
370373
let exportDefaultFunction = null;
371374
traverse(ast, {
372375
ExportDefaultDeclaration(path) {
@@ -380,7 +383,7 @@ function getAstExportDefaultFunction(ast, name) {
380383
}
381384
},
382385
FunctionDeclaration(path) {
383-
if (path.node.id.name === validFunctionName) {
386+
if (path.node.id.name === name) {
384387
exportDefaultFunction = path.node;
385388
path.stop();
386389
}

0 commit comments

Comments
 (0)