lithent 1.18.4 → 1.19.1

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 (63) hide show
  1. package/README.md +79 -16
  2. package/dist/hook/{unmount.d.ts → internal/unmount.d.ts} +1 -1
  3. package/dist/hook/{useUpdate.d.ts → internal/useUpdate.d.ts} +1 -1
  4. package/dist/hook/mountCallback.d.ts +11 -3
  5. package/dist/hook/mountReadyCallback.d.ts +10 -0
  6. package/dist/index.d.ts +4 -3
  7. package/dist/lithent.mjs +380 -336
  8. package/dist/lithent.mjs.map +1 -1
  9. package/dist/lithent.umd.js +1 -1
  10. package/dist/lithent.umd.js.map +1 -1
  11. package/dist/types/index.d.ts +8 -6
  12. package/dist/utils/predicator.d.ts +8 -0
  13. package/dist/utils/universalRef.d.ts +6 -10
  14. package/dist/wDom.d.ts +4 -0
  15. package/examples/dist/assets/index-CqMCFcHq.js +2 -0
  16. package/examples/dist/assets/index-CqMCFcHq.js.map +1 -0
  17. package/examples/dist/index.html +1 -1
  18. package/helper/dist/hook/computed.d.ts +4 -3
  19. package/helper/dist/hook/context.d.ts +19 -0
  20. package/helper/dist/hook/state.d.ts +2 -1
  21. package/helper/dist/hook/store.d.ts +7 -6
  22. package/helper/dist/index.d.ts +6 -0
  23. package/helper/dist/lithentHelper.mjs +138 -74
  24. package/helper/dist/lithentHelper.mjs.map +1 -1
  25. package/helper/dist/lithentHelper.umd.js +1 -1
  26. package/helper/dist/lithentHelper.umd.js.map +1 -1
  27. package/helper/dist/utils/children.d.ts +6 -0
  28. package/helper/dist/utils/types.d.ts +3 -0
  29. package/helper/src/hook/computed.ts +6 -6
  30. package/helper/src/hook/context.tsx +202 -0
  31. package/helper/src/hook/state.ts +4 -5
  32. package/helper/src/hook/store.ts +11 -6
  33. package/helper/src/index.ts +12 -0
  34. package/helper/src/tests/context.tsx +813 -0
  35. package/helper/src/tests/renderprops.tsx +81 -0
  36. package/helper/src/utils/children.ts +15 -0
  37. package/helper/src/utils/types.ts +10 -0
  38. package/package.json +1 -1
  39. package/src/diff.ts +59 -57
  40. package/src/hook/{unmount.ts → internal/unmount.ts} +9 -5
  41. package/src/hook/{useUpdate.ts → internal/useUpdate.ts} +10 -5
  42. package/src/hook/mountCallback.ts +30 -11
  43. package/src/hook/mountReadyCallback.ts +44 -0
  44. package/src/hook/updateCallback.ts +13 -5
  45. package/src/index.ts +9 -2
  46. package/src/render.ts +75 -100
  47. package/src/tests/core-childrentest.tsx +235 -0
  48. package/src/tests/core-mountreadycallback.tsx +283 -0
  49. package/src/tests/core-ref.tsx +105 -0
  50. package/src/types/index.ts +11 -6
  51. package/src/utils/predicator.ts +62 -40
  52. package/src/utils/redraw.ts +4 -5
  53. package/src/utils/universalRef.ts +16 -13
  54. package/src/wDom.ts +172 -109
  55. package/ssr/dist/lithentSsr.mjs +32 -32
  56. package/ssr/dist/lithentSsr.mjs.map +1 -1
  57. package/ssr/dist/lithentSsr.umd.js +2 -2
  58. package/ssr/dist/lithentSsr.umd.js.map +1 -1
  59. package/ssr/src/helper/index.ts +1 -1
  60. package/ssr/src/hydration.ts +8 -9
  61. package/ssr/src/renderToString.ts +2 -2
  62. package/examples/dist/assets/index-GZ-P6cMy.js +0 -2
  63. package/examples/dist/assets/index-GZ-P6cMy.js.map +0 -1
package/README.md CHANGED
@@ -38,6 +38,8 @@ used lightly in a variety of situations.
38
38
  - [Examples](#examples)
39
39
  - [With ESM](#with-esm)
40
40
  - [With UMD](#with-umd)
41
+ - [Context API](#context-api)
42
+ - [Multi-value Provider Example](#multi-value-provider-example)
41
43
  - [Related Projects](#related-projects)
42
44
  - [Develop Guide](#develop-guide)
43
45
  - [Test](#test)
@@ -90,14 +92,14 @@ pnpm add lithent
90
92
 
91
93
  #### Or Use CDN
92
94
 
93
- * UMD : https://cdn.jsdelivr.net/npm/lithent@1.18.4/dist/lithent.umd.js
94
- * UMD-HELPER: https://cdn.jsdelivr.net/npm/lithent@1.18.4/helper/dist/lithentHelper.umd.js
95
- * UMD-FTAGS: https://cdn.jsdelivr.net/npm/lithent@1.18.4/ftags/dist/lithentFTags.umd.js
96
- * UMD-TAG: https://cdn.jsdelivr.net/npm/lithent@1.18.4/tag/dist/lithentTag.umd.js
97
- * ESM : https://cdn.jsdelivr.net/npm/lithent@1.18.4/dist/lithent.mjs
98
- * ESM-HELPER: https://cdn.jsdelivr.net/npm/lithent@1.18.4/helper/dist/lithentHelper.mjs
99
- * ESM-FTAGS: https://cdn.jsdelivr.net/npm/lithent@1.18.4/ftags/dist/lithentFTags.mjs
100
- * ESM-TAG: https://cdn.jsdelivr.net/npm/lithent@1.18.4/tag/dist/lithentTag.mjs
95
+ * UMD : https://cdn.jsdelivr.net/npm/lithent@1.19.1/dist/lithent.umd.js
96
+ * UMD-HELPER: https://cdn.jsdelivr.net/npm/lithent@1.19.1/helper/dist/lithentHelper.umd.js
97
+ * UMD-FTAGS: https://cdn.jsdelivr.net/npm/lithent@1.19.1/ftags/dist/lithentFTags.umd.js
98
+ * UMD-TAG: https://cdn.jsdelivr.net/npm/lithent@1.19.1/tag/dist/lithentTag.umd.js
99
+ * ESM : https://cdn.jsdelivr.net/npm/lithent@1.19.1/dist/lithent.mjs
100
+ * ESM-HELPER: https://cdn.jsdelivr.net/npm/lithent@1.19.1/helper/dist/lithentHelper.mjs
101
+ * ESM-FTAGS: https://cdn.jsdelivr.net/npm/lithent@1.19.1/ftags/dist/lithentFTags.mjs
102
+ * ESM-TAG: https://cdn.jsdelivr.net/npm/lithent@1.19.1/tag/dist/lithentTag.mjs
101
103
 
102
104
 
103
105
  It's easier to use lithent with JSX or HTM.
@@ -122,9 +124,9 @@ import { fTags, fFragment, fMount } from 'lithent/ftags';
122
124
  const { section, div, p, br, strong } = fTags;
123
125
 
124
126
  /* UMD
125
- <script src="https://cdn.jsdelivr.net/npm/lithent@1.18.4/dist/lithent.umd.js"></script>
126
- <script src="https://cdn.jsdelivr.net/npm/lithent@1.18.4/helper/dist/lithentHelper.umd.js"></script>
127
- <script src="https://cdn.jsdelivr.net/npm/lithent@1.18.4/ftags/dist/lithentFTags.umd.js"></script>
127
+ <script src="https://cdn.jsdelivr.net/npm/lithent@1.19.1/dist/lithent.umd.js"></script>
128
+ <script src="https://cdn.jsdelivr.net/npm/lithent@1.19.1/helper/dist/lithentHelper.umd.js"></script>
129
+ <script src="https://cdn.jsdelivr.net/npm/lithent@1.19.1/ftags/dist/lithentFTags.umd.js"></script>
128
130
 
129
131
  const { render } = lithent;
130
132
  const { fTags, fMount, fFragment } = lithentFTags;
@@ -197,10 +199,10 @@ const destroy = render(lTag`<${Component} />`, document.getElementById('root'),
197
199
  #### With UMD
198
200
 
199
201
  ```html
200
- <script src="https://cdn.jsdelivr.net/npm/lithent@1.18.4/dist/lithent.umd.js"></script>
201
- <!--script src="https://cdn.jsdelivr.net/npm/lithent@1.18.4/helper/dist/lithentHelper.umd.js"></script-->
202
- <script src="https://cdn.jsdelivr.net/npm/lithent@1.18.4/tag/dist/lithentTag.umd.js"></script>
203
- <!--script src="https://cdn.jsdelivr.net/npm/lithent@1.18.4/ftags/dist/lithentFTags.umd.js"></script-->
202
+ <script src="https://cdn.jsdelivr.net/npm/lithent@1.19.1/dist/lithent.umd.js"></script>
203
+ <!--script src="https://cdn.jsdelivr.net/npm/lithent@1.19.1/helper/dist/lithentHelper.umd.js"></script-->
204
+ <script src="https://cdn.jsdelivr.net/npm/lithent@1.19.1/tag/dist/lithentTag.umd.js"></script>
205
+ <!--script src="https://cdn.jsdelivr.net/npm/lithent@1.19.1/ftags/dist/lithentFTags.umd.js"></script-->
204
206
 
205
207
  <div id="root"></div>
206
208
 
@@ -232,6 +234,68 @@ const destroy = render(lTag`<${Component} />`, document.getElementById('root'),
232
234
  </script>
233
235
  ```
234
236
 
237
+ ## Context API
238
+
239
+ Lithent-helper ships a lightweight context system so you can share state without manual prop drilling. Providers stay isolated from consumer renews and you can subscribe to every key or only the slices you need.
240
+
241
+ ### Multi-value Provider Example
242
+
243
+ ```tsx
244
+ import { h, mount } from 'lithent';
245
+ import { createContext } from 'lithent-helper';
246
+
247
+ type AppState = { user: string; theme: string; count: number };
248
+
249
+ const AppContext = createContext<AppState>();
250
+ const { Provider, contextState, useContext } = AppContext;
251
+
252
+ const AppProvider = mount((_renew, _props, children) => {
253
+ // Provider owns the shared state; consumers cannot trigger its renew directly.
254
+ const user = contextState('Alice');
255
+ const theme = contextState('dark');
256
+ const count = contextState(0);
257
+
258
+ return () => (
259
+ <Provider user={user} theme={theme} count={count}>
260
+ {children}
261
+ </Provider>
262
+ );
263
+ });
264
+
265
+ const StatsPanel = mount(renew => {
266
+ // Omitting the subscribe list subscribes to every value exposed by the Provider.
267
+ const ctx = useContext(AppContext, renew);
268
+ return () => (
269
+ <section>
270
+ <p>User: {ctx.user?.value}</p>
271
+ <p>Theme: {ctx.theme?.value}</p>
272
+ <p>Count: {ctx.count?.value}</p>
273
+ <button onClick={() => ctx.count && (ctx.count.value += 1)}>
274
+ Increment
275
+ </button>
276
+ <button onClick={() => ctx.count && (ctx.count.value = 3)}>
277
+ Set count to 3
278
+ </button>
279
+ </section>
280
+ );
281
+ });
282
+
283
+ const ThemeBadge = mount(renew => {
284
+ // Subscribe only to the theme key; user/count updates will not rerender this component.
285
+ const ctx = useContext(AppContext, renew, ['theme']);
286
+ return () => <span>Theme: {ctx.theme?.value}</span>;
287
+ });
288
+
289
+ const App = mount(() => {
290
+ return () => (
291
+ <AppProvider>
292
+ <StatsPanel />
293
+ <ThemeBadge />
294
+ </AppProvider>
295
+ );
296
+ });
297
+ ```
298
+
235
299
  ## Related Projects
236
300
  - [htm](https://www.npmjs.com/package/htm) - making **H**yperscript **T**agged **M**arkup possible
237
301
 
@@ -276,4 +340,3 @@ pnpm install
276
340
  pnpm build
277
341
  pnpm test
278
342
  ```
279
-
@@ -1,3 +1,3 @@
1
- import { WDom } from '../types';
1
+ import { WDom } from '../../types';
2
2
  export declare const unmount: (effectAction: () => void) => void;
3
3
  export declare const runUnmountQueueFromWDom: (newWDom: WDom) => void;
@@ -1,3 +1,3 @@
1
- import { WDom } from '../types';
1
+ import { WDom } from '../../types';
2
2
  export declare const useUpdated: (effectAction: () => (() => void) | void, dependencies?: () => any[]) => void;
3
3
  export declare const runUpdatedQueueFromWDom: (newWDom: WDom) => void;
@@ -1,5 +1,13 @@
1
1
  import { WDom } from '../types';
2
- export declare const execMountedQueue: () => void;
2
+ /**
3
+ * WDom을 mountedQueue에 추가
4
+ */
3
5
  export declare const addMountedQueue: (wDom: WDom) => void;
4
- export declare const mountCallback: (effectAction: () => void) => number;
5
- export declare const runMountedQueueFromWDom: (newWDom: WDom) => void;
6
+ /**
7
+ * DOM 렌더링 후 mountCallback 실행
8
+ */
9
+ export declare const execMountedQueue: () => void;
10
+ /**
11
+ * mountCallback 등록
12
+ */
13
+ export declare const mountCallback: (effectAction: () => void) => void;
@@ -0,0 +1,10 @@
1
+ import { WDom } from '../types';
2
+ /**
3
+ * WDom이 생성된 직후(DOM 마운트 전)에 실행될 콜백 등록
4
+ */
5
+ export declare const mountReadyCallback: (effectAction: () => void | (() => void)) => void;
6
+ /**
7
+ * 특정 WDom의 wdomCallback 즉시 실행
8
+ * wDomToDom() 내부에서 각 WDom 생성 시점에 호출됨
9
+ */
10
+ export declare const runWDomCallbacksFromWDom: (newWDom: WDom) => void;
package/dist/index.d.ts CHANGED
@@ -1,12 +1,13 @@
1
- export { h, Fragment, portal, mount } from './wDom';
1
+ export { h, Fragment, portal, mount, replaceWDom } from './wDom';
2
2
  export { isPropType } from './utils';
3
3
  export { componentUpdate } from './utils/redraw';
4
- export { componentMap } from './utils/universalRef';
4
+ export { getComponentKey, componentMap, getComponentSubInfo, } from './utils/universalRef';
5
5
  export { render } from './render';
6
6
  export { mountCallback } from './hook/mountCallback';
7
+ export { mountReadyCallback } from './hook/mountReadyCallback';
7
8
  export { updateCallback } from './hook/updateCallback';
8
9
  export { ref, nextTick } from './hook/ref';
9
- export type { WDom, TagFunction, TagFunctionResolver, FragmentFunction, Component, ComponentSubKey, ComponentMap, Props, Renew, MiddleStateWDomChildren, MiddleStateWDom, NodePointer, Param, } from './types';
10
+ export type { WDom, TagFunction, TagFunctionResolver, FragmentFunction, Component, ComponentSubKey, ComponentMap, ComponentInfo, CompKey, Props, Renew, MiddleStateWDomChildren, MiddleStateWDom, NodePointer, Param, } from './types';
10
11
  declare global {
11
12
  namespace JSX {
12
13
  interface IntrinsicElements {