Skip to content

Commit

Permalink
feat(deckgo#470): format code
Browse files Browse the repository at this point in the history
Signed-off-by: peterpeterparker <[email protected]>
  • Loading branch information
peterpeterparker committed Jan 25, 2020
1 parent 653c0ef commit 2983e84
Show file tree
Hide file tree
Showing 13 changed files with 338 additions and 330 deletions.
24 changes: 12 additions & 12 deletions utils/deck/src/utils/parse-content.utils.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
export function cleanContent(content: string): Promise<string> {
return new Promise<string>(async (resolve) => {
if (!content || content.length <= 0) {
resolve(content);
return;
}
return new Promise<string>(async (resolve) => {
if (!content || content.length <= 0) {
resolve(content);
return;
}

let result: string = content.replace(/(<.*?)(contenteditable=""|contenteditable="true"|contenteditable="false"|contenteditable)(.*?>)/gi, '$1$3');
result = result.replace(/(<.*?)(editable=""|editable="true"|editable)(.*?>)/gi, '$1$3');
result = result.replace(/(<.*?)(highlighted=""|highlighted="true"|highlighted)(.*?>)/gi, '$1$3');
result = result.replace(/(<.*?)(custom-loader=""|custom-loader="true"|custom-loader)(.*?>)/gi, '$1$3');
result = result.replace(/class="[a-zA-Z0-9:;\.\s\(\)\-\,]*"/gi, '');
let result: string = content.replace(/(<.*?)(contenteditable=""|contenteditable="true"|contenteditable="false"|contenteditable)(.*?>)/gi, '$1$3');
result = result.replace(/(<.*?)(editable=""|editable="true"|editable)(.*?>)/gi, '$1$3');
result = result.replace(/(<.*?)(highlighted=""|highlighted="true"|highlighted)(.*?>)/gi, '$1$3');
result = result.replace(/(<.*?)(custom-loader=""|custom-loader="true"|custom-loader)(.*?>)/gi, '$1$3');
result = result.replace(/class="[a-zA-Z0-9:;\.\s\(\)\-\,]*"/gi, '');

resolve(result);
});
resolve(result);
});
}
40 changes: 20 additions & 20 deletions utils/deck/src/utils/parse-style.utils.ts
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
export function convertStyle(originalStyle: string): Promise<any> {
return new Promise<any>((resolve) => {
if (!originalStyle || originalStyle.length <= 0) {
resolve(undefined);
return;
}
return new Promise<any>((resolve) => {
if (!originalStyle || originalStyle.length <= 0) {
resolve(undefined);
return;
}

const result: any = {};
const result: any = {};

const styles: string[] = originalStyle.split(';');
const styles: string[] = originalStyle.split(';');

if (styles && styles.length > 0) {
styles.forEach((style: string) => {
if (style && style.length > 0) {
const split: string[] = style.split(':');
if (split && split.length > 1) {
result[split[0].trim()] = split[1].trim();
} else if (split && split.length > 0) {
result[split[0].trim()] = undefined;
}
}
});
if (styles && styles.length > 0) {
styles.forEach((style: string) => {
if (style && style.length > 0) {
const split: string[] = style.split(':');
if (split && split.length > 1) {
result[split[0].trim()] = split[1].trim();
} else if (split && split.length > 0) {
result[split[0].trim()] = undefined;
}
}
});
}

resolve(result);
});
resolve(result);
});
}
136 changes: 68 additions & 68 deletions utils/deck/src/utils/slides.utils.ts
Original file line number Diff line number Diff line change
@@ -1,85 +1,85 @@
import {DeckdeckgoSlideDefinition, DeckdeckgoAttributeDefinition} from '@deckdeckgo/types';

export function findSlidesTitle(): Promise<string[]> {
return new Promise<string[]>((resolve) => {
if (!document) {
resolve();
return;
}

const results: string[] = [];

const slides: NodeListOf<HTMLElement> = document.querySelectorAll('deckgo-deck > *');

if (slides) {
for (const slide of Array.from(slides)) {
if (slide.tagName && slide.tagName.toLowerCase().indexOf('deckgo-slide') > -1) {
const title: HTMLElement | null = slide.querySelector('[slot="title"],[slot="question"]');

if (title && title.textContent && title.textContent !== '') {
results.push(title.textContent);
} else {
const start: HTMLElement | null = slide.querySelector('[slot="start"],[slot="header"]');

if (start && start.textContent && start.textContent !== '') {
results.push(start.textContent);
} else {
const end: HTMLElement | null = slide.querySelector('[slot="end"],[slot="footer"]');

if (end && end.textContent && end.textContent !== '') {
results.push(end.textContent);
} else {
results.push('');
}
}
}
}
return new Promise<string[]>((resolve) => {
if (!document) {
resolve();
return;
}

const results: string[] = [];

const slides: NodeListOf<HTMLElement> = document.querySelectorAll('deckgo-deck > *');

if (slides) {
for (const slide of Array.from(slides)) {
if (slide.tagName && slide.tagName.toLowerCase().indexOf('deckgo-slide') > -1) {
const title: HTMLElement | null = slide.querySelector('[slot="title"],[slot="question"]');

if (title && title.textContent && title.textContent !== '') {
results.push(title.textContent);
} else {
const start: HTMLElement | null = slide.querySelector('[slot="start"],[slot="header"]');

if (start && start.textContent && start.textContent !== '') {
results.push(start.textContent);
} else {
const end: HTMLElement | null = slide.querySelector('[slot="end"],[slot="footer"]');

if (end && end.textContent && end.textContent !== '') {
results.push(end.textContent);
} else {
results.push('');
}
}
}
}
}
}

resolve(results);
});
resolve(results);
});
}

export function getSlideDefinition(slide: HTMLElement): Promise<DeckdeckgoSlideDefinition | null> {
return new Promise<DeckdeckgoSlideDefinition | null>(async (resolve) => {
if (!slide) {
resolve(null);
return;
}

const attributes: DeckdeckgoAttributeDefinition[] | null = await getAttributesDefinition(slide.attributes);

resolve({
template: slide.tagName ? slide.tagName.toLowerCase() : undefined,
content: slide.innerHTML,
attributes: attributes
});
return new Promise<DeckdeckgoSlideDefinition | null>(async (resolve) => {
if (!slide) {
resolve(null);
return;
}

const attributes: DeckdeckgoAttributeDefinition[] | null = await getAttributesDefinition(slide.attributes);

resolve({
template: slide.tagName ? slide.tagName.toLowerCase() : undefined,
content: slide.innerHTML,
attributes: attributes
});
});
}

export function getAttributesDefinition(attributes: NamedNodeMap): Promise<DeckdeckgoAttributeDefinition[] | null> {
return new Promise<DeckdeckgoAttributeDefinition[] | null>(async (resolve) => {
if (!attributes || attributes.length <= 0) {
resolve(null);
return;
return new Promise<DeckdeckgoAttributeDefinition[] | null>(async (resolve) => {
if (!attributes || attributes.length <= 0) {
resolve(null);
return;
}

const results: DeckdeckgoAttributeDefinition[] = [];
Array.prototype.slice.call(attributes).forEach((attribute: Attr) => {
if (['id', 'hydrated', 'class', 'contenteditable'].indexOf(attribute.name.toLowerCase()) === -1) {
let attr: DeckdeckgoAttributeDefinition = {
name: attribute.name
};

if (attribute.value !== undefined) {
attr.value = `${attribute.value}`;
}

const results: DeckdeckgoAttributeDefinition[] = [];
Array.prototype.slice.call(attributes).forEach((attribute: Attr) => {
if (['id', 'hydrated', 'class', 'contenteditable'].indexOf(attribute.name.toLowerCase()) === -1) {
let attr: DeckdeckgoAttributeDefinition = {
name: attribute.name
};

if (attribute.value !== undefined) {
attr.value = `${attribute.value}`;
}

results.push(attr);
}
});

resolve(results && results.length > 0 ? results : null);
results.push(attr);
}
});

resolve(results && results.length > 0 ? results : null);
});
}
2 changes: 1 addition & 1 deletion utils/slide/src/interfaces/deckdeckgo-component.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export interface DeckdeckgoComponent {
lazyLoadContent(): Promise<void>;
lazyLoadContent(): Promise<void>;
}
6 changes: 3 additions & 3 deletions utils/slide/src/interfaces/deckdeckgo-slide-play.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import {DeckdeckgoSlideResize} from './deckdeckgo-slide-resize';

export interface DeckdeckgoSlidePlay extends DeckdeckgoSlideResize {
play(): Promise<void>;
play(): Promise<void>;

pause(): Promise<void>;
pause(): Promise<void>;

toggle(): Promise<void>;
toggle(): Promise<void>;
}
2 changes: 1 addition & 1 deletion utils/slide/src/interfaces/deckdeckgo-slide-resize.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {DeckdeckgoSlide} from './deckdeckgo-slide';

export interface DeckdeckgoSlideResize extends DeckdeckgoSlide {
resizeContent(): Promise<void>;
resizeContent(): Promise<void>;
}
1 change: 0 additions & 1 deletion utils/slide/src/utils/component-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ export function lazyLoadComponentContent(el: HTMLElement, tag: string): Promise<
const elements: HTMLElement[] = getAllElements(el, tag);

if (elements && elements.length > 0) {

elements.forEach((element: HTMLElement) => {
promises.push((element as any).lazyLoadContent());
});
Expand Down
64 changes: 32 additions & 32 deletions utils/slide/src/utils/images-utils.ts
Original file line number Diff line number Diff line change
@@ -1,59 +1,59 @@
import {lazyLoadSelectedImages, lazyLoadSelectedLazyImagesComponent} from '@deckdeckgo/utils';

export function lazyLoadImages(el: HTMLElement): Promise<void> {
return new Promise<void>(async (resolve) => {
const promises = [];
return new Promise<void>(async (resolve) => {
const promises = [];

promises.push(lazyLoadLazyImgTags(el));
promises.push(lazyLoadLazyImgComponents(el));
promises.push(lazyLoadLazyImgTags(el));
promises.push(lazyLoadLazyImgComponents(el));

await Promise.all(promises);
await Promise.all(promises);

resolve();
});
resolve();
});
}

function lazyLoadLazyImgTags(el: HTMLElement): Promise<void> {
return new Promise<void>(async (resolve) => {
const images: HTMLElement[] = getAllImages(el, 'img');
return new Promise<void>(async (resolve) => {
const images: HTMLElement[] = getAllImages(el, 'img');

await lazyLoadSelectedImages(images);
await lazyLoadSelectedImages(images);

resolve();
});
resolve();
});
}

function lazyLoadLazyImgComponents(el: HTMLElement): Promise<void> {
return new Promise<void>(async (resolve) => {
const images: HTMLElement[] = getAllImages(el, 'deckgo-lazy-img');
return new Promise<void>(async (resolve) => {
const images: HTMLElement[] = getAllImages(el, 'deckgo-lazy-img');

await lazyLoadSelectedLazyImagesComponent(images);
await lazyLoadSelectedLazyImagesComponent(images);

resolve();
});
resolve();
});
}

export function hideLazyLoadImages(el: HTMLElement): Promise<void> {
return new Promise<void>((resolve) => {
let images: HTMLElement[] = getAllImages(el, 'img');
return new Promise<void>((resolve) => {
let images: HTMLElement[] = getAllImages(el, 'img');

if (!images) {
resolve();
} else {
images = images.filter((image: HTMLElement) => image.getAttribute('data-src'));
if (!images) {
resolve();
} else {
images = images.filter((image: HTMLElement) => image.getAttribute('data-src'));

images.forEach((image: HTMLElement) => {
image.style.setProperty('visibility', 'hidden');
});
images.forEach((image: HTMLElement) => {
image.style.setProperty('visibility', 'hidden');
});

resolve();
}
});
resolve();
}
});
}

function getAllImages(el: HTMLElement, tag: string): HTMLElement[] {
const allSlotedImages: NodeListOf<HTMLElement> = el.querySelectorAll('[slot] ' + tag);
const allShadowImages: NodeListOf<HTMLElement> | [] = el.shadowRoot ? el.shadowRoot.querySelectorAll(tag) : [];
const allSlotedImages: NodeListOf<HTMLElement> = el.querySelectorAll('[slot] ' + tag);
const allShadowImages: NodeListOf<HTMLElement> | [] = el.shadowRoot ? el.shadowRoot.querySelectorAll(tag) : [];

return Array.from(allSlotedImages).concat(Array.from(allShadowImages));
return Array.from(allSlotedImages).concat(Array.from(allShadowImages));
}
Loading

0 comments on commit 2983e84

Please sign in to comment.