-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Convert to TypeScript / Add storybook #68
Changes from 7 commits
4964332
3431083
b224e05
ee1b7f1
7547e7b
3a2d781
b72aa6a
f89e356
d3fb820
205ef84
93004f7
421a2a9
4899443
3e67a87
962f3cf
e283208
1cd63bf
4aa9bfd
4c0faca
83c32f5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,3 +4,6 @@ debug.log | |
yarn-error.log | ||
.DS_Store | ||
.eslintcache | ||
dist/ | ||
storybook-static/ | ||
demo-storybook/ |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
{ | ||
"eslint.validate": [ "javascript" ], | ||
"editor.codeActionsOnSave": { | ||
"source.fixAll.eslint": true | ||
"source.fixAll.eslint": "explicit" | ||
} | ||
} |
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -1,16 +1,47 @@ | ||||||||||||||
import { component, html } from '@pionjs/pion'; | ||||||||||||||
import { Tree, Node } from '@neovici/cosmoz-tree/cosmoz-tree'; | ||||||||||||||
|
||||||||||||||
export const computePathToRender = (path, hideFromRoot, showMaxNodes) => { | ||||||||||||||
export type ComputePathTextType = { | ||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should not include the word There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since this uses some properties from Options we can reuse. See https://www.typescriptlang.org/docs/handbook/utility-types.html#picktype-keys
Suggested change
|
||||||||||||||
ownerTree: Tree; | ||||||||||||||
ellipsis: string; | ||||||||||||||
pathToRender: string | undefined; | ||||||||||||||
path: string; | ||||||||||||||
valueProperty: string; | ||||||||||||||
pathSeparator: string | undefined; | ||||||||||||||
}; | ||||||||||||||
|
||||||||||||||
export type RenderType = { | ||||||||||||||
title: string; | ||||||||||||||
text: string; | ||||||||||||||
}; | ||||||||||||||
|
||||||||||||||
export type TreenodeType = { | ||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Props |
||||||||||||||
valueProperty: string; | ||||||||||||||
pathSeparator: string; | ||||||||||||||
hideFromRoot: number; | ||||||||||||||
showMaxNodes: number; | ||||||||||||||
keyProperty: string; | ||||||||||||||
keyValue: string; | ||||||||||||||
ownerTree: Tree; | ||||||||||||||
ellipsis: string; | ||||||||||||||
fallback: string; | ||||||||||||||
}; | ||||||||||||||
|
||||||||||||||
export const computePathToRender = ( | ||||||||||||||
path?: string, | ||||||||||||||
hideFromRoot?: number, | ||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. hideFromRoot and showMaxNodes can't be optional. |
||||||||||||||
showMaxNodes?: number, | ||||||||||||||
) => { | ||||||||||||||
if (!path) { | ||||||||||||||
return; | ||||||||||||||
} | ||||||||||||||
let pathToRender = path; | ||||||||||||||
if (hideFromRoot > 0 && path.length > hideFromRoot) { | ||||||||||||||
Check failure on line 39 in src/cosmoz-treenode.ts GitHub Actions / build / build
|
||||||||||||||
pathToRender = path.slice(hideFromRoot); | ||||||||||||||
} | ||||||||||||||
|
||||||||||||||
if (showMaxNodes > 0 && pathToRender.length > showMaxNodes) { | ||||||||||||||
Check failure on line 43 in src/cosmoz-treenode.ts GitHub Actions / build / build
|
||||||||||||||
pathToRender = path.slice(-showMaxNodes); | ||||||||||||||
} | ||||||||||||||
return pathToRender; | ||||||||||||||
}, | ||||||||||||||
|
@@ -20,7 +51,7 @@ | |||||||||||||
* @param {Array} inputPath Array of path parts | ||||||||||||||
* @returns {Array} Array with defined parts | ||||||||||||||
*/ | ||||||||||||||
getKnownPath = (inputPath) => { | ||||||||||||||
getKnownPath = (inputPath: (Node | undefined)[] | null) => { | ||||||||||||||
let path = inputPath; | ||||||||||||||
if (!Array.isArray(path) || path.length === 0) { | ||||||||||||||
return path; | ||||||||||||||
|
@@ -36,7 +67,7 @@ | |||||||||||||
} | ||||||||||||||
return path; | ||||||||||||||
}, | ||||||||||||||
computePath = (ownerTree, keyProperty, keyValue) => { | ||||||||||||||
computePath = (ownerTree: Tree, keyProperty: string, keyValue: string) => { | ||||||||||||||
// HACK(pasleq): Cosmoz.Tree API needs to be fixed to avoid such code in components | ||||||||||||||
let path = null; | ||||||||||||||
|
||||||||||||||
|
@@ -62,13 +93,13 @@ | |||||||||||||
path, | ||||||||||||||
valueProperty, | ||||||||||||||
pathSeparator, | ||||||||||||||
}) => { | ||||||||||||||
}: ComputePathTextType) => { | ||||||||||||||
if (!pathToRender) { | ||||||||||||||
return ''; | ||||||||||||||
} | ||||||||||||||
|
||||||||||||||
const stringParts = pathToRender.map((node) => | ||||||||||||||
Check failure on line 101 in src/cosmoz-treenode.ts GitHub Actions / build / build
|
||||||||||||||
ownerTree.getProperty(node, valueProperty) | ||||||||||||||
ownerTree.getProperty(node, valueProperty), | ||||||||||||||
); | ||||||||||||||
|
||||||||||||||
let text = stringParts.join(pathSeparator); | ||||||||||||||
|
@@ -78,7 +109,7 @@ | |||||||||||||
} | ||||||||||||||
return text; | ||||||||||||||
}, | ||||||||||||||
render = ({ title, text }) => html` | ||||||||||||||
render = ({ title, text }: RenderType) => html` | ||||||||||||||
<style> | ||||||||||||||
:host { | ||||||||||||||
display: block; | ||||||||||||||
|
@@ -111,10 +142,10 @@ | |||||||||||||
ownerTree, | ||||||||||||||
ellipsis = '… / ', | ||||||||||||||
fallback, | ||||||||||||||
}) => { | ||||||||||||||
}: TreenodeType) => { | ||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since this i component I'd simply name this |
||||||||||||||
const path = computePath(ownerTree, keyProperty, keyValue); | ||||||||||||||
if (!path) return render({ text: fallback, title: fallback }); | ||||||||||||||
const pathToRender = computePathToRender(path, hideFromRoot, showMaxNodes), | ||||||||||||||
opts = { | ||||||||||||||
ownerTree, | ||||||||||||||
ellipsis, | ||||||||||||||
|
@@ -123,13 +154,13 @@ | |||||||||||||
pathSeparator, | ||||||||||||||
}; | ||||||||||||||
return render({ | ||||||||||||||
text: computePathText({ | ||||||||||||||
Check failure on line 157 in src/cosmoz-treenode.ts GitHub Actions / build / build
|
||||||||||||||
...opts, | ||||||||||||||
pathToRender, | ||||||||||||||
}), | ||||||||||||||
title: computePathText({ | ||||||||||||||
...opts, | ||||||||||||||
pathToRender: path, | ||||||||||||||
}), | ||||||||||||||
}); | ||||||||||||||
}; | ||||||||||||||
|
@@ -152,5 +183,5 @@ | |||||||||||||
'show-max-nodes', | ||||||||||||||
'fallback', | ||||||||||||||
], | ||||||||||||||
}) | ||||||||||||||
}), | ||||||||||||||
); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"extends": "./tsconfig.json", | ||
"compilerOptions": { | ||
"outDir": "dist", | ||
"declaration": true, | ||
"noEmit": false | ||
}, | ||
"include": [ | ||
"src" | ||
] | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{ | ||
"compilerOptions": { | ||
"allowSyntheticDefaultImports": true, | ||
"noEmit": true, | ||
"module": "esnext", | ||
"moduleResolution": "bundler", | ||
"strict": true, | ||
"target": "esnext", | ||
"allowJs": true, | ||
"types": [ | ||
"node", | ||
"mocha" | ||
] | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't
@web/storybook-builder
and@web/storybook-framework-web-components
enough ? Do we need to add all the@storybook/*
plugin to deps?