solarite 0.5.2 → 0.7.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.
Files changed (49) hide show
  1. package/LICENSE +21 -0
  2. package/dist/Solarite-debug.js +2823 -1856
  3. package/dist/Solarite.js +2779 -1824
  4. package/dist/Solarite.min.js +2 -4
  5. package/package.json +16 -3
  6. package/readme.md +58 -11
  7. package/src/Globals.js +54 -72
  8. package/src/HtmlParser.js +90 -90
  9. package/src/MultiValueMap.js +57 -105
  10. package/src/NodeGroup.js +624 -470
  11. package/src/Path.js +224 -211
  12. package/src/PathToAttribValue.js +401 -261
  13. package/src/PathToAttribs.js +113 -80
  14. package/src/PathToComment.js +7 -7
  15. package/src/PathToComponent.js +183 -188
  16. package/src/PathToEvent.js +76 -64
  17. package/src/PathToKey.js +19 -0
  18. package/src/PathToNodes.js +1053 -566
  19. package/src/RootNodeGroup.js +120 -8
  20. package/src/Shell.js +570 -348
  21. package/src/Solarite.d.ts +134 -113
  22. package/src/Solarite.js +243 -286
  23. package/src/Template.js +195 -274
  24. package/src/Util.js +353 -351
  25. package/src/assert.js +10 -10
  26. package/src/assignAttributes.js +63 -0
  27. package/src/delve.js +55 -43
  28. package/src/h.js +220 -138
  29. package/src/jsx-dev-runtime.d.ts +1 -0
  30. package/src/jsx-dev-runtime.js +5 -0
  31. package/src/jsx-runtime.d.ts +21 -0
  32. package/src/jsx-runtime.js +84 -0
  33. package/src/jsx.js +194 -0
  34. package/src/toEl.js +77 -82
  35. package/dist/udomdiff-license.txt +0 -18
  36. package/src/getArg.js +0 -137
  37. package/src/hash.js +0 -89
  38. package/src/udomdiff.js +0 -176
  39. package/src/unused/FastLookupArray.js +0 -54
  40. package/src/unused/Hashes.js +0 -339
  41. package/src/unused/InUse.test.js +0 -92
  42. package/src/unused/InUseMap.js +0 -98
  43. package/src/unused/LinkedList.js +0 -117
  44. package/src/unused/LinkedList.test.js +0 -115
  45. package/src/unused/Misc.js +0 -13
  46. package/src/unused/Perf.js +0 -47
  47. package/src/unused/TrackedArray.js +0 -54
  48. package/src/unused/WeakArray.js +0 -33
  49. package/src/watch.js +0 -543
package/src/Solarite.d.ts CHANGED
@@ -1,113 +1,134 @@
1
- /**
2
- * Solarite JavaScript UI library.
3
- * MIT License
4
- * https://vorticode.github.io/solarite/
5
- */
6
-
7
- export interface RenderOptions {
8
- styles?: boolean;
9
- scripts?: boolean;
10
- ids?: boolean;
11
- render?: boolean;
12
- }
13
-
14
- /**
15
- * Tagged template literal or function for creating Templates and rendering to the DOM. */
16
- declare function h(htmlStrings: TemplateStringsArray, ...exprs: any[]): Template;
17
- declare function h(htmlStrings: string | string[], ...exprs: any[]): Template;
18
- declare function h(el: HTMLElement | DocumentFragment, options?: RenderOptions): (htmlStrings: TemplateStringsArray, ...exprs: any[]) => HTMLElement | DocumentFragment;
19
- declare function h(el: HTMLElement | DocumentFragment, template: Template, options?: RenderOptions): void;
20
- declare function h(tag: string, props: object, ...children: any[]): Template; // JSX
21
- declare function h(obj: {render: Function}): (htmlStrings: TemplateStringsArray, ...exprs: any[]) => void; // Rebound render
22
- declare function h(): (htmlStrings: TemplateStringsArray, ...exprs: any[]) => Node|DocumentFragment;
23
-
24
- export default h;
25
- export {h};
26
- export {h as r}; // deprecated
27
-
28
- /**
29
- * Solarite provides more features if your web component extends Solarite instead of HTMLElement. */
30
- export class Solarite extends HTMLElement {
31
- constructor(attribs?: Record<string, any> | null);
32
- render(attribs?: Record<string, any>, changed?:boolean): void;
33
- renderFirstTime(): void;
34
- connectedCallback(): void;
35
- static define(tagName?: string | null): void;
36
- static getAttribs(el: HTMLElement): Record<string, any>;
37
- }
38
-
39
-
40
- /**
41
- * Convert a template, string, or object into a DOM Node or Element. */
42
- export function toEl(arg: string | Template | {render: () => void}): Node | HTMLElement | DocumentFragment;
43
-
44
- /**
45
- * Assign fields from `src` to `dest` if they exist in `dest` and don't exist in `ignore`.
46
- * When a value in `src` is a string and the existing value in `dest` is a boolean, number, or Date,
47
- * it will be converted to that type. */
48
- export function assignFields(dest: object, src: object|null, ignore?: string[]): void;
49
-
50
- /**
51
- * @deprecated
52
- * Retrieve and cast an attribute value from an HTMLElement. */
53
- export function getArg(el: HTMLElement, attributeName: string, defaultValue?: any,
54
- type?: typeof ArgType[keyof typeof ArgType] | Function | any[]): any;
55
-
56
- /**
57
- * @deprecated
58
- * Update attributes on an element from an object. */
59
- export function setArgs(el: HTMLElement, args: object): void;
60
-
61
- /** @deprecated */
62
- export const ArgType: {
63
- Bool: string;
64
- Int: string;
65
- Float: string;
66
- String: string;
67
- Json: string;
68
- Eval: string;
69
- }
70
-
71
- export class Template {
72
- exprs: any[];
73
- html: string[];
74
- constructor(htmlStrings: string[], exprs: any[]);
75
- render(el?: HTMLElement | null, options?: RenderOptions): HTMLElement | DocumentFragment;
76
- getExactKey(): string;
77
- getCloseKey(): string;
78
- static fromJsx(tag: string, props: Record<string, any> | null, children: any[]): Template;
79
- }
80
-
81
- export function delve(obj: object, path: string[], createVal?: any): any;
82
-
83
- /**
84
- * Internal utilities and state. */
85
- export const Globals: {
86
- connected: WeakSet<HTMLElement>;
87
- currentPath: any;
88
- currentSlotChildren: any[] | null;
89
- div: HTMLDivElement;
90
- doc: Document;
91
- elementClasses: {[key: string]: typeof Node};
92
- htmlProps: {[key: string]: boolean};
93
- nodeEvents: WeakMap<Node, {[eventName: string]: [Function, Function, any[]]}>;
94
- rootNodeGroups: WeakMap<HTMLElement, any>;
95
- objToEl: WeakMap<any, any>;
96
- rendered: WeakSet<HTMLElement>;
97
- shells: WeakMap<string[], any>;
98
- reset: Function;
99
- };
100
-
101
- export const SolariteUtil: {
102
- arraySame(a: any[], b: any[]): boolean;
103
- attribsToObject(el: HTMLElement, ignore?: string | null): Record<string, any>;
104
- bindId(root: any, el: HTMLElement): void;
105
- bindStyles(style: HTMLStyleElement, root: HTMLElement): void;
106
- camelToDashes(str: string): string;
107
- dashesToCamel(str: string): string;
108
- defineClass(Class: typeof HTMLElement, tagName?: string | null): void;
109
- isIterable(obj: any): boolean;
110
- trimEmptyNodes(nodes: NodeList | Node[]): Node[];
111
- [key: string]: any;
112
- };
113
-
1
+ /**
2
+ * Solarite JavaScript UI library.
3
+ * MIT License
4
+ * https://vorticode.github.io/solarite/
5
+ */
6
+
7
+ export interface RenderOptions {
8
+ styles?: boolean;
9
+ scripts?: boolean;
10
+ ids?: boolean;
11
+ render?: boolean;
12
+
13
+ /** Defaults to true: bubbling events (click, input, etc.) dispatch from one document-level
14
+ * listener instead of addEventListener per element - much faster creation and teardown
15
+ * of large lists. Pass false to bind every event directly, or an array to delegate only
16
+ * the listed event names. Non-bubbling events always bind directly. Note: delegated
17
+ * handlers run when the event reaches the document, so manual stopPropagation() on an
18
+ * ancestor suppresses them, and manually added ancestor listeners fire first. A
19
+ * programmatically dispatched non-bubbling event won't reach delegated handlers. */
20
+ eventDelegation?: boolean | string[];
21
+ }
22
+
23
+ /**
24
+ * Tagged template literal or function for creating Templates and rendering to the DOM.
25
+ *
26
+ * The key attribute is reserved for keyed lists: `h`<tr key=${row.id}>...``
27
+ * It must be a single whole-value expression on a top-level element; DOM node identity
28
+ * then follows the key across re-renders (state preservation, minimal moves).
29
+ * Static or mixed key values throw, and components never receive key as an arg. */
30
+ declare function h(htmlStrings: TemplateStringsArray, ...exprs: any[]): Template;
31
+ declare function h(htmlStrings: string | string[], ...exprs: any[]): Template;
32
+ declare function h(el: HTMLElement | DocumentFragment, options?: RenderOptions): (htmlStrings: TemplateStringsArray, ...exprs: any[]) => HTMLElement | DocumentFragment;
33
+ declare function h(el: HTMLElement | DocumentFragment, template: Template, options?: RenderOptions): void;
34
+ declare function h(tag: string | Function | symbol, props: object | null, ...children: any[]): Template; // JSX classic factory
35
+ declare function h(obj: {render: Function}): (htmlStrings: TemplateStringsArray, ...exprs: any[]) => void; // Rebound render
36
+ declare function h(): (htmlStrings: TemplateStringsArray, ...exprs: any[]) => Node|DocumentFragment;
37
+
38
+ declare namespace h {
39
+ /** Render a list, reusing each item's DOM while the item is the SAME object; replace an item
40
+ * (don't mutate it) to re-render it. fn runs only for new items. No deps: identity is the dep. */
41
+ function map<T>(items:T[], fn:(item:T) => Template): Template[];
42
+
43
+ /** Alias of h.map with a name that flags the immutability contract at the call site. */
44
+ function immutableMap<T>(items:T[], fn:(item:T) => Template): Template[];
45
+ }
46
+
47
+ /** Tagged template literal for SVG markup and SVG child fragments. */
48
+ declare function svg(htmlStrings: TemplateStringsArray, ...exprs: any[]): Template;
49
+ declare function svg(htmlStrings: string | string[], ...exprs: any[]): Template;
50
+
51
+ export default h;
52
+ export {h, svg};
53
+
54
+ /**
55
+ * Solarite provides more features if your web component extends Solarite instead of HTMLElement. */
56
+ export class Solarite extends HTMLElement {
57
+ constructor(attribs?: Record<string, any> | null);
58
+ render(attribs?: Record<string, any>, changed?:boolean): void;
59
+ renderFirstTime(): void;
60
+ connectedCallback(): void;
61
+ static define(tagName?: string | null): void;
62
+ static getAttribs(el: HTMLElement): Record<string, any>;
63
+ }
64
+
65
+
66
+ /**
67
+ * Convert a template, string, or object into a DOM Node or Element. */
68
+ export function toEl(arg: string | Template | {render: () => void}): Node | HTMLElement | DocumentFragment;
69
+
70
+ /** An event binding registered by a two-way or event attribute, dispatchable via handleEvent(). */
71
+ export interface EventBinding {
72
+ handleEvent(event: Event): any;
73
+ }
74
+
75
+ /** Get the EventBinding registered for a node+key, or undefined. */
76
+ export function getEventBinding(node: Node, key: string): EventBinding | undefined;
77
+
78
+ /**
79
+ * Read an element's html attributes onto fields that already exist on the element, to
80
+ * support plain-html instantiation like `<my-timer duration="7" auto-start>`.
81
+ *
82
+ * Attribute names convert from kebab-case to camelCase. A `${...}` attribute is JSON-parsed
83
+ * back to its original type. Every other attribute value is a string: if its field is named
84
+ * in `types`, the string is cast with that converter, otherwise it's assigned as a string.
85
+ *
86
+ * `types` maps a field name to a converter: Number, Boolean, String, Date, or any function
87
+ * taking the string and returning a value. Boolean is true for any string except 'false'
88
+ * and '0', so a bare attribute reads as true. Field names in `ignore` are skipped. */
89
+ export function assignAttributes(dest: HTMLElement, types?: Record<string, Function>, ignore?: string[]): void;
90
+
91
+ export class Template {
92
+ exprs: any[];
93
+ html: string[];
94
+ /** List key for keyed diffing, set by the JSX runtime from a `key` prop. */
95
+ key?: any;
96
+ constructor(htmlStrings: string[], exprs: any[]);
97
+ render(el?: HTMLElement | null, options?: RenderOptions): HTMLElement | DocumentFragment;
98
+ getCloseKey(): string;
99
+ }
100
+
101
+ /** JSX fragment marker for the classic/automatic factories: `<>...</>`. */
102
+ export const Fragment: unique symbol;
103
+
104
+ export function delve(obj: object, path: string[], createVal?: any): any;
105
+
106
+ /**
107
+ * Internal utilities and state. */
108
+ export const Globals: {
109
+ connected: WeakSet<HTMLElement>;
110
+ currentSlotChildren: any[] | null;
111
+ div: HTMLDivElement;
112
+ doc: Document;
113
+ elementClasses: {[key: string]: typeof Node};
114
+ htmlProps: {[key: string]: boolean};
115
+ rootNodeGroups: WeakMap<HTMLElement, any>;
116
+ objToEl: WeakMap<any, any>;
117
+ rendered: WeakSet<HTMLElement>;
118
+ shells: WeakMap<string[], any>;
119
+ reset: Function;
120
+ };
121
+
122
+ export const SolariteUtil: {
123
+ arraySame(a: any[], b: any[]): boolean;
124
+ attribsToObject(el: HTMLElement, ignore?: string | null): Record<string, any>;
125
+ bindId(root: any, el: HTMLElement): void;
126
+ bindStyles(style: HTMLStyleElement, root: HTMLElement): void;
127
+ camelToDashes(str: string): string;
128
+ dashesToCamel(str: string): string;
129
+ defineClass(Class: typeof HTMLElement, tagName?: string | null): void;
130
+ isIterable(obj: any): boolean;
131
+ trimEmptyNodes(nodes: NodeList | Node[]): Node[];
132
+ [key: string]: any;
133
+ };
134
+