generated from Tinkoff/angular-open-source-starter
-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(demo): add
Stackblitz
integration for documentation examples (#…
…158)
- Loading branch information
1 parent
7c79212
commit 0815b8e
Showing
11 changed files
with
94 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
28 changes: 0 additions & 28 deletions
28
projects/demo/src/pages/stackblitz-starter/stackblitz.service.ts
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
```ts | ||
import './styles.css'; | ||
import {Maskito} from '@maskito/core'; | ||
import mask from './mask'; | ||
|
||
const element: HTMLInputElement | HTMLTextAreaElement | null = document.querySelector('input, textarea'); | ||
|
||
if (element) { | ||
const maskedElement = new Maskito(element, mask); | ||
|
||
console.info('Call this function when the element is detached from DOM', maskedElement.destroy); | ||
} | ||
``` |
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import {Injectable} from '@angular/core'; | ||
import stackblitz, {OpenOptions, Project} from '@stackblitz/sdk'; | ||
import { | ||
TuiCodeEditor, | ||
tuiRawLoad, | ||
tuiTryParseMarkdownCodeBlock, | ||
} from '@taiga-ui/addon-doc'; | ||
|
||
@Injectable() | ||
export class StackblitzService implements TuiCodeEditor { | ||
private readonly baseProjectConfigs: Pick<Project, 'dependencies' | 'template'> = { | ||
template: `typescript`, | ||
dependencies: { | ||
'@maskito/core': '*', | ||
'@maskito/kit': '*', | ||
}, | ||
}; | ||
|
||
readonly name = 'Stackblitz'; | ||
|
||
async edit( | ||
component: string, | ||
id: string, | ||
files: Record<string, string>, | ||
): Promise<void> { | ||
const [tsMd, css] = await Promise.all( | ||
[import('./files/example.ts.md?raw'), import('./files/styles.css?raw')].map( | ||
tuiRawLoad, | ||
), | ||
); | ||
|
||
return stackblitz.openProject( | ||
{ | ||
...this.baseProjectConfigs, | ||
title: `maskito/${component}/${id}`, | ||
description: `Maskito example of the component ${component}`, | ||
files: { | ||
'index.html': component.includes('textarea') | ||
? `<textarea></textarea>` | ||
: `<input />`, | ||
'styles.css': css, | ||
'index.ts': tuiTryParseMarkdownCodeBlock(tsMd)[0], | ||
'mask.ts': files['MaskitoOptions'], | ||
}, | ||
}, | ||
{openFile: 'index.ts,mask.ts'}, | ||
); | ||
} | ||
|
||
openStarter( | ||
{title, description, files}: Pick<Project, 'description' | 'files' | 'title'>, | ||
openOptions?: OpenOptions, | ||
): void { | ||
return stackblitz.openProject( | ||
{ | ||
...this.baseProjectConfigs, | ||
title, | ||
description, | ||
files, | ||
}, | ||
openOptions, | ||
); | ||
} | ||
} |