lithent 0.1.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 (73) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +202 -0
  3. package/dist/diff.d.ts +14 -0
  4. package/dist/hook/mountCallback.d.ts +3 -0
  5. package/dist/hook/ref.d.ts +3 -0
  6. package/dist/hook/unmount.d.ts +3 -0
  7. package/dist/hook/updateCallback.d.ts +2 -0
  8. package/dist/hook/useUpdate.d.ts +3 -0
  9. package/dist/index.d.ts +29 -0
  10. package/dist/lithent.mjs +867 -0
  11. package/dist/lithent.mjs.map +1 -0
  12. package/dist/lithent.umd.js +2 -0
  13. package/dist/lithent.umd.js.map +1 -0
  14. package/dist/render.d.ts +15 -0
  15. package/dist/types/index.d.ts +65 -0
  16. package/dist/utils/index.d.ts +3 -0
  17. package/dist/utils/predicator.d.ts +36 -0
  18. package/dist/utils/universalRef.d.ts +59 -0
  19. package/dist/wDom.d.ts +17 -0
  20. package/examples/dist/assets/index.e76a0ef8.js +2 -0
  21. package/examples/dist/assets/index.e76a0ef8.js.map +1 -0
  22. package/examples/dist/index.html +13 -0
  23. package/examples/package.json +33 -0
  24. package/examples/src/index.tsx +109 -0
  25. package/helper/dist/hook/computed.d.ts +4 -0
  26. package/helper/dist/hook/effect.d.ts +1 -0
  27. package/helper/dist/hook/state.d.ts +4 -0
  28. package/helper/dist/hook/store.d.ts +8 -0
  29. package/helper/dist/index.d.ts +4 -0
  30. package/helper/dist/lithentHelper.mjs +56 -0
  31. package/helper/dist/lithentHelper.mjs.map +1 -0
  32. package/helper/dist/lithentHelper.umd.js +2 -0
  33. package/helper/dist/lithentHelper.umd.js.map +1 -0
  34. package/helper/package.json +32 -0
  35. package/helper/src/hook/computed.ts +23 -0
  36. package/helper/src/hook/effect.ts +20 -0
  37. package/helper/src/hook/state.ts +26 -0
  38. package/helper/src/hook/store.ts +25 -0
  39. package/helper/src/index.ts +4 -0
  40. package/package.json +90 -0
  41. package/router/dist/Router.d.ts +4 -0
  42. package/router/dist/Router.mjs +56 -0
  43. package/router/dist/Router.mjs.map +1 -0
  44. package/router/dist/Router.umd.js +2 -0
  45. package/router/dist/Router.umd.js.map +1 -0
  46. package/router/dist/hook/params.d.ts +2 -0
  47. package/router/package.json +37 -0
  48. package/router/src/Router.tsx +63 -0
  49. package/router/src/components/Main.tsx +14 -0
  50. package/router/src/components/Sub.tsx +7 -0
  51. package/router/src/components/Sub2.tsx +17 -0
  52. package/router/src/example.tsx +19 -0
  53. package/router/src/hook/params.ts +9 -0
  54. package/src/diff.ts +235 -0
  55. package/src/examples/callback.tsx +81 -0
  56. package/src/examples/insert.tsx +36 -0
  57. package/src/examples/loop.tsx +33 -0
  58. package/src/examples/nested.tsx +44 -0
  59. package/src/examples/renew.tsx +29 -0
  60. package/src/examples/selectbox.tsx +42 -0
  61. package/src/examples/textarea.tsx +24 -0
  62. package/src/hook/mountCallback.ts +41 -0
  63. package/src/hook/ref.ts +1 -0
  64. package/src/hook/unmount.ts +26 -0
  65. package/src/hook/updateCallback.ts +29 -0
  66. package/src/hook/useUpdate.ts +51 -0
  67. package/src/index.ts +50 -0
  68. package/src/render.ts +409 -0
  69. package/src/types/index.ts +107 -0
  70. package/src/utils/index.ts +52 -0
  71. package/src/utils/predicator.ts +119 -0
  72. package/src/utils/universalRef.ts +137 -0
  73. package/src/wDom.ts +284 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2023 superlucky84
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,202 @@
1
+ # Basic Usage
2
+
3
+ Wwact is a virtualDOM implementation library that behaves similarly to React.
4
+
5
+ [production motive](https://medium.com/p/d14ba89373d3)
6
+
7
+ A simpler style of library inspired by Reactjs.
8
+
9
+ The idea of wwact is to keep the value associated with a `component` as a closure.
10
+
11
+ There aren't as many rules as in React, you just need to know how closures work in JSX and JavaScript.
12
+
13
+ ## Install
14
+
15
+ ```bash
16
+ pnpm add wwact
17
+ ```
18
+
19
+ ## Using JSX
20
+
21
+ Please include the JSX option in the build tool you use.
22
+
23
+ ```js
24
+ // vite.config.js
25
+
26
+ export default defineConfig({
27
+ ...
28
+ esbuild: {
29
+ jsxFactory: 'h',
30
+ jsxFragment: 'Fragment',
31
+ },
32
+ ...
33
+ });
34
+ ```
35
+
36
+ ## Example
37
+
38
+ ```jsx
39
+ // example.jsx
40
+ import {
41
+ h,
42
+ Fragment,
43
+ render,
44
+ ref,
45
+ mountCallback,
46
+ updateCallback,
47
+ wwx,
48
+ } from 'wwact';
49
+ import { state, computed, effect } from 'wwact/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 = wwx<{ 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>('text', renew);
59
+ const getParentValue = () => props.parentValue;
60
+ const parentValue = props.parentValue;
61
+ const summ = computed<() => number>(
62
+ () => count.v + notRefValue + props.parentValue
63
+ );
64
+
65
+ // Even if you don't use a ref, the private value is always maintained as a regular variable.
66
+ let notRefValue = props.parentValue;
67
+
68
+ // Ref is only used to reference the DOM.
69
+ const domRef = ref(null);
70
+
71
+ const increase = () => {
72
+ count.v = count.v + 1;
73
+ notRefValue += 1;
74
+ };
75
+
76
+ const handleInputChane = (event: InputEvent) => {
77
+ text.v = (event.target as HTMLInputElement).value;
78
+ };
79
+
80
+ const handleMounted = () => {
81
+ console.log('MOUNTED', domRef);
82
+
83
+ return () => console.log('UNMOUNT');
84
+ };
85
+ const handleUpdated = () => {
86
+ console.log('UPDATE - parentValue');
87
+
88
+ return () => console.log('UPDATED');
89
+ };
90
+
91
+ mountCallback(handleMounted);
92
+ updateCallback(handleUpdated, () => [props.parentValue]); // Only Defs Updated (using a closure to update a value)
93
+
94
+ // Behaves like `react`'s `useEffect`
95
+ effect(
96
+ () => console.log('INJECT'),
97
+ () => console.log('CLEAN_UP'),
98
+ () => [count.v]
99
+ );
100
+
101
+ // Wrap in a function and return (using a closure to hold the value)
102
+ // This is the "update" function.
103
+ return () => (
104
+ <Fragment>
105
+ {/* Note that the event is onInput (we use the native event name to avoid confusion). */}
106
+ <input type="text" value={text.v} onInput={handleInputChane} />
107
+ <div ref={domRef}>count: {count.v}</div>
108
+ {/* When the value is updated from the parent component, the function declared inside is executed, so you need to use the `props.` call by reference to output the latest value of the updated property. */}
109
+ <div>parentValue: {props.parentValue} (working)</div>
110
+ <div>parentValue: {getParentValue()} (working)</div>
111
+ <div>parentValue: {parentValue} (not working)</div>
112
+ <div>sum: {count.v + notRefValue + props.parentValue}</div>
113
+ <div>sum(computed): {summ.v}</div>
114
+ {/* It doesn't pull it out from under the reference, it uses the value directly, so you can just use it. */}
115
+ <div>notRefValue: {notRefValue}</div>
116
+ {children}
117
+ <button onClick={increase}>Increase</button>
118
+ </Fragment>
119
+ );
120
+ }
121
+ );
122
+
123
+ const Root = wwx(renew => {
124
+ const parentNumber = state<number>(7, renew);
125
+
126
+ const increaseParent = () => {
127
+ parentNumber.v = parentNumber.v + 1;
128
+ };
129
+
130
+ const decreaseParent = () => {
131
+ parentNumber.v = parentNumber.v - 1;
132
+ };
133
+
134
+ return () => (
135
+ <Fragment>
136
+ <button onClick={decreaseParent}>Decrease - Parent</button>
137
+ <div>
138
+ <ChildComponent parentValue={parentNumber.v}>
139
+ <button onClick={increaseParent}>Increase - Parent</button>
140
+ </ChildComponent>
141
+ </div>
142
+ </Fragment>
143
+ );
144
+ });
145
+ const root = <Root />;
146
+
147
+ render(root, document.getElementById('root'));
148
+ ```
149
+
150
+ # Develop
151
+
152
+ ## pnpm install (this project was created using pnpm.)
153
+
154
+ ```bash
155
+ npm install -g pnpm
156
+ ```
157
+
158
+ ## project install
159
+ ```bash
160
+ git clone https://github.com/superlucky84/wwact.git
161
+
162
+ cd wwact
163
+
164
+ pnpm install
165
+ ```
166
+
167
+ ## project build
168
+ ```bash
169
+ pnpm build:all
170
+ ```
171
+
172
+ ## Running the development environment
173
+ ```bash
174
+ pnpm dev:wwact
175
+ ```
176
+
177
+ ---
178
+
179
+ # Packages
180
+
181
+ ## wwact
182
+
183
+ Main module
184
+
185
+ ## router
186
+
187
+ Hash routing extension
188
+
189
+ ## compiler
190
+
191
+ Converter for using template syntax(.wwx)
192
+
193
+ Can be used using `jsx` without using `wwx`
194
+
195
+ ## vitePlugin
196
+
197
+ A plugin to connect the template syntax (wwx) and the transpiler to the vite build tool
198
+
199
+ ## wwveal
200
+
201
+ Presentation tool made with wwact
202
+
package/dist/diff.d.ts ADDED
@@ -0,0 +1,14 @@
1
+ /**
2
+ * 변경점의 컴포넌트로 부터 기존트리와 상태를 비교하며 새로 가상돔 트리를 새로 만든다.
3
+ * (오리지널 가상돔으로 부터 유의미한 상태를 유지해야 하는 경우를 판별하여 새로운 트리를 만듬)
4
+ *
5
+ * 1. 동일한 트리의 위치해 있고 오리지널과 컴포넌트의 타입이 같은경우 기존 상태를 계승한다.
6
+ * 2. 동일한 컴포넌트가 아니라고 판단되는 경우에는 기존 상태를 무시하는 새로운 트리를 생성한다.
7
+ * 3. fragment타입의 경우에는 children의 갯수까지 같아야지 같은 타입이라고 판단한다.
8
+ * 4. loop타입의 자식들은 같은 키값을 가졌는지로 동일한지 판단하며 키값이 없을경우 fragment타입처럼 취급한다.
9
+ */
10
+ import { WDom, TagFunctionResolver } from './types';
11
+ export declare const makeNewWDomTree: ({ originalWDom, newWDom, }: {
12
+ originalWDom?: WDom | undefined;
13
+ newWDom: WDom | TagFunctionResolver;
14
+ }) => WDom;
@@ -0,0 +1,3 @@
1
+ import { WDom } from '../types';
2
+ export declare const mountCallback: (effectAction: () => void) => void;
3
+ export declare const runMountedQueueFromWDom: (newWDom: WDom) => void;
@@ -0,0 +1,3 @@
1
+ export declare const ref: <T>(initValue: T) => {
2
+ value: T;
3
+ };
@@ -0,0 +1,3 @@
1
+ import { WDom } from '../types';
2
+ export declare const unmount: (effectAction: () => void) => void;
3
+ export declare const runUnmountQueueFromWDom: (newWDom: WDom) => void;
@@ -0,0 +1,2 @@
1
+ export declare const updateCallback: (effectAction: () => (() => void) | void, dependencies?: () => any[]) => void;
2
+ export declare const runUpdateCallback: () => void;
@@ -0,0 +1,3 @@
1
+ import { WDom } from '../types';
2
+ export declare const useUpdated: (effectAction: () => (() => void) | void, dependencies?: () => any[]) => void;
3
+ export declare const runUpdatedQueueFromWDom: (newWDom: WDom) => void;
@@ -0,0 +1,29 @@
1
+ import { h, Fragment, mount } from './wDom';
2
+ import { render } from './render';
3
+ import { mountCallback } from './hook/mountCallback';
4
+ import { updateCallback } from './hook/updateCallback';
5
+ import { ref } from './hook/ref';
6
+ declare const ext: {
7
+ componentRef: import('./types').ComponentRef;
8
+ componentKeyRef: {
9
+ value: import('./types').Props;
10
+ };
11
+ dataStoreStore: {
12
+ [key: string]: import('./types').UseDataStoreValue;
13
+ };
14
+ dataStoreRenderQueue: {
15
+ [key: string]: (() => boolean)[];
16
+ };
17
+ checkFunction: (target: unknown) => target is Function;
18
+ getComponentKey: () => import('./types').Props;
19
+ componentRender: (componentKey: import('./types').Props) => () => boolean;
20
+ };
21
+ export type { WDom, TagFunction, TagFunctionResolver, FragmentFunction, ComponentSubKey, ComponentRef, Props, Renew, MiddleStateWDomChildren, MiddleStateWDom, UseDataStoreValue, NodePointer, Param, } from './types';
22
+ declare global {
23
+ namespace JSX {
24
+ interface IntrinsicElements {
25
+ [name: string]: any;
26
+ }
27
+ }
28
+ }
29
+ export { h, Fragment, render, mount, mountCallback, updateCallback, ref, ext };