@lukekaalim/act-web 3.2.1 → 3.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,23 @@
1
1
  # @lukekaalim/act-web
2
2
 
3
+ ## 3.3.0
4
+
5
+ ### Minor Changes
6
+
7
+ - Scheduling refactor
8
+
9
+ ### Patch Changes
10
+
11
+ - Updated dependencies
12
+ - @lukekaalim/act-backstage@2.0.0
13
+ - @lukekaalim/act-recon@2.0.0
14
+
15
+ ## 3.2.2
16
+
17
+ ### Patch Changes
18
+
19
+ - cece5b4: Fixes CSS vars in the "style" prop not being applied
20
+
3
21
  ## 3.2.1
4
22
 
5
23
  ### Patch Changes
package/package.json CHANGED
@@ -1,11 +1,11 @@
1
1
  {
2
2
  "name": "@lukekaalim/act-web",
3
- "version": "3.2.1",
3
+ "version": "3.3.0",
4
4
  "type": "module",
5
5
  "main": "mod.ts",
6
6
  "dependencies": {
7
7
  "@lukekaalim/act": "^3.1.0",
8
- "@lukekaalim/act-recon": "^1.1.1",
9
- "@lukekaalim/act-backstage": "^1.2.1"
8
+ "@lukekaalim/act-recon": "^2.0.0",
9
+ "@lukekaalim/act-backstage": "^2.0.0"
10
10
  }
11
11
  }
package/props.ts CHANGED
@@ -1,18 +1,27 @@
1
1
  import * as act from '@lukekaalim/act';
2
2
 
3
+ declare global {
4
+ interface Window {
5
+ HTMLElement: typeof HTMLElement,
6
+ SVGElement: typeof SVGElement,
7
+ Text: typeof Text,
8
+ }
9
+ }
10
+
3
11
  export const setProps = (
12
+ window: Window,
4
13
  node: HTMLElement | SVGElement | Text,
5
14
 
6
15
  next: act.Element,
7
16
  prev: null | act.Element
8
17
  ) => {
9
- if (node instanceof HTMLElement) {
18
+ if (node instanceof window.HTMLElement) {
10
19
  setHTMLElementProps(node, next, prev);
11
20
  }
12
- if (node instanceof SVGElement) {
21
+ if (node instanceof window.SVGElement) {
13
22
  setSVGElementProps(node, next, prev);
14
23
  }
15
- if (node instanceof Text) {
24
+ if (node instanceof window.Text) {
16
25
  if (node.textContent !== next.props.value)
17
26
  node.textContent = next.props.value as string
18
27
  }
@@ -93,7 +102,8 @@ export const setStyleProp = (
93
102
  style: null | Record<keyof CSSStyleDeclaration, string | number>,
94
103
  prevStyle: null | Record<keyof CSSStyleDeclaration, string | number>,
95
104
  ) => {
96
- setPropObject(node as any, style, prevStyle)
105
+ setPropObject(node as any, style, prevStyle, (name, value) =>
106
+ (node.setProperty(name, value as string), true))
97
107
  }
98
108
 
99
109
  const setPropObject = (
package/render.ts CHANGED
@@ -1,12 +1,32 @@
1
- import { h } from "@lukekaalim/act";
1
+ import { createId, h } from "@lukekaalim/act";
2
2
  import { createWebSpace, HTML } from "./space";
3
- import { createRenderFunction, RenderFunction, Scheduler } from "@lukekaalim/act-backstage";
3
+ import { createRenderFunction, RenderFunction } from "@lukekaalim/act-backstage";
4
+ import { Scheduler } from "@lukekaalim/act-recon";
4
5
 
5
- const intervalScheduler: Scheduler<NodeJS.Timeout> = {
6
- duration: 10,
7
- request: func => setInterval(func, 10),
8
- cancel: id => clearInterval(id),
6
+ export const createDOMScheduler = (): Scheduler => {
7
+ const workMap = new Map();
8
+ let id: number | null = null;
9
+ const work = () => {
10
+ id = null;
11
+ for (const [,callback] of workMap)
12
+ callback();
13
+
14
+ workMap.clear();
15
+ };
16
+ return {
17
+ requestWork(callback) {
18
+ const workId = createId<'WorkID'>();
19
+ workMap.set(workId, callback);
20
+ if (!id)
21
+ id = setTimeout(work, 1) as any;
22
+ return workId;
23
+ },
24
+ cancelWork(workId) {
25
+ workMap.delete(workId);
26
+ },
27
+ }
9
28
  }
10
29
 
30
+
11
31
  export const render: RenderFunction<HTMLElement> = (node, root) =>
12
- createRenderFunction(intervalScheduler, createWebSpace)(h(HTML, {}, node), root);
32
+ createRenderFunction(createDOMScheduler(), createWebSpace)(h(HTML, {}, node), root);
package/space.ts CHANGED
@@ -8,7 +8,13 @@ import { setProps } from './props.ts';
8
8
  export const HTML: act.Component = ({ children }) => act.h(act.renderNodeType, { type: 'web:html' }, children);
9
9
  export const SVG: act.Component = ({ children }) => act.h(act.renderNodeType, { type: 'web:svg' }, children);
10
10
 
11
- export const createWebSpace = (tree: recon.CommitTree, root: HTMLElement, document: Document = window.document) => {
11
+ const defaultWindow = window;
12
+
13
+ export const createWebSpace = (
14
+ tree: recon.CommitTree,
15
+ root: HTMLElement,
16
+ window: Window = defaultWindow
17
+ ) => {
12
18
  return createSimpleRenderSpace(tree, {
13
19
  rootTypes: new Set(['web:html', 'web:svg']),
14
20
  create(element, rootType) {
@@ -19,7 +25,7 @@ export const createWebSpace = (tree: recon.CommitTree, root: HTMLElement, docume
19
25
  switch (tag) {
20
26
  case act.primitiveNodeTypes.string:
21
27
  case act.primitiveNodeTypes.number:
22
- return document.createTextNode("");
28
+ return window.document.createTextNode("<empty text>");
23
29
  default:
24
30
  return null;
25
31
  }
@@ -27,9 +33,9 @@ export const createWebSpace = (tree: recon.CommitTree, root: HTMLElement, docume
27
33
  case 'string': {
28
34
  switch (rootType) {
29
35
  case 'web:html':
30
- return document.createElementNS('http://www.w3.org/1999/xhtml', tag);
36
+ return window.document.createElementNS('http://www.w3.org/1999/xhtml', tag);
31
37
  case 'web:svg':
32
- return document.createElementNS('http://www.w3.org/2000/svg', tag);
38
+ return window.document.createElementNS('http://www.w3.org/2000/svg', tag);
33
39
  }
34
40
  }
35
41
  default:
@@ -37,7 +43,7 @@ export const createWebSpace = (tree: recon.CommitTree, root: HTMLElement, docume
37
43
  }
38
44
  },
39
45
  update(el, next, prev) {
40
- setProps(el, next, prev);
46
+ setProps(window, el, next, prev);
41
47
  },
42
48
  link(el, parent) {
43
49
  (parent || root).appendChild(el);
package/tags.ts CHANGED
@@ -6,7 +6,7 @@ export const htmlTagNames = new Set([
6
6
  "h1", "h2", "h3", "h4", "h5", "h6",
7
7
  "hl",
8
8
  'p',
9
- "ol", "ul", "li",
9
+ "ol", "ul", "li", "menu",
10
10
  "table", 'td', 'tr', 'th',
11
11
  "pre",
12
12