lithent 0.31.1 โ 0.32.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/README.md +66 -185
- package/dist/diff.d.ts +1 -13
- package/dist/lithent.mjs +113 -167
- package/dist/lithent.mjs.map +1 -1
- package/dist/lithent.umd.js +1 -1
- package/dist/lithent.umd.js.map +1 -1
- package/dist/types/index.d.ts +5 -5
- package/dist/utils/predicator.d.ts +10 -14
- package/dist/utils/universalRef.d.ts +6 -18
- package/examples/dist/assets/index.32d7fabc.js +2 -0
- package/examples/dist/assets/index.32d7fabc.js.map +1 -0
- package/examples/dist/index.html +1 -1
- package/examples/package.json +6 -1
- package/examples/src/htm.js +20 -0
- package/examples/src/htm.ts +22 -0
- package/helper/dist/hook/effect.d.ts +1 -1
- package/helper/dist/lithentHelper.mjs +10 -9
- package/helper/dist/lithentHelper.mjs.map +1 -1
- package/helper/dist/lithentHelper.umd.js +1 -1
- package/helper/dist/lithentHelper.umd.js.map +1 -1
- package/helper/src/hook/effect.ts +5 -4
- package/helper/src/hook/store.ts +6 -7
- package/package.json +2 -11
- package/src/diff.ts +42 -73
- package/src/hook/unmount.ts +18 -9
- package/src/render.ts +46 -55
- package/src/types/index.ts +3 -3
- package/src/utils/predicator.ts +25 -14
- package/src/utils/universalRef.ts +21 -35
- package/src/wDom.ts +29 -70
- package/examples/dist/assets/index.f72705d1.js +0 -2
- package/examples/dist/assets/index.f72705d1.js.map +0 -1
- package/router/dist/Router.d.ts +0 -4
- package/router/dist/Router.mjs +0 -56
- package/router/dist/Router.mjs.map +0 -1
- package/router/dist/Router.umd.js +0 -2
- package/router/dist/Router.umd.js.map +0 -1
- package/router/dist/hook/params.d.ts +0 -2
- package/router/package.json +0 -37
- package/router/src/Router.tsx +0 -63
- package/router/src/components/Main.tsx +0 -14
- package/router/src/components/Sub.tsx +0 -7
- package/router/src/components/Sub2.tsx +0 -17
- package/router/src/example.tsx +0 -19
- package/router/src/hook/params.ts +0 -9
package/README.md
CHANGED
|
@@ -1,200 +1,92 @@
|
|
|
1
|
-
#
|
|
1
|
+
# lithent
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
> A lightweight Virtual DOM UI library
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
Lithent were developed to make it easy to insert Virtual DOM component
|
|
6
|
+
fragments into pages already drawn with SSR, and are intended to be
|
|
7
|
+
used lightly with other libraries.
|
|
6
8
|
|
|
7
|
-
|
|
9
|
+
`(9.54 KiB / gzip: 3.54 KiB)`
|
|
8
10
|
|
|
9
|
-
|
|
11
|
+
## ๐ฉ Table of Contents
|
|
12
|
+
* [Basic Guide](#basic-guide)
|
|
13
|
+
* [How To Install](#how-to-install)
|
|
14
|
+
* [Width HTM](#with-htm)
|
|
15
|
+
* [Width JSX](#with-jsx)
|
|
16
|
+
* [Examples](#examples)
|
|
17
|
+
* [Develop Guide](#develop-guide)
|
|
10
18
|
|
|
11
|
-
|
|
19
|
+
## Basic Guide
|
|
12
20
|
|
|
13
|
-
|
|
21
|
+
* https://superlucky84.github.io/lithent/
|
|
22
|
+
|
|
23
|
+
## How To Install
|
|
14
24
|
|
|
15
25
|
```bash
|
|
16
26
|
pnpm add lithent
|
|
17
27
|
```
|
|
18
28
|
|
|
19
|
-
|
|
29
|
+
#### With HTM
|
|
20
30
|
|
|
21
|
-
|
|
31
|
+
* [Htm Github](https://github.com/developit/htm)
|
|
22
32
|
|
|
23
|
-
```
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
export default defineConfig({
|
|
27
|
-
...
|
|
28
|
-
esbuild: {
|
|
29
|
-
jsxFactory: 'h',
|
|
30
|
-
jsxFragment: 'Fragment',
|
|
31
|
-
},
|
|
32
|
-
...
|
|
33
|
-
});
|
|
33
|
+
```bash
|
|
34
|
+
pnpm add -D htm
|
|
34
35
|
```
|
|
35
36
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
import {
|
|
41
|
-
h,
|
|
42
|
-
Fragment,
|
|
43
|
-
render,
|
|
44
|
-
ref,
|
|
45
|
-
mountCallback,
|
|
46
|
-
updateCallback,
|
|
47
|
-
mount,
|
|
48
|
-
} from 'lithent';
|
|
49
|
-
import { state, computed, effect, store } from 'lithent-helper';
|
|
50
|
-
|
|
51
|
-
// This is the "mount" function.
|
|
52
|
-
// This function is only executed on mount, and on update, only updates `props` and then executes the internal return function.
|
|
53
|
-
// childen is passed as the second argument.
|
|
54
|
-
const ChildComponent = mount<{ parentValue: number }>(
|
|
55
|
-
(renew, props, children) => {
|
|
56
|
-
// The value is used as a "getter" to make it easy to get and write to in the higher-order functions it returns
|
|
57
|
-
const count = state<number>(1, renew);
|
|
58
|
-
const text = state<string>(
|
|
59
|
-
'"destructuring" the "props" value directly from the mount function will cause referencing issues, so if you want to use it, you need to "destructuring" it from the internal function (updater).',
|
|
60
|
-
renew
|
|
61
|
-
);
|
|
62
|
-
const getParentValue = () => props.parentValue;
|
|
63
|
-
const parentValueFromMount = props.parentValue;
|
|
64
|
-
const summ = computed<number>(
|
|
65
|
-
() => count.v + notRefValue + props.parentValue
|
|
66
|
-
);
|
|
67
|
-
|
|
68
|
-
const localStore = store<{ text: string; count: number }>({
|
|
69
|
-
text: 's',
|
|
70
|
-
count: 0,
|
|
71
|
-
})(renew);
|
|
72
|
-
/*
|
|
73
|
-
// To share a store, make it externally and use `asign`.
|
|
74
|
-
const asignStore = store<{ text: string; count: number }>({ text: 's', count: 0 });
|
|
75
|
-
|
|
76
|
-
const sharedStore = asignStore(nenew);
|
|
77
|
-
*/
|
|
78
|
-
|
|
79
|
-
// Even if you don't use a ref, the private value is always maintained as a regular variable.
|
|
80
|
-
let notRefValue = props.parentValue;
|
|
81
|
-
|
|
82
|
-
// Ref is only used to reference the DOM.
|
|
83
|
-
const domRef = ref(null);
|
|
84
|
-
|
|
85
|
-
const increase = () => {
|
|
86
|
-
count.v = count.v + 1;
|
|
87
|
-
notRefValue += 1;
|
|
88
|
-
};
|
|
89
|
-
|
|
90
|
-
const handleInputChane = (event: InputEvent) => {
|
|
91
|
-
text.v = (event.target as HTMLInputElement).value;
|
|
92
|
-
};
|
|
93
|
-
|
|
94
|
-
const localStoreUpdate = () => {
|
|
95
|
-
localStore.count += 1;
|
|
96
|
-
localStore.text += '1';
|
|
97
|
-
};
|
|
98
|
-
|
|
99
|
-
const handleMounted = () => {
|
|
100
|
-
console.log('MOUNTED', domRef);
|
|
101
|
-
|
|
102
|
-
return () => console.log('UNMOUNT');
|
|
103
|
-
};
|
|
104
|
-
const handleUpdated = () => {
|
|
105
|
-
console.log('UPDATE - parentValue');
|
|
106
|
-
|
|
107
|
-
return () => console.log('UPDATED');
|
|
108
|
-
};
|
|
109
|
-
|
|
110
|
-
mountCallback(handleMounted);
|
|
111
|
-
updateCallback(handleUpdated, () => [props.parentValue]); // Only Defs Updated (using a closure to update a value)
|
|
112
|
-
|
|
113
|
-
// Behaves like `react`'s `useEffect`
|
|
114
|
-
effect(
|
|
115
|
-
() => console.log('INJECT'),
|
|
116
|
-
() => console.log('CLEAN_UP'),
|
|
117
|
-
() => [count.v]
|
|
118
|
-
);
|
|
119
|
-
|
|
120
|
-
// Wrap in a function and return (using a closure to hold the value)
|
|
121
|
-
// This is the "update" function.
|
|
122
|
-
return ({ parentValue }) => (
|
|
123
|
-
<Fragment>
|
|
124
|
-
{/* Note that the event is onInput (we use the native event name to avoid confusion). */}
|
|
125
|
-
<div>
|
|
126
|
-
<textarea
|
|
127
|
-
value={text.v}
|
|
128
|
-
onInput={handleInputChane}
|
|
129
|
-
style={{ width: '300px', height: '100px' }}
|
|
130
|
-
/>
|
|
131
|
-
</div>
|
|
132
|
-
<div>{text.v}</div>
|
|
133
|
-
<div>
|
|
134
|
-
<div style={{ color: 'blue' }}>
|
|
135
|
-
parentValueFromRef: {props.parentValue} (working)
|
|
136
|
-
</div>
|
|
137
|
-
<div style={{ color: 'blue' }}>
|
|
138
|
-
parentValueFromFunction: {getParentValue()} (working)
|
|
139
|
-
</div>
|
|
140
|
-
<div style={{ color: 'blue' }}>
|
|
141
|
-
parentValueFromUpdaterDestructuring: {parentValue} (working)
|
|
142
|
-
</div>
|
|
143
|
-
<div style={{ color: 'red' }}>
|
|
144
|
-
parentValueFromMounterDestructuring: {parentValueFromMount} (not
|
|
145
|
-
working)
|
|
146
|
-
</div>
|
|
147
|
-
</div>
|
|
148
|
-
<div>
|
|
149
|
-
<div ref={domRef}>count: {count.v}</div>
|
|
150
|
-
<div>sum: {count.v + notRefValue + props.parentValue}</div>
|
|
151
|
-
<div>sum(computed): {summ.v}</div>
|
|
152
|
-
{/* It doesn't pull it out from under the reference, it uses the value directly, so you can just use it. */}
|
|
153
|
-
<div>notRefValue: {notRefValue}</div>
|
|
154
|
-
<div>localStore(text): {localStore.text}</div>
|
|
155
|
-
<div>localStore(count): {localStore.count}</div>
|
|
156
|
-
</div>
|
|
157
|
-
<button onClick={increase}>Increase</button>
|
|
158
|
-
<button onClick={localStoreUpdate}>localStoreUpdate</button>
|
|
159
|
-
{children}
|
|
160
|
-
</Fragment>
|
|
161
|
-
);
|
|
162
|
-
}
|
|
37
|
+
```js
|
|
38
|
+
import { h, render, mount } from 'lithent';
|
|
39
|
+
import htm from 'htm';
|
|
40
|
+
const html = htm.bind(h);
|
|
163
41
|
);
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
#### With JSX
|
|
45
|
+
|
|
46
|
+
* [Setting Guide](https://superlucky84.github.io/lithent/#install)
|
|
47
|
+
|
|
48
|
+
## Examples
|
|
49
|
+
|
|
50
|
+
* [More Examples](https://superlucky84.github.io/lithent/#examples)
|
|
164
51
|
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
const
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
</
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
);
|
|
52
|
+
```js
|
|
53
|
+
import { h, render, mount, Fragment } from 'lithent';
|
|
54
|
+
import { state } from 'lithent/helper';
|
|
55
|
+
import htm from 'htm';
|
|
56
|
+
const html = htm.bind(h);
|
|
57
|
+
|
|
58
|
+
const Component = mount((r, _props) => {
|
|
59
|
+
const count = state(0, r);
|
|
60
|
+
|
|
61
|
+
const change = () => (count.v += 1);
|
|
62
|
+
|
|
63
|
+
// Updater
|
|
64
|
+
return () => html`
|
|
65
|
+
<${Fragment}>
|
|
66
|
+
<li>count: ${count.v}</li>
|
|
67
|
+
<button onClick=${change}>increase</button>
|
|
68
|
+
<//>
|
|
69
|
+
`;
|
|
184
70
|
});
|
|
185
71
|
|
|
186
|
-
|
|
72
|
+
// insertBefore
|
|
73
|
+
// render(`<${Component} />`, document.getElementById('root'), document.getElementById('nextElement'));
|
|
74
|
+
|
|
75
|
+
// appendChild
|
|
76
|
+
render(html`<${Component} />`, document.getElementById('root'));
|
|
187
77
|
```
|
|
188
78
|
|
|
189
|
-
|
|
79
|
+
## Develop Guide
|
|
80
|
+
|
|
81
|
+
It's open source, so you can develop and contribute together.
|
|
190
82
|
|
|
191
|
-
|
|
83
|
+
### pnpm install (this project was created using pnpm.)
|
|
192
84
|
|
|
193
85
|
```bash
|
|
194
86
|
npm install -g pnpm
|
|
195
87
|
```
|
|
196
88
|
|
|
197
|
-
|
|
89
|
+
### project install
|
|
198
90
|
```bash
|
|
199
91
|
git clone https://github.com/superlucky84/lithent.git
|
|
200
92
|
|
|
@@ -203,23 +95,12 @@ cd lithent
|
|
|
203
95
|
pnpm install
|
|
204
96
|
```
|
|
205
97
|
|
|
206
|
-
|
|
98
|
+
### project build
|
|
207
99
|
```bash
|
|
208
|
-
pnpm build
|
|
100
|
+
pnpm build
|
|
209
101
|
```
|
|
210
102
|
|
|
211
|
-
|
|
103
|
+
### Running the development environment
|
|
212
104
|
```bash
|
|
213
|
-
pnpm dev
|
|
105
|
+
pnpm dev // or pnpm dev:core
|
|
214
106
|
```
|
|
215
|
-
|
|
216
|
-
---
|
|
217
|
-
|
|
218
|
-
# Packages
|
|
219
|
-
|
|
220
|
-
## lithent
|
|
221
|
-
|
|
222
|
-
## helper
|
|
223
|
-
|
|
224
|
-
## router
|
|
225
|
-
|
package/dist/diff.d.ts
CHANGED
|
@@ -1,14 +1,2 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* ๋ณ๊ฒฝ์ ์ ์ปดํฌ๋ํธ๋ก ๋ถํฐ ๊ธฐ์กดํธ๋ฆฌ์ ์ํ๋ฅผ ๋น๊ตํ๋ฉฐ ์๋ก ๊ฐ์๋ ํธ๋ฆฌ๋ฅผ ์๋ก ๋ง๋ ๋ค.
|
|
3
|
-
* (์ค๋ฆฌ์ง๋ ๊ฐ์๋์ผ๋ก ๋ถํฐ ์ ์๋ฏธํ ์ํ๋ฅผ ์ ์งํด์ผ ํ๋ ๊ฒฝ์ฐ๋ฅผ ํ๋ณํ์ฌ ์๋ก์ด ํธ๋ฆฌ๋ฅผ ๋ง๋ฌ)
|
|
4
|
-
*
|
|
5
|
-
* 1. ๋์ผํ ํธ๋ฆฌ์ ์์นํด ์๊ณ ์ค๋ฆฌ์ง๋๊ณผ ์ปดํฌ๋ํธ์ ํ์
์ด ๊ฐ์๊ฒฝ์ฐ ๊ธฐ์กด ์ํ๋ฅผ ๊ณ์นํ๋ค.
|
|
6
|
-
* 2. ๋์ผํ ์ปดํฌ๋ํธ๊ฐ ์๋๋ผ๊ณ ํ๋จ๋๋ ๊ฒฝ์ฐ์๋ ๊ธฐ์กด ์ํ๋ฅผ ๋ฌด์ํ๋ ์๋ก์ด ํธ๋ฆฌ๋ฅผ ์์ฑํ๋ค.
|
|
7
|
-
* 3. fragmentํ์
์ ๊ฒฝ์ฐ์๋ children์ ๊ฐฏ์๊น์ง ๊ฐ์์ผ์ง ๊ฐ์ ํ์
์ด๋ผ๊ณ ํ๋จํ๋ค.
|
|
8
|
-
* 4. loopํ์
์ ์์๋ค์ ๊ฐ์ ํค๊ฐ์ ๊ฐ์ก๋์ง๋ก ๋์ผํ์ง ํ๋จํ๋ฉฐ ํค๊ฐ์ด ์์๊ฒฝ์ฐ fragmentํ์
์ฒ๋ผ ์ทจ๊ธํ๋ค.
|
|
9
|
-
*/
|
|
10
1
|
import { WDom, TagFunctionResolver } from './types';
|
|
11
|
-
export declare const makeNewWDomTree: (
|
|
12
|
-
originalWDom?: WDom | undefined;
|
|
13
|
-
newWDom: WDom | TagFunctionResolver;
|
|
14
|
-
}) => WDom;
|
|
2
|
+
export declare const makeNewWDomTree: (newWDom: WDom | TagFunctionResolver, originalWDom?: WDom) => WDom;
|