Skip to content
This repository was archived by the owner on Feb 6, 2024. It is now read-only.

Commit c1cbeba

Browse files
feat: style code in docs (#1462)
* feat: edit code style on doc Signed-off-by: peterpeterparker <[email protected]> * feat: exclude attributes Signed-off-by: peterpeterparker <[email protected]> * feat: filter attributes for update paragraphs Signed-off-by: peterpeterparker <[email protected]>
1 parent bb123c2 commit c1cbeba

File tree

5 files changed

+42
-11
lines changed

5 files changed

+42
-11
lines changed

studio/src/app/config/editor.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,6 @@ import {codeMenu} from '../menus/code.menu';
1010

1111
export const editorConfig: Partial<StyloConfig> = {
1212
plugins: [h1, h2, h3, ul, imgStorage, imgUnsplash, imgGif, code, hr],
13-
menus: [codeMenu]
13+
menus: [codeMenu],
14+
excludeAttributes: ['id', 'hydrated', 'editable', 'paragraph_id', 'highlighted', 'custom-loader']
1415
};

studio/src/app/events/editor/doc/doc.data.events.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import {
1313
deleteOfflineParagraph,
1414
updateOfflineParagraph
1515
} from '../../../providers/data/paragraph/paragraph.offline.provider';
16+
import {editorConfig} from '../../../config/editor';
1617

1718
export class DocDataEvents {
1819
init() {
@@ -273,7 +274,8 @@ export class DocDataEvents {
273274

274275
private paragraphAttributes(paragraph: HTMLElement): Record<string, string | number | boolean | undefined> | null {
275276
const attrs: Attr[] = Array.from(paragraph.attributes).filter(
276-
({nodeName}: Attr) => !['id', 'hydrated', 'class', 'contenteditable', 'paragraph_id'].includes(nodeName)
277+
({nodeName}: Attr) =>
278+
!['placeholder', 'data-gramm', 'class', 'spellcheck', 'contenteditable', ...editorConfig.excludeAttributes].includes(nodeName)
277279
);
278280

279281
return attrs.length > 0

studio/src/app/menus/code.menu.ts

Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,20 @@
1-
import {StyloMenu} from '@papyrs/stylo';
21
import {popoverController} from '@ionic/core';
32

3+
import {StyloMenu} from '@papyrs/stylo';
4+
5+
import {SelectedTarget} from '../types/editor/selected-target';
6+
7+
import {SelectedElementUtils} from '../utils/editor/selected-element.utils';
8+
49
export const codeMenu: StyloMenu = {
510
match: ({paragraph}: {paragraph: HTMLElement}) => paragraph?.nodeName.toLowerCase() === 'deckgo-highlight-code',
611
actions: [
712
{
813
text: 'edit_code',
9-
icon: `<svg xmlns='http://www.w3.org/2000/svg' width='20' height='20' viewBox='0 0 512 512'>
10-
<polygon points='364.13 125.25 87 403 64 448 108.99 425 386.75 147.87 364.13 125.25' style='fill:none;stroke:currentColor;stroke-linecap:round;stroke-linejoin:round;stroke-width:32px'/>
11-
<path d='M420.69,68.69,398.07,91.31l22.62,22.63,22.62-22.63a16,16,0,0,0,0-22.62h0A16,16,0,0,0,420.69,68.69Z' style='fill:none;stroke:currentColor;stroke-linecap:round;stroke-linejoin:round;stroke-width:32px'/>
12-
</svg>`,
14+
icon: `<svg xmlns="http://www.w3.org/2000/svg" width='20' height='20' viewBox="0 0 512 512">
15+
<path d="M384 224v184a40 40 0 01-40 40H104a40 40 0 01-40-40V168a40 40 0 0140-40h167.48" fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="32"/>
16+
<path d="M459.94 53.25a16.06 16.06 0 00-23.22-.56L424.35 65a8 8 0 000 11.31l11.34 11.32a8 8 0 0011.34 0l12.06-12c6.1-6.09 6.67-16.01.85-22.38zM399.34 90L218.82 270.2a9 9 0 00-2.31 3.93L208.16 299a3.91 3.91 0 004.86 4.86l24.85-8.35a9 9 0 003.93-2.31L422 112.66a9 9 0 000-12.66l-9.95-10a9 9 0 00-12.71 0z"/>
17+
</svg>`,
1318
action: async ({paragraph}: {paragraph: HTMLElement}) => {
1419
const editCode: CustomEvent<void> = new CustomEvent<void>('editCode', {
1520
bubbles: true
@@ -18,6 +23,29 @@ export const codeMenu: StyloMenu = {
1823
paragraph.dispatchEvent(editCode);
1924
}
2025
},
26+
{
27+
text: 'style',
28+
icon: `<svg xmlns='http://www.w3.org/2000/svg' width='20' height='20' viewBox='0 0 512 512'>
29+
<path d='M452.37,59.63h0a40.49,40.49,0,0,0-57.26,0L184,294.74c23.08,4.7,46.12,27.29,49.26,49.26L452.37,116.89A40.49,40.49,0,0,0,452.37,59.63Z' style='fill:none;stroke:currentColor;stroke-linecap:round;stroke-linejoin:round;stroke-width:32px'/>
30+
<path d='M138,336c-29.88,0-54,24.5-54,54.86,0,23.95-20.88,36.57-36,36.57C64.56,449.74,92.82,464,120,464c39.78,0,72-32.73,72-73.14C192,360.5,167.88,336,138,336Z' style='fill:none;stroke:currentColor;stroke-linecap:round;stroke-linejoin:round;stroke-width:32px'/>
31+
</svg>`,
32+
action: async ({paragraph}: {paragraph: HTMLElement}) => {
33+
const popover: HTMLIonPopoverElement = await popoverController.create({
34+
component: 'app-element-style',
35+
componentProps: {
36+
selectedTarget: {
37+
target: paragraph,
38+
...(SelectedElementUtils.initDescription(paragraph) as SelectedTarget)
39+
}
40+
},
41+
mode: 'ios',
42+
showBackdrop: false,
43+
cssClass: 'popover-menu'
44+
});
45+
46+
await popover.present();
47+
}
48+
},
2149
{
2250
text: 'options',
2351
icon: `<svg xmlns='http://www.w3.org/2000/svg' width='20' height='20' viewBox='0 0 512 512'>

studio/src/app/popovers/editor/style/app-element-style/app-element-style.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@ export class AppElementStyle {
2020
selectedTarget: SelectedTarget;
2121

2222
@Prop()
23-
imgDidChange: EventEmitter<HTMLElement>;
23+
imgDidChange?: EventEmitter<HTMLElement>;
2424

2525
@Prop()
26-
imageHelper: ImageHelper;
26+
imageHelper?: ImageHelper;
2727

2828
@Event() optionsDidChange: EventEmitter<void>;
2929

studio/src/components.d.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -197,8 +197,8 @@ export namespace Components {
197197
interface AppEditor {
198198
}
199199
interface AppElementStyle {
200-
"imageHelper": ImageHelper;
201-
"imgDidChange": EventEmitter<HTMLElement>;
200+
"imageHelper"?: ImageHelper;
201+
"imgDidChange"?: EventEmitter<HTMLElement>;
202202
"selectedTarget": SelectedTarget;
203203
}
204204
interface AppEmbed {

0 commit comments

Comments
 (0)