Skip to content

Commit c62a62c

Browse files
Merge pull request #1 from phillip-kruger/main
Inital migration
2 parents bae0b91 + b1773d2 commit c62a62c

22 files changed

+13084
-1
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
node_modules

README.md

+92-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,93 @@
11
# qui-code-block
2-
Code block component built on Code mirror 6
2+
3+
The code block UI component is based on codemirror 6, wrapped in a Lit webcomponent.
4+
5+
## Installation
6+
7+
```bash
8+
npm i @qomponent/qui-code-block
9+
```
10+
11+
## Usage
12+
13+
```javascript
14+
import '@qomponent/qui-code-block';
15+
```
16+
17+
```html
18+
<qui-code-block mode="properties" theme="dark">
19+
<slot>
20+
foo = bar
21+
</slot>
22+
</qui-code-block>
23+
```
24+
25+
### Modes:
26+
27+
- properties
28+
- js
29+
- java
30+
- xml
31+
- json
32+
- yaml
33+
- sql
34+
- html
35+
- css
36+
- sass
37+
- markdown
38+
39+
### Linenumber
40+
41+
Add `showLineNumbers` attribute. Example:
42+
43+
```html
44+
<qui-code-block mode="properties" theme="dark" showLineNumbers>
45+
<slot>
46+
foo = bar
47+
</slot>
48+
</qui-code-block>
49+
```
50+
51+
### Editable
52+
53+
Add `editable` attribute. Example:
54+
55+
```html
56+
<qui-code-block id="code" mode="properties" theme="dark" value='${this._value}' editable>
57+
<slot>
58+
foo = bar
59+
</slot>
60+
</qui-code-block>
61+
```
62+
63+
You can get the value at any time by looking at the value attribute that you set (it's reflective) or you
64+
can add a listener `shiftEnter` that will contain the new value in `event.detail.content` when Shift-Enter is pressed.
65+
66+
```javascript
67+
let newValue = this.shadowRoot.getElementById('code').getAttribute('value');
68+
```
69+
70+
### Theme
71+
72+
Add attribute `theme`. Value can be `dark` or `light`;
73+
74+
## Example
75+
76+
To run the example:
77+
78+
```bash
79+
npm install
80+
npm start
81+
```
82+
83+
84+
Then go to [http://localhost:8080/example](http://localhost:8080/example)
85+
86+
## Contributing
87+
88+
Pull requests are welcome. For major changes, please open an issue first
89+
to discuss what you would like to change.
90+
91+
## License
92+
93+
[Apache 2](http://www.apache.org/licenses/LICENSE-2.0)

asciiarmor.js

+107
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
// From @codemirror/legacy-modes
2+
function errorIfNotEmpty(stream) {
3+
4+
var nonWS = stream.match(/^\s*\S/);
5+
6+
stream.skipToEnd();
7+
8+
return nonWS ? "error" : null;
9+
10+
}
11+
12+
13+
export const asciiArmor = {
14+
15+
name: "asciiarmor",
16+
17+
token: function(stream, state) {
18+
19+
var m;
20+
21+
if (state.state == "top") {
22+
23+
if (stream.sol() && (m = stream.match(/^-----BEGIN (.*)?-----\s*$/))) {
24+
25+
state.state = "headers";
26+
27+
state.type = m[1];
28+
29+
return "tag";
30+
31+
}
32+
33+
return errorIfNotEmpty(stream);
34+
35+
} else if (state.state == "headers") {
36+
37+
if (stream.sol() && stream.match(/^\w+:/)) {
38+
39+
state.state = "header";
40+
41+
return "atom";
42+
43+
} else {
44+
45+
var result = errorIfNotEmpty(stream);
46+
47+
if (result) state.state = "body";
48+
49+
return result;
50+
51+
}
52+
53+
} else if (state.state == "header") {
54+
55+
stream.skipToEnd();
56+
57+
state.state = "headers";
58+
59+
return "string";
60+
61+
} else if (state.state == "body") {
62+
63+
if (stream.sol() && (m = stream.match(/^-----END (.*)?-----\s*$/))) {
64+
65+
if (m[1] != state.type) return "error";
66+
67+
state.state = "end";
68+
69+
return "tag";
70+
71+
} else {
72+
73+
if (stream.eatWhile(/[A-Za-z0-9+\/=]/)) {
74+
75+
return null;
76+
77+
} else {
78+
79+
stream.next();
80+
81+
return "error";
82+
83+
}
84+
85+
}
86+
87+
} else if (state.state == "end") {
88+
89+
return errorIfNotEmpty(stream);
90+
91+
}
92+
93+
},
94+
95+
blankLine: function(state) {
96+
97+
if (state.state == "headers") state.state = "body";
98+
99+
},
100+
101+
startState: function() {
102+
103+
return {state: "top", type: null};
104+
105+
}
106+
107+
};

0 commit comments

Comments
 (0)