Compare commits
4 Commits
Author | SHA1 | Date | |
---|---|---|---|
446c9d0f59 | |||
a689252f4b | |||
2f1ce0058c | |||
a49c8e7aa7 |
4
package-lock.json
generated
4
package-lock.json
generated
@ -1,12 +1,12 @@
|
||||
{
|
||||
"name": "@pushrocks/smartntml",
|
||||
"version": "1.0.11",
|
||||
"version": "2.0.0",
|
||||
"lockfileVersion": 2,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "@pushrocks/smartntml",
|
||||
"version": "1.0.11",
|
||||
"version": "2.0.0",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@happy-dom/global-registrator": "^6.0.4",
|
||||
|
12
package.json
12
package.json
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@pushrocks/smartntml",
|
||||
"version": "1.0.11",
|
||||
"version": "2.0.0",
|
||||
"private": false,
|
||||
"description": "lit-html for the backend",
|
||||
"main": "dist_ts/index.js",
|
||||
@ -17,13 +17,13 @@
|
||||
"@gitzone/tsbundle": "^2.0.7",
|
||||
"@gitzone/tstest": "^1.0.73",
|
||||
"@pushrocks/tapbundle": "^5.0.4",
|
||||
"@types/node": "^18.7.23"
|
||||
"@types/node": "^18.7.23",
|
||||
"why-is-node-running": "^2.2.2"
|
||||
},
|
||||
"dependencies": {
|
||||
"@happy-dom/global-registrator": "^6.0.4",
|
||||
"@pushrocks/smartpromise": "^3.1.7",
|
||||
"@types/strip-comments": "^2.0.1",
|
||||
"lit": "^2.3.1"
|
||||
"@designestate/dees-element": "^2.0.20",
|
||||
"@happy-dom/global-registrator": "^8.9.0",
|
||||
"@pushrocks/smartpromise": "^3.1.7"
|
||||
},
|
||||
"browserslist": [
|
||||
"last 1 chrome versions"
|
||||
|
4562
pnpm-lock.yaml
generated
Normal file
4562
pnpm-lock.yaml
generated
Normal file
File diff suppressed because it is too large
Load Diff
12
test/test.ts
12
test/test.ts
@ -1,20 +1,26 @@
|
||||
import log from 'why-is-node-running';
|
||||
import { expect, expectAsync, tap } from '@pushrocks/tapbundle';
|
||||
import * as smartntml from '../ts/index.js';
|
||||
|
||||
let testSmartntmlInstance: smartntml.Smartntml;
|
||||
|
||||
tap.test('first test', async () => {
|
||||
testSmartntmlInstance = await smartntml.Smartntml.createAndInit();
|
||||
testSmartntmlInstance = new smartntml.Smartntml();
|
||||
});
|
||||
|
||||
tap.test('should render a string', async () => {
|
||||
const arrayArg = [1, 2, 3, 4, 5, 6];
|
||||
const stringResult = await testSmartntmlInstance.renderTemplateResult(testSmartntmlInstance.html`
|
||||
const stringResult = await testSmartntmlInstance.renderTemplateResult(smartntml.deesElement.html`
|
||||
<div class="hello">${arrayArg.map(
|
||||
(element) => testSmartntmlInstance.html`<div>${element}</div>`
|
||||
(element) => smartntml.deesElement.html`<div>${element}</div>`
|
||||
)}</div>
|
||||
`);
|
||||
console.log(stringResult);
|
||||
});
|
||||
|
||||
tap.test('should log', async () => {
|
||||
log();
|
||||
setTimeout(()=> process.exit(0), 0);
|
||||
})
|
||||
|
||||
tap.start();
|
||||
|
@ -3,6 +3,6 @@
|
||||
*/
|
||||
export const commitinfo = {
|
||||
name: '@pushrocks/smartntml',
|
||||
version: '1.0.11',
|
||||
version: '2.0.0',
|
||||
description: 'lit-html for the backend'
|
||||
}
|
||||
|
43
ts/index.ts
43
ts/index.ts
@ -1,48 +1,19 @@
|
||||
import './instrument/happydom.js';
|
||||
import * as plugins from './smartntml.plugins.js';
|
||||
|
||||
import type * as litTypes from 'lit';
|
||||
import { unsafeHTML } from 'lit/directives/unsafe-html.js';
|
||||
export type { TemplateResult } from 'lit';
|
||||
const deesElement = plugins.deesElement;
|
||||
export {
|
||||
deesElement
|
||||
}
|
||||
|
||||
export class Smartntml {
|
||||
// STATIC
|
||||
public static async createAndInit() {
|
||||
const smartntml = new Smartntml();
|
||||
await smartntml.init();
|
||||
return smartntml;
|
||||
}
|
||||
|
||||
private static smartntmlSingletonDeferred: plugins.smartpromise.Deferred<Smartntml>;
|
||||
public static async createAndInitSingleton() {
|
||||
if (this.smartntmlSingletonDeferred) {
|
||||
return this.smartntmlSingletonDeferred.promise;
|
||||
}
|
||||
this.smartntmlSingletonDeferred = plugins.smartpromise.defer();
|
||||
const smartntmlInstance = await this.createAndInit();
|
||||
this.smartntmlSingletonDeferred.resolve(smartntmlInstance);
|
||||
return this.smartntmlSingletonDeferred.promise;
|
||||
}
|
||||
|
||||
// INSTANCE
|
||||
private render: typeof litTypes.render;
|
||||
public html: typeof litTypes.html;
|
||||
public unsafeHTML: typeof unsafeHTML;
|
||||
|
||||
constructor() {
|
||||
this.init();
|
||||
}
|
||||
|
||||
public async init() {
|
||||
const lit = await import('lit');
|
||||
const litUnsafeHtmlDirective = await import('lit/directives/unsafe-html.js');
|
||||
this.render = lit.render;
|
||||
this.html = lit.html;
|
||||
this.unsafeHTML = litUnsafeHtmlDirective.unsafeHTML;
|
||||
}
|
||||
|
||||
public async renderTemplateResult(templateResult: litTypes.TemplateResult, stripCommentsArg = true) {
|
||||
public async renderTemplateResult(templateResult: plugins.deesElement.TemplateResult, stripCommentsArg = true) {
|
||||
const element = document.createElement('div');
|
||||
this.render(templateResult, element);
|
||||
plugins.deesElement.render(templateResult, element);
|
||||
let stringResult = element.innerHTML;
|
||||
if (stripCommentsArg) {
|
||||
stringResult = stringResult.replace(/<!--(.*?)-->/g, '');
|
||||
|
4
ts/instrument/happydom.ts
Normal file
4
ts/instrument/happydom.ts
Normal file
@ -0,0 +1,4 @@
|
||||
// happy-dom setup
|
||||
import { GlobalRegistrator } from '@happy-dom/global-registrator';
|
||||
GlobalRegistrator.register();
|
||||
window.location.href = 'http://localhost';
|
@ -1,8 +1,3 @@
|
||||
// happy-dom setup
|
||||
import { GlobalRegistrator } from '@happy-dom/global-registrator';
|
||||
GlobalRegistrator.register();
|
||||
window.location.href = 'http://localhost';
|
||||
|
||||
// @pushrocks scope
|
||||
import * as smartpromise from '@pushrocks/smartpromise';
|
||||
|
||||
@ -10,4 +5,11 @@ export {
|
||||
smartpromise
|
||||
}
|
||||
|
||||
// designestate
|
||||
import * as deesElement from '@designestate/dees-element';
|
||||
|
||||
export {
|
||||
deesElement
|
||||
}
|
||||
|
||||
// third party scope
|
||||
|
Reference in New Issue
Block a user