Compare commits
8 Commits
Author | SHA1 | Date | |
---|---|---|---|
0fd7ae74f8 | |||
9d6238618f | |||
0dd10351ad | |||
1d2b489830 | |||
446c9d0f59 | |||
a689252f4b | |||
2f1ce0058c | |||
a49c8e7aa7 |
4
package-lock.json
generated
4
package-lock.json
generated
@ -1,12 +1,12 @@
|
|||||||
{
|
{
|
||||||
"name": "@pushrocks/smartntml",
|
"name": "@pushrocks/smartntml",
|
||||||
"version": "1.0.11",
|
"version": "2.0.2",
|
||||||
"lockfileVersion": 2,
|
"lockfileVersion": 2,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"packages": {
|
"packages": {
|
||||||
"": {
|
"": {
|
||||||
"name": "@pushrocks/smartntml",
|
"name": "@pushrocks/smartntml",
|
||||||
"version": "1.0.11",
|
"version": "2.0.2",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@happy-dom/global-registrator": "^6.0.4",
|
"@happy-dom/global-registrator": "^6.0.4",
|
||||||
|
12
package.json
12
package.json
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@pushrocks/smartntml",
|
"name": "@pushrocks/smartntml",
|
||||||
"version": "1.0.11",
|
"version": "2.0.2",
|
||||||
"private": false,
|
"private": false,
|
||||||
"description": "lit-html for the backend",
|
"description": "lit-html for the backend",
|
||||||
"main": "dist_ts/index.js",
|
"main": "dist_ts/index.js",
|
||||||
@ -15,15 +15,17 @@
|
|||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@gitzone/tsbuild": "^2.1.65",
|
"@gitzone/tsbuild": "^2.1.65",
|
||||||
"@gitzone/tsbundle": "^2.0.7",
|
"@gitzone/tsbundle": "^2.0.7",
|
||||||
|
"@gitzone/tsrun": "^1.2.39",
|
||||||
"@gitzone/tstest": "^1.0.73",
|
"@gitzone/tstest": "^1.0.73",
|
||||||
"@pushrocks/tapbundle": "^5.0.4",
|
"@pushrocks/tapbundle": "^5.0.4",
|
||||||
"@types/node": "^18.7.23"
|
"@types/node": "^18.7.23",
|
||||||
|
"why-is-node-running": "^2.2.2"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@happy-dom/global-registrator": "^6.0.4",
|
"@designestate/dees-element": "^2.0.20",
|
||||||
|
"@happy-dom/global-registrator": "^8.9.0",
|
||||||
"@pushrocks/smartpromise": "^3.1.7",
|
"@pushrocks/smartpromise": "^3.1.7",
|
||||||
"@types/strip-comments": "^2.0.1",
|
"fake-indexeddb": "^4.0.1"
|
||||||
"lit": "^2.3.1"
|
|
||||||
},
|
},
|
||||||
"browserslist": [
|
"browserslist": [
|
||||||
"last 1 chrome versions"
|
"last 1 chrome versions"
|
||||||
|
4568
pnpm-lock.yaml
generated
Normal file
4568
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 { expect, expectAsync, tap } from '@pushrocks/tapbundle';
|
||||||
import * as smartntml from '../ts/index.js';
|
import * as smartntml from '../ts/index.js';
|
||||||
|
|
||||||
let testSmartntmlInstance: smartntml.Smartntml;
|
let testSmartntmlInstance: smartntml.Smartntml;
|
||||||
|
|
||||||
tap.test('first test', async () => {
|
tap.test('first test', async () => {
|
||||||
testSmartntmlInstance = await smartntml.Smartntml.createAndInit();
|
testSmartntmlInstance = new smartntml.Smartntml();
|
||||||
});
|
});
|
||||||
|
|
||||||
tap.test('should render a string', async () => {
|
tap.test('should render a string', async () => {
|
||||||
const arrayArg = [1, 2, 3, 4, 5, 6];
|
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(
|
<div class="hello">${arrayArg.map(
|
||||||
(element) => testSmartntmlInstance.html`<div>${element}</div>`
|
(element) => smartntml.deesElement.html`<div>${element}</div>`
|
||||||
)}</div>
|
)}</div>
|
||||||
`);
|
`);
|
||||||
console.log(stringResult);
|
console.log(stringResult);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
tap.test('should log', async () => {
|
||||||
|
log();
|
||||||
|
setTimeout(()=> process.exit(0), 0);
|
||||||
|
})
|
||||||
|
|
||||||
tap.start();
|
tap.start();
|
||||||
|
@ -3,6 +3,6 @@
|
|||||||
*/
|
*/
|
||||||
export const commitinfo = {
|
export const commitinfo = {
|
||||||
name: '@pushrocks/smartntml',
|
name: '@pushrocks/smartntml',
|
||||||
version: '1.0.11',
|
version: '2.0.2',
|
||||||
description: 'lit-html for the backend'
|
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 * as plugins from './smartntml.plugins.js';
|
||||||
|
|
||||||
import type * as litTypes from 'lit';
|
const deesElement = plugins.deesElement;
|
||||||
import { unsafeHTML } from 'lit/directives/unsafe-html.js';
|
export {
|
||||||
export type { TemplateResult } from 'lit';
|
deesElement
|
||||||
|
}
|
||||||
|
|
||||||
export class Smartntml {
|
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() {
|
constructor() {
|
||||||
this.init();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public async init() {
|
public async renderTemplateResult(templateResult: plugins.deesElement.TemplateResult, stripCommentsArg = true) {
|
||||||
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) {
|
|
||||||
const element = document.createElement('div');
|
const element = document.createElement('div');
|
||||||
this.render(templateResult, element);
|
plugins.deesElement.render(templateResult, element);
|
||||||
let stringResult = element.innerHTML;
|
let stringResult = element.innerHTML;
|
||||||
if (stripCommentsArg) {
|
if (stripCommentsArg) {
|
||||||
stringResult = stringResult.replace(/<!--(.*?)-->/g, '');
|
stringResult = stringResult.replace(/<!--(.*?)-->/g, '');
|
||||||
|
8
ts/instrument/happydom.ts
Normal file
8
ts/instrument/happydom.ts
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
// happy-dom setup
|
||||||
|
|
||||||
|
// first lets setup indexeddb
|
||||||
|
import 'fake-indexeddb/auto';
|
||||||
|
|
||||||
|
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
|
// @pushrocks scope
|
||||||
import * as smartpromise from '@pushrocks/smartpromise';
|
import * as smartpromise from '@pushrocks/smartpromise';
|
||||||
|
|
||||||
@ -10,4 +5,11 @@ export {
|
|||||||
smartpromise
|
smartpromise
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// designestate
|
||||||
|
import * as deesElement from '@designestate/dees-element';
|
||||||
|
|
||||||
|
export {
|
||||||
|
deesElement
|
||||||
|
}
|
||||||
|
|
||||||
// third party scope
|
// third party scope
|
||||||
|
Reference in New Issue
Block a user