@actualwave/codemirror-lang-embed-css 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/index.js +35 -0
  2. package/package.json +22 -0
package/index.js ADDED
@@ -0,0 +1,35 @@
1
+ const { cssLanguage, css } = require('@codemirror/lang-css');
2
+
3
+ // Matches the bare `css` tag as well as any styled-components-shaped tag:
4
+ // `styled.View`/`styled.Text`/... (MemberExpression) and `styled(Component)`
5
+ // (CallExpression, which readIdentifierPath collapses to the callee's own
6
+ // path, so it also resolves to a `['styled', ...]` path).
7
+ function matchCssTag(tagPath) {
8
+ return tagPath[0] === 'css' || tagPath[0] === 'styled';
9
+ }
10
+
11
+ // css`...`/styled`...` content is a bare declaration list (`color: #fff;
12
+ // padding: 12px;`), not a full stylesheet with a `selector { ... }` wrapper.
13
+ // Parsed with cssLanguage's default "StyleSheet" top rule, the parser treats
14
+ // that content as sitting *before* any rule block, so cssCompletionSource
15
+ // (which only offers property names when the cursor's ancestor is "Block" or
16
+ // "Styles" — see @codemirror/lang-css's completion.js) falls back to
17
+ // selector/tag-name completion instead (hence "main"/"small"/"summary").
18
+ // @codemirror/lang-html hits this exact same shape for `style="..."`
19
+ // attribute values and fixes it by reparsing with the grammar's alternate
20
+ // "Styles" top rule (see its dist: `cssLanguage.parser.configure({top:
21
+ // "Styles"})`) — same grammar, same NodeSet, so the languageDataProp
22
+ // (autocomplete source) attached at cssLanguage's original definition still
23
+ // resolves correctly off the "Styles" top node. Only `.parser` is used here;
24
+ // embed-core's registry never touches other Language fields (see resolve()).
25
+ const stylesParser = cssLanguage.parser.configure({ top: 'Styles' });
26
+
27
+ function createEmbedding() {
28
+ return {
29
+ matcher: matchCssTag,
30
+ language: { parser: stylesParser },
31
+ extension: css().support,
32
+ };
33
+ }
34
+
35
+ module.exports = { createEmbedding };
package/package.json ADDED
@@ -0,0 +1,22 @@
1
+ {
2
+ "name": "@actualwave/codemirror-lang-embed-css",
3
+ "version": "0.1.0",
4
+ "description": "Registers `css`/`styled.*`/`styled(...)` tagged-template tags for embedded CSS highlighting inside JS/TSX",
5
+ "main": "index.js",
6
+ "license": "MIT",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "https://github.com/burdiuz/codemorror-lang-modules.git",
10
+ "directory": "packages/embed-css"
11
+ },
12
+ "bugs": {
13
+ "url": "https://github.com/burdiuz/codemorror-lang-modules/issues"
14
+ },
15
+ "homepage": "https://github.com/burdiuz/codemorror-lang-modules/tree/main/packages/embed-css",
16
+ "dependencies": {
17
+ "@actualwave/codemirror-lang-embed-core": "*"
18
+ },
19
+ "peerDependencies": {
20
+ "@codemirror/lang-css": "^6.0.0"
21
+ }
22
+ }