Skip to content

Commit 840c4a0

Browse files
committed
feat: <code>
1 parent 5f0274b commit 840c4a0

File tree

11 files changed

+132
-26
lines changed

11 files changed

+132
-26
lines changed

packages/layout/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313
"keywords": [],
1414
"exports": {
1515
".": {
16-
"import": "./dist/index.js",
17-
"types": "./src/index.ts"
16+
"types": "./src/index.ts",
17+
"import": "./dist/index.js"
1818
}
1919
},
2020
"main": "./dist/index.mjs",

packages/layout/tsup.config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { defineConfig } from "tsup";
1+
import { defineConfig } from 'tsup'
22

33
export default defineConfig({
44
entry: ['./src/index.ts'],

packages/model/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313
"keywords": [],
1414
"exports": {
1515
".": {
16-
"import": "./dist/index.js",
17-
"types": "./src/index.ts"
16+
"types": "./src/index.ts",
17+
"import": "./dist/index.js"
1818
}
1919
},
2020
"main": "./dist/index.mjs",

packages/model/tsup.config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { defineConfig } from "tsup";
1+
import { defineConfig } from 'tsup'
22

33
export default defineConfig({
44
entry: ['./src/index.ts'],

packages/test/src/example.sciux

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@
55
<flexbox>{{ value }}</flexbox>
66
<flexbox>{{ checked }}</flexbox>
77
<rows>
8-
<flexbox>1</flexbox>
8+
<flexbox>
9+
<code language="js">console.log('hello')</code>
10+
</flexbox>
911
<flexbox>1</flexbox>
1012
<flexbox>
1113
<input model="value"/>
@@ -20,8 +22,7 @@
2022
<block>2</block>
2123
<block>3</block>
2224
<block>4</block>
23-
<block>5</block>
24-
<block>6</block>
25+
<canvas :width="100" :height="200"></canvas>
2526
</table>
2627

2728
<!-- 测试垂直布局表格 -->

packages/test/src/main.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { align, block, columns, flexbox, grid, rows } from '@sciux/layout'
2-
import { table } from '@sciux/widget'
32
import { button, checkbox, input, slider } from '@sciux/model'
4-
import { components, render } from 'sciux-laplace'
3+
import { canvas, code, link, table } from '@sciux/widget'
4+
import { components, render, TextMode, textModes } from 'sciux-laplace'
55
import source from './example.sciux?raw'
66

77
components.set('block', block)
@@ -13,7 +13,12 @@ components.set('align', align)
1313
components.set('button', button)
1414
components.set('input', input)
1515
components.set('table', table)
16+
components.set('code', code)
17+
components.set('canvas', canvas)
18+
components.set('link', link)
1619
components.set('checkbox', checkbox)
1720
components.set('slider', slider)
1821

22+
textModes.set('code', TextMode.RCDATA)
23+
1924
render(source, document.getElementById('app')!)

packages/test/tsconfig.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,24 @@
11
{
22
"compilerOptions": {
33
"target": "ES2020",
4+
"lib": ["ES2020", "DOM", "DOM.Iterable"],
5+
"moduleDetection": "force",
46
"useDefineForClassFields": true,
57
"module": "ESNext",
6-
"lib": ["ES2020", "DOM", "DOM.Iterable"],
7-
"skipLibCheck": true,
88

99
/* Bundler mode */
1010
"moduleResolution": "bundler",
1111
"allowImportingTsExtensions": true,
12-
"verbatimModuleSyntax": true,
13-
"moduleDetection": "force",
14-
"noEmit": true,
1512

1613
/* Linting */
1714
"strict": true,
15+
"noFallthroughCasesInSwitch": true,
1816
"noUnusedLocals": true,
1917
"noUnusedParameters": true,
18+
"noEmit": true,
19+
"verbatimModuleSyntax": true,
20+
"skipLibCheck": true,
2021
"erasableSyntaxOnly": true,
21-
"noFallthroughCasesInSwitch": true,
2222
"noUncheckedSideEffectImports": true
2323
},
2424
"include": ["src"]

packages/widget/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
"@sciux/layout": "workspace:^",
3434
"@vue/reactivity": "^3.5.14",
3535
"arktype": "^2.1.20",
36-
"sciux-laplace": "latest"
36+
"sciux-laplace": "latest",
37+
"shiki": "^3.4.2"
3738
}
3839
}

packages/widget/src/code.ts

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/* eslint-disable antfu/no-top-level-await */
2+
import { type } from 'arktype'
3+
import { defineComponent } from 'sciux-laplace'
4+
import { createHighlighter } from 'shiki'
5+
6+
const highlighter = await createHighlighter({
7+
themes: ['github-dark'],
8+
langs: ['js', 'javascript', 'ts', 'typescript', 'python', 'java', 'c', 'cpp', 'c++', 'rust', 'html', 'css', 'sql'],
9+
})
10+
11+
const T = type({
12+
language: 'string',
13+
})
14+
15+
export default defineComponent<'code', typeof T.infer>((attrs) => {
16+
return {
17+
name: 'code',
18+
attrs: T,
19+
setup(children) {
20+
const container = document.createElement('div')
21+
container.style.width = '100%'
22+
container.style.height = '100%'
23+
const kids = children()
24+
// Filter out text nodes
25+
const content = kids[0].textContent ?? ''
26+
const html = highlighter.codeToHtml(content, {
27+
lang: attrs.language.value,
28+
theme: 'github-dark',
29+
})
30+
container.innerHTML = html
31+
return container
32+
},
33+
}
34+
})

packages/widget/src/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,4 @@
1+
export { default as canvas } from './canvas'
2+
export { default as code } from './code'
3+
export { default as link } from './link'
14
export { default as table } from './table'

0 commit comments

Comments
 (0)