@starbeamx/vanilla
Advanced tools
Comparing version 0.7.4 to 0.8.0
# @starbeamx/store | ||
## 0.8.0 | ||
### Minor Changes | ||
- 1a553c5: Prepare for 0.8 | ||
### Patch Changes | ||
- Updated dependencies [1a553c5] | ||
- @starbeam/debug@0.8.0 | ||
- @starbeam/timeline@0.8.0 | ||
- @starbeam/universal@0.8.0 | ||
## 0.7.4 | ||
@@ -4,0 +17,0 @@ |
@@ -12,3 +12,3 @@ import { Description } from "@starbeam/debug"; | ||
interface Rendered { | ||
poll(): void; | ||
poll: () => void; | ||
} | ||
@@ -15,0 +15,0 @@ interface OutputConstructor { |
@@ -1,3 +0,3 @@ | ||
import { FormulaFn, LIFETIME } from '@starbeam/core'; | ||
import { descriptionFrom } from '@starbeam/debug'; | ||
import { Formula, LIFETIME } from '@starbeam/universal'; | ||
@@ -8,22 +8,16 @@ class Cursor { | ||
} | ||
static insertBefore(parent, node) { | ||
return new Cursor(parent, node); | ||
} | ||
#parentNode; | ||
#nextSibling; | ||
#document; | ||
constructor(parentNode, nextSibling) { | ||
this.#parentNode = parentNode; | ||
this.#nextSibling = nextSibling; | ||
if (parentNode.ownerDocument === null) { | ||
throw new Error("Cursor must be created with a parent node that is part of a document"); | ||
} | ||
this.#document = parentNode.ownerDocument; | ||
} | ||
insert(node) { | ||
@@ -33,7 +27,5 @@ this.#parentNode.insertBefore(node, this.#nextSibling); | ||
} | ||
get document() { | ||
return this.#document; | ||
} | ||
} | ||
@@ -55,3 +47,3 @@ | ||
}); | ||
const formula = FormulaFn(update, description); | ||
const formula = Formula(update, description); | ||
LIFETIME.on.cleanup(owner, cleanup); | ||
@@ -62,10 +54,7 @@ return { | ||
} | ||
}; | ||
} | ||
}; | ||
}; | ||
} | ||
function Text(text, description) { | ||
@@ -78,3 +67,5 @@ return Render(_ref2 => { | ||
return { | ||
cleanup: () => node.remove(), | ||
cleanup: () => { | ||
node.remove(); | ||
}, | ||
update: () => { | ||
@@ -93,3 +84,2 @@ node.textContent = text.read(); | ||
} | ||
class FragmentRange { | ||
@@ -99,6 +89,4 @@ static create(start, end) { | ||
} | ||
#start; | ||
#end; | ||
constructor(start, end) { | ||
@@ -108,7 +96,5 @@ this.#start = start; | ||
} | ||
clear() { | ||
let current = this.#start; | ||
const end = this.#end; | ||
while (current !== null && current !== end) { | ||
@@ -119,31 +105,21 @@ const next = current.nextSibling; | ||
} | ||
end.remove(); | ||
} | ||
get nodes() { | ||
const nodes = []; | ||
if (this.#start.nextSibling === this.#end) { | ||
return nodes; | ||
} | ||
let start = this.#start.nextSibling; | ||
const end = this.#end.previousSibling; | ||
while (start) { | ||
nodes.push(start); | ||
if (start === end) { | ||
break; | ||
} | ||
start = start.nextSibling; | ||
} | ||
return nodes; | ||
} | ||
} | ||
function Fragment(nodes, description) { | ||
@@ -166,3 +142,2 @@ const desc = descriptionFrom({ | ||
const renderedNodes = []; | ||
for (const nodeConstructor of nodes) { | ||
@@ -174,3 +149,2 @@ const node = nodeConstructor(into).create({ | ||
} | ||
const end = placeholder(into.document); | ||
@@ -180,8 +154,10 @@ into.insert(end); | ||
return { | ||
cleanup: () => range.clear(), | ||
cleanup: () => { | ||
range.clear(); | ||
}, | ||
update() { | ||
renderedNodes.forEach(node => node.poll()); | ||
renderedNodes.forEach(node => { | ||
node.poll(); | ||
}); | ||
} | ||
}; | ||
@@ -196,3 +172,2 @@ }, desc); | ||
const current = value.read(); | ||
if (typeof current === "string") { | ||
@@ -203,8 +178,8 @@ into.setAttribute(name, current); | ||
} | ||
return { | ||
cleanup: () => into.removeAttribute(name), | ||
cleanup: () => { | ||
into.removeAttribute(name); | ||
}, | ||
update: () => { | ||
const next = value.read(); | ||
if (typeof next === "string") { | ||
@@ -242,3 +217,2 @@ into.setAttribute(name, next); | ||
const renderAttributes = []; | ||
for (const attrConstructor of attributes) { | ||
@@ -250,3 +224,2 @@ const attr = attrConstructor(element).create({ | ||
} | ||
const fragment = Array.isArray(body) ? Fragment(body) : body; | ||
@@ -258,3 +231,5 @@ const renderBody = fragment(elementCursor).create({ | ||
return { | ||
cleanup: () => element.remove(), | ||
cleanup: () => { | ||
element.remove(); | ||
}, | ||
update: () => { | ||
@@ -264,3 +239,2 @@ for (const attr of renderAttributes) { | ||
} | ||
renderBody.poll(); | ||
@@ -279,3 +253,2 @@ } | ||
Element.Attr = Attr; | ||
function placeholder(document) { | ||
@@ -282,0 +255,0 @@ return document.createTextNode(""); |
{ | ||
"name": "@starbeamx/vanilla", | ||
"version": "0.8.0", | ||
"description": "A renderer for Starbeam using Vanilla JavaScript", | ||
"version": "0.7.4", | ||
"type": "module", | ||
"main": "dist/index.cjs", | ||
"starbeam:type": "library", | ||
"dependencies": { | ||
"@starbeam/core": "^0.7.4", | ||
"@starbeam/debug": "^0.7.4", | ||
"@starbeam/timeline": "^0.7.4" | ||
}, | ||
"types": "dist/index.d.ts", | ||
"exports": { | ||
@@ -20,3 +15,16 @@ ".": { | ||
}, | ||
"types": "dist/index.d.ts" | ||
"starbeam:type": "library:public", | ||
"dependencies": { | ||
"@starbeam/debug": "^0.8.0", | ||
"@starbeam/timeline": "^0.8.0", | ||
"@starbeam/universal": "^0.8.0" | ||
}, | ||
"devDependencies": { | ||
"@starbeam-dev/build-support": "1.0.0" | ||
}, | ||
"scripts": { | ||
"test:lint": "eslint", | ||
"test:specs": "vitest --run", | ||
"test:types": "tsc -b" | ||
} | ||
} |
@@ -1,5 +0,5 @@ | ||
import { FormulaFn, LIFETIME } from "@starbeam/core"; | ||
import type { Description } from "@starbeam/debug"; | ||
import { descriptionFrom } from "@starbeam/debug"; | ||
import type { Reactive } from "@starbeam/timeline"; | ||
import { Formula, LIFETIME } from "@starbeam/universal"; | ||
@@ -9,3 +9,3 @@ import { Cursor } from "./cursor.js"; | ||
interface Rendered { | ||
poll(): void; | ||
poll: () => void; | ||
} | ||
@@ -32,3 +32,3 @@ | ||
const formula = FormulaFn(update, description); | ||
const formula = Formula(update, description); | ||
@@ -56,3 +56,5 @@ LIFETIME.on.cleanup(owner, cleanup); | ||
return { | ||
cleanup: () => node.remove(), | ||
cleanup: () => { | ||
node.remove(); | ||
}, | ||
@@ -76,3 +78,3 @@ update: () => { | ||
class FragmentRange { | ||
static create(start: ChildNode, end: ChildNode) { | ||
static create(start: ChildNode, end: ChildNode): FragmentRange { | ||
return new FragmentRange(start, end); | ||
@@ -89,3 +91,3 @@ } | ||
clear() { | ||
clear(): void { | ||
let current: ChildNode | null = this.#start; | ||
@@ -110,4 +112,4 @@ const end = this.#end; | ||
let start = this.#start.nextSibling as ChildNode; | ||
const end = this.#end.previousSibling as ChildNode; | ||
let start = this.#start.nextSibling; | ||
const end = this.#end.previousSibling; | ||
@@ -121,3 +123,3 @@ while (start) { | ||
start = start.nextSibling as ChildNode; | ||
start = start.nextSibling; | ||
} | ||
@@ -158,6 +160,10 @@ | ||
return { | ||
cleanup: () => range.clear(), | ||
cleanup: () => { | ||
range.clear(); | ||
}, | ||
update() { | ||
renderedNodes.forEach((node) => node.poll()); | ||
renderedNodes.forEach((node) => { | ||
node.poll(); | ||
}); | ||
}, | ||
@@ -184,3 +190,5 @@ }; | ||
return { | ||
cleanup: () => into.removeAttribute(name), | ||
cleanup: () => { | ||
into.removeAttribute(name); | ||
}, | ||
update: () => { | ||
@@ -240,3 +248,5 @@ const next = value.read(); | ||
return { | ||
cleanup: () => element.remove(), | ||
cleanup: () => { | ||
element.remove(); | ||
}, | ||
@@ -265,4 +275,4 @@ update: () => { | ||
function placeholder(document: Document) { | ||
function placeholder(document: Document): Text { | ||
return document.createTextNode(""); | ||
} |
{ | ||
"private": true, | ||
"type": "module", | ||
"name": "@starbeam-tests/x-vanilla", | ||
"version": "1.0.0", | ||
"type": "module", | ||
"starbeam:type": "tests", | ||
"scripts": { | ||
"test:lint": "eslint", | ||
"test:types": "tsc -b" | ||
}, | ||
"dependencies": { | ||
"@starbeamx/vanilla": "workspace:^", | ||
"@starbeam/core": "workspace:^" | ||
}, | ||
"publishConfig": { | ||
"main": "dist/index.cjs", | ||
"types": "dist/index.d.ts", | ||
"exports": { | ||
".": { | ||
"types": "./dist/index.d.ts", | ||
"import": "./dist/index.js", | ||
"default": "./dist/index.cjs" | ||
} | ||
} | ||
"@starbeam/universal": "workspace:^", | ||
"@starbeamx/vanilla": "workspace:^" | ||
} | ||
} |
{ | ||
"extends": "../../../.config/tsconfig/tsconfig.-package.json", | ||
"extends": "../../../../.config/tsconfig/tsconfig.shared.json", | ||
"compilerOptions": { | ||
"outDir": "../../../dist/packages", | ||
"composite": true, | ||
"declaration": true, | ||
"declarationDir": "../../../../dist/types", | ||
"declarationMap": true, | ||
"declarationDir": "../../../dist/types", | ||
"declaration": true, | ||
"composite": true, | ||
"types": ["../../env"] | ||
} | ||
"outDir": "../../../../dist/packages", | ||
"types": ["../../../env"] | ||
}, | ||
"exclude": ["dist/**/*"] | ||
} |
// @vitest-environment happy-dom | ||
import { Cell, LIFETIME } from "@starbeam/core"; | ||
import { Cell, LIFETIME } from "@starbeam/universal"; | ||
import { Cursor, El, Fragment, Text } from "@starbeamx/vanilla"; | ||
import { describe, expect, test } from "vitest"; | ||
import { env } from "./env"; | ||
describe("Vanilla Renderer", () => { | ||
@@ -83,12 +85,3 @@ test("it can render text", () => { | ||
function env() { | ||
return { | ||
global: globalThis, | ||
document: globalThis.document, | ||
body: new Body(globalThis.document.body), | ||
owner: {}, | ||
}; | ||
} | ||
class Body { | ||
export class Body { | ||
#body: HTMLElement; | ||
@@ -102,7 +95,7 @@ #snapshot: ChildNode[]; | ||
get cursor() { | ||
get cursor(): Cursor { | ||
return Cursor.appendTo(this.#body); | ||
} | ||
get innerHTML() { | ||
get innerHTML(): string { | ||
return this.#body.innerHTML; | ||
@@ -115,3 +108,3 @@ } | ||
expectStable() { | ||
expectStable(): void { | ||
const snapshot = this.#snapshot; | ||
@@ -118,0 +111,0 @@ |
{ | ||
"extends": "../../.config/tsconfig/tsconfig.-package.json", | ||
"extends": "../../../.config/tsconfig/tsconfig.shared.json", | ||
"compilerOptions": { | ||
"outDir": "../../dist/packages", | ||
"composite": true, | ||
"declaration": true, | ||
"composite": true, | ||
"declarationDir": "../../../dist/types", | ||
"declarationMap": true, | ||
"declarationDir": "../../dist/types", | ||
"types": ["../env"] | ||
} | ||
"outDir": "../../../dist/packages", | ||
"types": ["../../env"] | ||
}, | ||
"exclude": ["dist/**/*"] | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
68354
23
972
1
+ Added@starbeam/universal@^0.8.0
+ Added@starbeam/core-utils@0.8.9(transitive)
+ Added@starbeam/debug@0.8.9(transitive)
+ Added@starbeam/interfaces@0.8.9(transitive)
+ Added@starbeam/timeline@0.8.9(transitive)
+ Added@starbeam/universal@0.8.9(transitive)
+ Added@starbeam/verify@0.8.9(transitive)
+ Addedansicolor@1.1.100(transitive)
+ Addedbase64-js@1.5.1(transitive)
+ Addedbuffer@6.0.3(transitive)
+ Addedieee754@1.2.1(transitive)
- Removed@starbeam/core@^0.7.4
- Removed@starbeam/core@0.7.4(transitive)
- Removed@starbeam/core-utils@0.7.3(transitive)
- Removed@starbeam/debug@0.7.4(transitive)
- Removed@starbeam/interfaces@0.7.3(transitive)
- Removed@starbeam/timeline@0.7.4(transitive)
- Removed@starbeam/verify@0.7.3(transitive)
Updated@starbeam/debug@^0.8.0
Updated@starbeam/timeline@^0.8.0