Skip to content

Commit

Permalink
chore(demo): improve editor options description
Browse files Browse the repository at this point in the history
  • Loading branch information
splincode committed Dec 10, 2024
1 parent 25289d1 commit 8173b55
Show file tree
Hide file tree
Showing 16 changed files with 273 additions and 150 deletions.
21 changes: 11 additions & 10 deletions projects/demo/src/app/app.pages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,10 @@ export const DEMO_PAGES: TuiDocRoutePages = [
},
{
section: 'Documentation',
title: 'Tokens',
route: `${TuiDemoPath.StarterKit}/Options`,
keywords: 'TUI_EDITOR_OPTIONS, TUI_ATTACH_FILES_LOADER',
},
{
section: 'Documentation',
title: 'Parse options',
route: TuiDemoPath.ParseOptions,
keywords: 'editor, parse, options, preserveWhitespace',
title: 'Options',
route: TuiDemoPath.Options,
keywords:
'editor, parse, options, preserveWhitespace, editor props, tuiEditorOptionsProvider, TUI_EDITOR_OPTIONS',
},
{
section: 'Documentation',
Expand Down Expand Up @@ -66,6 +61,12 @@ export const DEMO_PAGES: TuiDocRoutePages = [
route: TuiDemoPath.Focus,
keywords: 'editor, focus, focusable, wysiwyg, редактор, фокус, html, rich, text',
},
{
section: 'Documentation',
title: 'Upload files',
route: TuiDemoPath.UploadFiles,
keywords: 'attach, files, upload, TUI_ATTACH_FILES_LOADER',
},
{
section: 'Documentation',
title: 'Custom tool',
Expand Down Expand Up @@ -182,7 +183,7 @@ export const DEMO_PAGES: TuiDocRoutePages = [
title: 'Upload',
keywords:
'editor, upload, images, wysiwyg, редактор, текст, html, rich, text',
route: `/${TuiDemoPath.ImagesUpload}`,
route: `/${TuiDemoPath.UploadImages}`,
},
],
},
Expand Down
6 changes: 3 additions & 3 deletions projects/demo/src/app/app.routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ export const routes: Routes = [
title: 'StarterKit',
}),
route({
path: TuiDemoPath.ParseOptions,
loadComponent: async () => import('./pages/parse-options'),
path: TuiDemoPath.Options,
loadComponent: async () => import('./pages/options'),
title: 'ParseOptions',
}),
route({
Expand Down Expand Up @@ -115,7 +115,7 @@ export const routes: Routes = [
title: 'Editor — Preview images',
}),
route({
path: TuiDemoPath.ImagesUpload,
path: TuiDemoPath.UploadImages,
loadComponent: async () => import('./pages/images/upload'),
title: 'Editor — Upload images',
}),
Expand Down
10 changes: 10 additions & 0 deletions projects/demo/src/app/pages/options/examples/2/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<tui-editor
[formControl]="control"
[tools]="builtInTools"
/>

<h4>HTML:</h4>
<tui-editor-socket [content]="control.value || ''" />

<h4>Text:</h4>
<p>{{ control.value }}</p>
55 changes: 55 additions & 0 deletions projects/demo/src/app/pages/options/examples/2/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import {ChangeDetectionStrategy, Component, ViewEncapsulation} from '@angular/core';
import {FormControl, ReactiveFormsModule} from '@angular/forms';
import {TuiAlertService} from '@taiga-ui/core';
import type {TuiEditorOptions} from '@taiga-ui/editor';
import {
TUI_EDITOR_DEFAULT_OPTIONS,
TUI_EDITOR_EXTENSIONS,
TUI_EDITOR_OPTIONS,
TuiEditor,
TuiEditorSocket,
TuiEditorTool,
} from '@taiga-ui/editor';

@Component({
standalone: true,
imports: [ReactiveFormsModule, TuiEditor, TuiEditorSocket],
templateUrl: './index.html',
encapsulation: ViewEncapsulation.None,
changeDetection: ChangeDetectionStrategy.OnPush,
providers: [
{
provide: TUI_EDITOR_OPTIONS,
deps: [TuiAlertService],
useFactory(alerts: TuiAlertService): TuiEditorOptions {
return {
...TUI_EDITOR_DEFAULT_OPTIONS,
editorProps: {
handleDOMEvents: {
keydown: (_, event: KeyboardEvent) => {
if (event.key === 'Enter' && !event.shiftKey) {
alerts
.open('Enter <strong>pressed</strong>')
.subscribe();
}

return true;
},
},
},
};
},
},
{
provide: TUI_EDITOR_EXTENSIONS,
useValue: [
import('@taiga-ui/editor').then(({TuiStarterKit}) => TuiStarterKit),
],
},
],
})
export default class Example {
protected readonly builtInTools = [TuiEditorTool.Undo];

protected control = new FormControl('<p>Hello world</p>');
}
167 changes: 167 additions & 0 deletions projects/demo/src/app/pages/options/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,167 @@
<tui-doc-page
header="Editor"
type="components"
>
<tui-doc-example
id="options"
heading="TUI_EDITOR_OPTIONS"
[description]="info"
>
<ng-template #info>
<p>
You can also passed the default options inherited from
<a
href="https://github.com/ueberdosis/tiptap/blob/develop/packages/core/src/types.ts#L74"
tuiLink
>
TipTap.
</a>
By default you can use a
<code>tuiEditorOptionsProvider</code>
helper to override TUI_EDITOR_OPTIONS.
</p>
</ng-template>

<tui-doc-code [code]="exampleOptions" />

<p>
<strong>Description of the available configurations:</strong>
</p>
<dl>
<dt>
<code>appearance</code>
</dt>
<dd class="tui-space_bottom-5">
<p>Visual presets of interactive components</p>
</dd>

<dt>
<code>colors</code>
</dt>
<dd class="tui-space_bottom-5">
map of colors in toolbar's dropdowns with color-selection.

<p>
It accepts
<code [innerText]="'ReadonlyMap<string, string>'"></code>
: the
<strong>key</strong>
is the name of the color (used only for hint and accessibility), the
<strong>value</strong>
– HTML color code.
</p>
</dd>

<dt>
<code>blankColor</code>
</dt>
<dd class="tui-space_bottom-5">
Null color. It is used in situations when there is no color selected.

<p>
it accepts
<code>string</code>
(HTML color code).
</p>
</dd>

<dt>
<code>fontOptions</code>
</dt>
<dd class="tui-space_bottom-5">You can customize your own list of font sizes in editor.</dd>

<dt>
<code>translate</code>
</dt>
<dd class="tui-space_bottom-5">
Although not all browsers recognize this attribute, it is respected by automatic translation systems
such as Google Translate, and may also be respected by tools used by human translators. As such it's
important that web authors use this attribute to mark content that should not be translated..
</dd>

<dt>
<code>icons</code>
</dt>
<dd class="tui-space_bottom-5">
You can redefine
<a
href="https://github.com/taiga-family/tui-editor/blob/main/projects/tui-editor/tokens/editor-options.ts#L74"
rel="noreferrer"
target="_blank"
tuiLink
>
icons
</a>
by names.
<a
href="https://taiga-ui.dev/icons/mapping"
rel="noreferrer"
target="_blank"
tuiLink
>
More ->
</a>
</dd>

<dt>
<code>spellcheck</code>
</dt>
<dd class="tui-space_bottom-5">Defines whether the editor may be checked for spelling errors.</dd>

<dt>
<code>enableDefaultStyles</code>
</dt>
<dd class="tui-space_bottom-5">
By default, editor styles will be included without encapsulation, if you want your own styles, you can
disable them.
</dd>
</dl>
</tui-doc-example>

<tui-doc-example
id="preserve-whitespace"
heading="Preserve whitespace"
[component]="component1"
[content]="example1"
[description]="first"
>
<ng-template #first>
<p>
Passed content is parsed by ProseMirror. To hook into the parsing, you can pass parseOptions which are
then handled by
<a
href="https://prosemirror.net/docs/ref/#model.ParseOptions"
target="_blank"
tuiLink
>
ProseMirror.
</a>
By default, whitespace is collapsed as per HTML's rules. Pass true to preserve whitespace, but normalize
newlines to spaces, and 'full' to preserve whitespace entirely.
</p>
</ng-template>
</tui-doc-example>

<tui-doc-example
id="editor-props"
heading="Editor Props"
[component]="component2"
[content]="example2"
[description]="second"
>
<ng-template #second>
<p>
For advanced use cases, you can pass editorProps which will be handled by
<a
href="https://prosemirror.net/docs/ref/#view.EditorProps"
target="_blank"
tuiLink
>
ProseMirror
</a>
. You can use it to override various editor events or change editor DOM element attributes, for example
to add some Tailwind classes. Here is an example:
</p>
</ng-template>
</tui-doc-example>
</tui-doc-page>
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,19 @@ import {TuiLink} from '@taiga-ui/core';
changeDetection: ChangeDetectionStrategy.OnPush,
})
export default class Example {
protected readonly exampleOptions = import('./import/tokens/options.md?raw');

protected readonly component1 = import('./examples/1');

protected readonly example1 = {
TypeScript: import('./examples/1/index.ts?raw'),
HTML: import('./examples/1/index.html?raw'),
};

protected readonly component2 = import('./examples/2');

protected readonly example2 = {
TypeScript: import('./examples/2/index.ts?raw'),
HTML: import('./examples/2/index.html?raw'),
};
}
24 changes: 0 additions & 24 deletions projects/demo/src/app/pages/parse-options/index.html

This file was deleted.

Loading

0 comments on commit 8173b55

Please sign in to comment.