lithent 0.31.0 โ†’ 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.
Files changed (47) hide show
  1. package/README.md +66 -185
  2. package/dist/diff.d.ts +1 -13
  3. package/dist/lithent.mjs +115 -169
  4. package/dist/lithent.mjs.map +1 -1
  5. package/dist/lithent.umd.js +1 -1
  6. package/dist/lithent.umd.js.map +1 -1
  7. package/dist/types/index.d.ts +5 -5
  8. package/dist/utils/predicator.d.ts +10 -14
  9. package/dist/utils/universalRef.d.ts +6 -18
  10. package/examples/dist/assets/index.32d7fabc.js +2 -0
  11. package/examples/dist/assets/index.32d7fabc.js.map +1 -0
  12. package/examples/dist/index.html +1 -1
  13. package/examples/package.json +6 -1
  14. package/examples/src/htm.js +20 -0
  15. package/examples/src/htm.ts +22 -0
  16. package/helper/dist/hook/effect.d.ts +1 -1
  17. package/helper/dist/lithentHelper.mjs +10 -9
  18. package/helper/dist/lithentHelper.mjs.map +1 -1
  19. package/helper/dist/lithentHelper.umd.js +1 -1
  20. package/helper/dist/lithentHelper.umd.js.map +1 -1
  21. package/helper/src/hook/effect.ts +5 -4
  22. package/helper/src/hook/store.ts +6 -7
  23. package/package.json +2 -11
  24. package/src/diff.ts +42 -73
  25. package/src/hook/unmount.ts +18 -9
  26. package/src/render.ts +49 -58
  27. package/src/types/index.ts +3 -3
  28. package/src/utils/predicator.ts +25 -14
  29. package/src/utils/universalRef.ts +21 -35
  30. package/src/wDom.ts +29 -70
  31. package/examples/dist/assets/index.8ff7cab2.js +0 -2
  32. package/examples/dist/assets/index.8ff7cab2.js.map +0 -1
  33. package/examples/dist/assets/index.91a636db.js +0 -2
  34. package/examples/dist/assets/index.91a636db.js.map +0 -1
  35. package/router/dist/Router.d.ts +0 -4
  36. package/router/dist/Router.mjs +0 -56
  37. package/router/dist/Router.mjs.map +0 -1
  38. package/router/dist/Router.umd.js +0 -2
  39. package/router/dist/Router.umd.js.map +0 -1
  40. package/router/dist/hook/params.d.ts +0 -2
  41. package/router/package.json +0 -37
  42. package/router/src/Router.tsx +0 -63
  43. package/router/src/components/Main.tsx +0 -14
  44. package/router/src/components/Sub.tsx +0 -7
  45. package/router/src/components/Sub2.tsx +0 -17
  46. package/router/src/example.tsx +0 -19
  47. package/router/src/hook/params.ts +0 -9
package/README.md CHANGED
@@ -1,200 +1,92 @@
1
- # litheNT Basic Usage
1
+ # lithent
2
2
 
3
- litheNT is a virtualDOM implementation library that behaves similarly to React.
3
+ > A lightweight Virtual DOM UI library
4
4
 
5
- [production motive](https://medium.com/p/d14ba89373d3)
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
- A simpler style of library inspired by Reactjs.
9
+ `(9.54 KiB / gzip: 3.54 KiB)`
8
10
 
9
- The idea of litheNT is to keep the value associated with a `component` as a closure.
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
- There aren't as many rules as in React, you just need to know how closures work in JSX and JavaScript.
19
+ ## Basic Guide
12
20
 
13
- ## Install
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
- ## Using JSX
29
+ #### With HTM
20
30
 
21
- Please include the JSX option in the build tool you use.
31
+ * [Htm Github](https://github.com/developit/htm)
22
32
 
23
- ```js
24
- // vite.config.js
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
- ## Example
37
-
38
- ```jsx
39
- // example.jsx
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
- const Root = mount(renew => {
166
- const parentNumber = state<number>(7, renew);
167
-
168
- const increaseParent = () => {
169
- parentNumber.v = parentNumber.v + 1;
170
- };
171
-
172
- const decreaseParent = () => {
173
- parentNumber.v = parentNumber.v - 1;
174
- };
175
-
176
- return () => (
177
- <Fragment>
178
- <ChildComponent parentValue={parentNumber.v}>
179
- <button onClick={increaseParent}>Increase - Parent</button>
180
- </ChildComponent>
181
- <button onClick={decreaseParent}>Decrease - Parent</button>
182
- </Fragment>
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
- render(<Root />, document.getElementById('root'));
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
- # Develop
79
+ ## Develop Guide
80
+
81
+ It's open source, so you can develop and contribute together.
190
82
 
191
- ## pnpm install (this project was created using pnpm.)
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
- ## project install
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
- ## project build
98
+ ### project build
207
99
  ```bash
208
- pnpm build:all
100
+ pnpm build
209
101
  ```
210
102
 
211
- ## Running the development environment
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: ({ originalWDom, newWDom, }: {
12
- originalWDom?: WDom | undefined;
13
- newWDom: WDom | TagFunctionResolver;
14
- }) => WDom;
2
+ export declare const makeNewWDomTree: (newWDom: WDom | TagFunctionResolver, originalWDom?: WDom) => WDom;