@nderscore/tamagui-typescript-plugin
Advanced tools
Comparing version 0.2.0 to 0.3.0
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.getCompletionDetails = void 0; | ||
const getTokenType_1 = require("./getTokenType"); | ||
const getTokens_1 = require("./getTokens"); | ||
const metadata_1 = require("./metadata"); | ||
@@ -20,3 +20,3 @@ const utils_1 = require("./utils"); | ||
logger(`calculating tamagui completion details <$${position}@${fileName}>`); | ||
const type = (0, getTokenType_1.getTokenTypeAtPosition)(fileName, position, config, ctx); | ||
const type = (0, getTokens_1.getTokenType)(fileName, position, config, ctx); | ||
if (!type) | ||
@@ -26,3 +26,2 @@ return original; | ||
const sanitizedEntryName = (0, utils_1.sanitizeMaybeQuotedString)(entryName); | ||
let found = false; | ||
if (type === 'color') { | ||
@@ -36,7 +35,5 @@ const themeValue = config.themeColors[sanitizedEntryName]; | ||
}); | ||
found = true; | ||
return original; | ||
} | ||
} | ||
if (found) | ||
return original; | ||
const [scale, value] = (0, utils_1.getMaybeSpecificToken)(entryName, type, config); | ||
@@ -43,0 +40,0 @@ if (scale && value) { |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.getCompletionsAtPosition = void 0; | ||
const getTokenType_1 = require("./getTokenType"); | ||
exports.getCompletions = void 0; | ||
const getTokens_1 = require("./getTokens"); | ||
const utils_1 = require("./utils"); | ||
@@ -9,3 +9,3 @@ /** | ||
*/ | ||
const getCompletionsAtPosition = (original, { fileName, position, | ||
const getCompletions = (original, { fileName, position, | ||
// options, | ||
@@ -15,3 +15,3 @@ ctx, config, defaultTheme, }) => { | ||
logger(`calculating tamagui completions <$${position}@${fileName}>`); | ||
const type = (0, getTokenType_1.getTokenTypeAtPosition)(fileName, position, config, ctx); | ||
const type = (0, getTokens_1.getTokenType)(fileName, position, config, ctx); | ||
if (!type) | ||
@@ -50,3 +50,3 @@ return original; | ||
}; | ||
exports.getCompletionsAtPosition = getCompletionsAtPosition; | ||
exports.getCompletions = getCompletions; | ||
//# sourceMappingURL=getCompletions.js.map |
@@ -6,2 +6,3 @@ "use strict"; | ||
const getCompletions_1 = require("./getCompletions"); | ||
const getQuickInfo_1 = require("./getQuickInfo"); | ||
/** | ||
@@ -39,3 +40,3 @@ * Binding code for hooks into the language server | ||
return undefined; | ||
return (0, getCompletions_1.getCompletionsAtPosition)(original, { | ||
return (0, getCompletions_1.getCompletions)(original, { | ||
fileName, | ||
@@ -49,2 +50,17 @@ position, | ||
}, | ||
// | ||
getQuickInfoAtPosition(fileName, position) { | ||
const ctx = getContext(); | ||
const { info } = ctx; | ||
const original = info.languageService.getQuickInfoAtPosition(fileName, position); | ||
ctx.logger('HHUHH???????'); | ||
return (0, getQuickInfo_1.getQuickInfo)(original, { | ||
fileName, | ||
position, | ||
ctx, | ||
config, | ||
defaultTheme, | ||
}); | ||
}, | ||
// | ||
}; | ||
@@ -51,0 +67,0 @@ return languageServerHooks; |
@@ -45,4 +45,7 @@ "use strict"; | ||
return makeTable([ | ||
{ value: 'Value', scale: 'Scale' }, | ||
{ value, scale }, | ||
{ scale: 'Scale', value: 'Value' }, | ||
{ | ||
scale: `**${scale}**`, | ||
value, | ||
}, | ||
]); | ||
@@ -49,0 +52,0 @@ }; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.toPascal = exports.sanitizeMaybeQuotedString = exports.getMaybeSpecificToken = exports.getSortText = void 0; | ||
// Detect specific scale tokens ($foo.bar) | ||
const specificTokenPattern = /^\$[A-Za-z]\w+\./; | ||
// Detect specific scale tokens | ||
const specificTokenPattern = /^\$(color|radius|size|space|zIndex)\.(.+)$/; | ||
/** | ||
@@ -14,10 +14,10 @@ * Reformats a token string to be used for sorting | ||
let text = sortText; | ||
if (specificTokenPattern.test(text)) { | ||
// add prefix to specific tokens to sort them last: | ||
text = `__${text}`; | ||
} | ||
// add prefix to specific tokens to sort them last: | ||
text = text.replace(specificTokenPattern, '$zzzzzzzzzz$1.$2'); | ||
// add prefix to numeric portions of tokens to sort them numerically: | ||
text = text.replace(/(-?)(\d+|\btrue$)/, (_, sign, num) => { | ||
return `${sign ? '1' : '0'}${num.padStart(9, '0')}`; | ||
text = text.replace(/(-?)(\d+)/g, (_, sign, num) => { | ||
return `${sign ? '1' : '0'}${num.padStart(12, '0')}`; | ||
}); | ||
// special case for negative text tokens like $-true | ||
text = text.replace(/(^\$|\.)-(\w.+)$/, '$1z$2'); | ||
return text; | ||
@@ -33,3 +33,7 @@ }; | ||
const sanitizedEntryName = (0, exports.sanitizeMaybeQuotedString)(entryName); | ||
const [, scale, token] = (_a = sanitizedEntryName.match(/^\$([a-zA-Z]\w+)\.(.+)$/)) !== null && _a !== void 0 ? _a : ['', defaultScale, sanitizedEntryName]; | ||
const [, scale, token] = (_a = sanitizedEntryName.match(specificTokenPattern)) !== null && _a !== void 0 ? _a : [ | ||
null, | ||
defaultScale, | ||
sanitizedEntryName, | ||
]; | ||
if (!scale || !token) | ||
@@ -36,0 +40,0 @@ return [undefined, undefined]; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.getCompletionDetails = void 0; | ||
const getTokenType_1 = require("./getTokenType"); | ||
const getTokens_1 = require("./getTokens"); | ||
const metadata_1 = require("./metadata"); | ||
@@ -20,3 +20,3 @@ const utils_1 = require("./utils"); | ||
logger(`calculating tamagui completion details <$${position}@${fileName}>`); | ||
const type = (0, getTokenType_1.getTokenTypeAtPosition)(fileName, position, config, ctx); | ||
const type = (0, getTokens_1.getTokenType)(fileName, position, config, ctx); | ||
if (!type) | ||
@@ -26,3 +26,2 @@ return original; | ||
const sanitizedEntryName = (0, utils_1.sanitizeMaybeQuotedString)(entryName); | ||
let found = false; | ||
if (type === 'color') { | ||
@@ -36,7 +35,5 @@ const themeValue = config.themeColors[sanitizedEntryName]; | ||
}); | ||
found = true; | ||
return original; | ||
} | ||
} | ||
if (found) | ||
return original; | ||
const [scale, value] = (0, utils_1.getMaybeSpecificToken)(entryName, type, config); | ||
@@ -43,0 +40,0 @@ if (scale && value) { |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.getCompletionsAtPosition = void 0; | ||
const getTokenType_1 = require("./getTokenType"); | ||
exports.getCompletions = void 0; | ||
const getTokens_1 = require("./getTokens"); | ||
const utils_1 = require("./utils"); | ||
@@ -9,3 +9,3 @@ /** | ||
*/ | ||
const getCompletionsAtPosition = (original, { fileName, position, | ||
const getCompletions = (original, { fileName, position, | ||
// options, | ||
@@ -15,3 +15,3 @@ ctx, config, defaultTheme, }) => { | ||
logger(`calculating tamagui completions <$${position}@${fileName}>`); | ||
const type = (0, getTokenType_1.getTokenTypeAtPosition)(fileName, position, config, ctx); | ||
const type = (0, getTokens_1.getTokenType)(fileName, position, config, ctx); | ||
if (!type) | ||
@@ -50,3 +50,3 @@ return original; | ||
}; | ||
exports.getCompletionsAtPosition = getCompletionsAtPosition; | ||
exports.getCompletions = getCompletions; | ||
//# sourceMappingURL=getCompletions.js.map |
@@ -6,2 +6,3 @@ "use strict"; | ||
const getCompletions_1 = require("./getCompletions"); | ||
const getQuickInfo_1 = require("./getQuickInfo"); | ||
/** | ||
@@ -39,3 +40,3 @@ * Binding code for hooks into the language server | ||
return undefined; | ||
return (0, getCompletions_1.getCompletionsAtPosition)(original, { | ||
return (0, getCompletions_1.getCompletions)(original, { | ||
fileName, | ||
@@ -49,2 +50,17 @@ position, | ||
}, | ||
// | ||
getQuickInfoAtPosition(fileName, position) { | ||
const ctx = getContext(); | ||
const { info } = ctx; | ||
const original = info.languageService.getQuickInfoAtPosition(fileName, position); | ||
ctx.logger('HHUHH???????'); | ||
return (0, getQuickInfo_1.getQuickInfo)(original, { | ||
fileName, | ||
position, | ||
ctx, | ||
config, | ||
defaultTheme, | ||
}); | ||
}, | ||
// | ||
}; | ||
@@ -51,0 +67,0 @@ return languageServerHooks; |
@@ -45,4 +45,7 @@ "use strict"; | ||
return makeTable([ | ||
{ value: 'Value', scale: 'Scale' }, | ||
{ value, scale }, | ||
{ scale: 'Scale', value: 'Value' }, | ||
{ | ||
scale: `**${scale}**`, | ||
value, | ||
}, | ||
]); | ||
@@ -49,0 +52,0 @@ }; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.toPascal = exports.sanitizeMaybeQuotedString = exports.getMaybeSpecificToken = exports.getSortText = void 0; | ||
// Detect specific scale tokens ($foo.bar) | ||
const specificTokenPattern = /^\$[A-Za-z]\w+\./; | ||
// Detect specific scale tokens | ||
const specificTokenPattern = /^\$(color|radius|size|space|zIndex)\.(.+)$/; | ||
/** | ||
@@ -14,10 +14,10 @@ * Reformats a token string to be used for sorting | ||
let text = sortText; | ||
if (specificTokenPattern.test(text)) { | ||
// add prefix to specific tokens to sort them last: | ||
text = `__${text}`; | ||
} | ||
// add prefix to specific tokens to sort them last: | ||
text = text.replace(specificTokenPattern, '$zzzzzzzzzz$1.$2'); | ||
// add prefix to numeric portions of tokens to sort them numerically: | ||
text = text.replace(/(-?)(\d+|\btrue$)/, (_, sign, num) => { | ||
return `${sign ? '1' : '0'}${num.padStart(9, '0')}`; | ||
text = text.replace(/(-?)(\d+)/g, (_, sign, num) => { | ||
return `${sign ? '1' : '0'}${num.padStart(12, '0')}`; | ||
}); | ||
// special case for negative text tokens like $-true | ||
text = text.replace(/(^\$|\.)-(\w.+)$/, '$1z$2'); | ||
return text; | ||
@@ -33,3 +33,7 @@ }; | ||
const sanitizedEntryName = (0, exports.sanitizeMaybeQuotedString)(entryName); | ||
const [, scale, token] = (_a = sanitizedEntryName.match(/^\$([a-zA-Z]\w+)\.(.+)$/)) !== null && _a !== void 0 ? _a : ['', defaultScale, sanitizedEntryName]; | ||
const [, scale, token] = (_a = sanitizedEntryName.match(specificTokenPattern)) !== null && _a !== void 0 ? _a : [ | ||
null, | ||
defaultScale, | ||
sanitizedEntryName, | ||
]; | ||
if (!scale || !token) | ||
@@ -36,0 +40,0 @@ return [undefined, undefined]; |
{ | ||
"name": "@nderscore/tamagui-typescript-plugin", | ||
"version": "0.2.0", | ||
"version": "0.3.0", | ||
"license": "MIT", | ||
@@ -5,0 +5,0 @@ "repository": { |
@@ -9,2 +9,4 @@ # @nderscore/tamagui-typescript-plugin | ||
- Show Tamagui theme/token values on hover | ||
- Graphical previews for color and theme tokens | ||
@@ -26,8 +28,18 @@ | ||
##### Theme tokens | ||
![Theme Token Screenshot](./docs/screenshot_autocomplete_theme.png) | ||
##### Translucent colors | ||
![Translucent Color Screenshot](./docs/screenshot_autocomplete_translucent.png) | ||
##### Sorted space tokens | ||
![Space Token Screenshot](./docs/screenshot_autocomplete_space.png) | ||
##### Quick info on hover | ||
![Quick Info Hover Screenshot](./docs/screenshot_quickinfo.png) | ||
## Setup | ||
@@ -34,0 +46,0 @@ |
import type ts from 'typescript/lib/tsserverlibrary'; | ||
import { getTokenTypeAtPosition } from './getTokenType'; | ||
import { getTokenType } from './getTokens'; | ||
import { | ||
@@ -50,3 +50,3 @@ makeColorTokenDescription, | ||
const type = getTokenTypeAtPosition(fileName, position, config, ctx); | ||
const type = getTokenType(fileName, position, config, ctx); | ||
@@ -59,3 +59,2 @@ if (!type) return original; | ||
let found = false; | ||
if (type === 'color') { | ||
@@ -69,8 +68,6 @@ const themeValue = config.themeColors[sanitizedEntryName]; | ||
}); | ||
found = true; | ||
return original; | ||
} | ||
} | ||
if (found) return original; | ||
const [scale, value] = getMaybeSpecificToken(entryName, type, config); | ||
@@ -77,0 +74,0 @@ if (scale && value) { |
import type ts from 'typescript/lib/tsserverlibrary'; | ||
import { getTokenTypeAtPosition } from './getTokenType'; | ||
import { getTokenType } from './getTokens'; | ||
import { ParsedConfig } from './readConfig'; | ||
@@ -16,3 +16,3 @@ import { TSContext } from './types'; | ||
*/ | ||
export const getCompletionsAtPosition = ( | ||
export const getCompletions = ( | ||
original: ts.WithMetadata<ts.CompletionInfo>, | ||
@@ -39,3 +39,3 @@ { | ||
const type = getTokenTypeAtPosition(fileName, position, config, ctx); | ||
const type = getTokenType(fileName, position, config, ctx); | ||
@@ -42,0 +42,0 @@ if (!type) return original; |
import type ts from 'typescript/lib/tsserverlibrary'; | ||
import { getCompletionDetails } from './getCompletionDetails'; | ||
import { getCompletionsAtPosition } from './getCompletions'; | ||
import { getCompletions } from './getCompletions'; | ||
import { getQuickInfo } from './getQuickInfo'; | ||
import { ParsedConfig } from './readConfig'; | ||
@@ -70,3 +71,3 @@ import { TSContext } from './types'; | ||
return getCompletionsAtPosition(original, { | ||
return getCompletions(original, { | ||
fileName, | ||
@@ -80,2 +81,20 @@ position, | ||
}, | ||
// | ||
getQuickInfoAtPosition(fileName, position) { | ||
const ctx = getContext(); | ||
const { info } = ctx; | ||
const original = info.languageService.getQuickInfoAtPosition( | ||
fileName, | ||
position | ||
); | ||
ctx.logger('HHUHH???????'); | ||
return getQuickInfo(original, { | ||
fileName, | ||
position, | ||
ctx, | ||
config, | ||
defaultTheme, | ||
}); | ||
}, | ||
// | ||
}; | ||
@@ -82,0 +101,0 @@ |
@@ -45,4 +45,7 @@ import color from 'color'; | ||
return makeTable([ | ||
{ value: 'Value', scale: 'Scale' }, | ||
{ value, scale }, | ||
{ scale: 'Scale', value: 'Value' }, | ||
{ | ||
scale: `**${scale}**`, | ||
value, | ||
}, | ||
]); | ||
@@ -49,0 +52,0 @@ }; |
import { ParsedConfig } from './readConfig'; | ||
// Detect specific scale tokens ($foo.bar) | ||
const specificTokenPattern = /^\$[A-Za-z]\w+\./; | ||
// Detect specific scale tokens | ||
const specificTokenPattern = /^\$(color|radius|size|space|zIndex)\.(.+)$/; | ||
@@ -14,10 +14,10 @@ /** | ||
let text = sortText; | ||
if (specificTokenPattern.test(text)) { | ||
// add prefix to specific tokens to sort them last: | ||
text = `__${text}`; | ||
} | ||
// add prefix to specific tokens to sort them last: | ||
text = text.replace(specificTokenPattern, '$zzzzzzzzzz$1.$2'); | ||
// add prefix to numeric portions of tokens to sort them numerically: | ||
text = text.replace(/(-?)(\d+|\btrue$)/, (_, sign, num) => { | ||
return `${sign ? '1' : '0'}${num.padStart(9, '0')}`; | ||
text = text.replace(/(-?)(\d+)/g, (_, sign, num) => { | ||
return `${sign ? '1' : '0'}${num.padStart(12, '0')}`; | ||
}); | ||
// special case for negative text tokens like $-true | ||
text = text.replace(/(^\$|\.)-(\w.+)$/, '$1z$2'); | ||
return text; | ||
@@ -36,5 +36,7 @@ }; | ||
const sanitizedEntryName = sanitizeMaybeQuotedString(entryName); | ||
const [, scale, token] = sanitizedEntryName.match( | ||
/^\$([a-zA-Z]\w+)\.(.+)$/ | ||
) ?? ['', defaultScale, sanitizedEntryName]; | ||
const [, scale, token] = sanitizedEntryName.match(specificTokenPattern) ?? [ | ||
null, | ||
defaultScale, | ||
sanitizedEntryName, | ||
]; | ||
@@ -41,0 +43,0 @@ if (!scale || !token) return [undefined, undefined] as const; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
126537
63
2204
113