@davidsouther/jiffies 2.2.4 → 2.3.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/LICENSE +1 -1
- package/lib/cjs/assert.d.ts +2 -2
- package/lib/cjs/awaitable.d.ts +1 -1
- package/lib/cjs/components/button_bar.d.ts +2 -2
- package/lib/cjs/components/inline_edit.d.ts +2 -2
- package/lib/cjs/components/logger.d.ts +1 -1
- package/lib/cjs/components/select.d.ts +4 -7
- package/lib/cjs/components/test.d.ts +1 -1
- package/lib/cjs/components/virtual_scroll.d.ts +6 -4
- package/lib/cjs/context.d.ts +5 -9
- package/lib/cjs/debounce.d.ts +1 -1
- package/lib/cjs/diff.d.ts +2 -2
- package/lib/cjs/display.d.ts +1 -1
- package/lib/cjs/dom/css/border.d.ts +2 -2
- package/lib/cjs/dom/css/constants.d.ts +3 -3
- package/lib/cjs/dom/css/core.d.ts +1 -1
- package/lib/cjs/dom/css/fstyle.d.ts +2 -2
- package/lib/cjs/dom/css/sizing.d.ts +2 -2
- package/lib/cjs/dom/dom.d.ts +8 -8
- package/lib/cjs/dom/fc.d.ts +8 -12
- package/lib/cjs/dom/form/form.d.ts +5 -6
- package/lib/cjs/dom/html.d.ts +112 -113
- package/lib/cjs/dom/observable.d.ts +1 -1
- package/lib/cjs/dom/provide.d.ts +1 -1
- package/lib/cjs/dom/router/router.d.ts +2 -2
- package/lib/cjs/dom/svg.d.ts +64 -64
- package/lib/cjs/dom/types/css.d.ts +10 -32
- package/lib/cjs/dom/types/html.d.ts +4 -6
- package/lib/cjs/equal.d.ts +8 -5
- package/lib/cjs/flags.d.ts +1 -1
- package/lib/cjs/fs.d.ts +3 -3
- package/lib/cjs/fs_node.d.ts +1 -1
- package/lib/cjs/lock.d.ts +1 -1
- package/lib/cjs/log.d.ts +9 -9
- package/lib/cjs/observable/event.d.ts +2 -2
- package/lib/cjs/observable/observable.d.ts +37 -35
- package/lib/cjs/result.d.ts +21 -21
- package/lib/cjs/safe.d.ts +1 -1
- package/lib/cjs/scope/describe.d.ts +4 -4
- package/lib/cjs/scope/display/console.d.ts +1 -1
- package/lib/cjs/scope/display/dom.d.ts +2 -2
- package/lib/cjs/scope/display/junit.d.ts +1 -1
- package/lib/cjs/scope/execute.d.ts +2 -2
- package/lib/cjs/scope/index.d.ts +3 -3
- package/lib/cjs/scope/scope.d.ts +3 -3
- package/lib/cjs/scope/state.d.ts +1 -1
- package/lib/cjs/server/http/apps.d.ts +1 -1
- package/lib/cjs/server/http/css.d.ts +1 -1
- package/lib/cjs/server/http/index.d.ts +4 -9
- package/lib/cjs/server/http/response.d.ts +3 -3
- package/lib/cjs/server/http/sitemap.d.ts +1 -1
- package/lib/cjs/server/http/static.d.ts +1 -1
- package/lib/cjs/server/http/typescript.d.ts +1 -1
- package/lib/cjs/test_all.d.ts +9 -9
- package/lib/cjs/tsconfig.tsbuildinfo +1 -1
- package/lib/esm/assert.d.ts +2 -2
- package/lib/esm/awaitable.d.ts +1 -1
- package/lib/esm/components/button_bar.d.ts +2 -2
- package/lib/esm/components/inline_edit.d.ts +2 -2
- package/lib/esm/components/logger.d.ts +1 -1
- package/lib/esm/components/select.d.ts +3 -3
- package/lib/esm/components/test.d.ts +1 -1
- package/lib/esm/components/virtual_scroll.d.ts +6 -4
- package/lib/esm/context.d.ts +5 -9
- package/lib/esm/debounce.d.ts +1 -2
- package/lib/esm/diff.d.ts +2 -2
- package/lib/esm/display.d.ts +1 -1
- package/lib/esm/dom/css/border.d.ts +2 -2
- package/lib/esm/dom/css/constants.d.ts +3 -3
- package/lib/esm/dom/css/core.d.ts +1 -1
- package/lib/esm/dom/css/fstyle.d.ts +2 -2
- package/lib/esm/dom/css/sizing.d.ts +2 -2
- package/lib/esm/dom/dom.d.ts +8 -8
- package/lib/esm/dom/fc.d.ts +8 -12
- package/lib/esm/dom/form/form.d.ts +5 -6
- package/lib/esm/dom/html.d.ts +112 -113
- package/lib/esm/dom/observable.d.ts +1 -1
- package/lib/esm/dom/provide.d.ts +1 -1
- package/lib/esm/dom/router/router.d.ts +2 -2
- package/lib/esm/dom/svg.d.ts +64 -64
- package/lib/esm/dom/types/css.d.ts +10 -32
- package/lib/esm/dom/types/html.d.ts +4 -6
- package/lib/esm/equal.d.ts +8 -5
- package/lib/esm/flags.d.ts +1 -1
- package/lib/esm/fs.d.ts +3 -3
- package/lib/esm/fs_node.d.ts +1 -1
- package/lib/esm/lock.d.ts +1 -1
- package/lib/esm/log.d.ts +9 -9
- package/lib/esm/observable/event.d.ts +2 -2
- package/lib/esm/observable/observable.d.ts +37 -35
- package/lib/esm/result.d.ts +21 -21
- package/lib/esm/safe.d.ts +1 -1
- package/lib/esm/scope/describe.d.ts +4 -4
- package/lib/esm/scope/display/console.d.ts +1 -1
- package/lib/esm/scope/display/dom.d.ts +2 -2
- package/lib/esm/scope/display/junit.d.ts +1 -1
- package/lib/esm/scope/execute.d.ts +2 -2
- package/lib/esm/scope/index.d.ts +3 -3
- package/lib/esm/scope/scope.d.ts +3 -3
- package/lib/esm/scope/state.d.ts +1 -1
- package/lib/esm/server/http/apps.d.ts +1 -1
- package/lib/esm/server/http/css.d.ts +1 -1
- package/lib/esm/server/http/index.d.ts +4 -9
- package/lib/esm/server/http/response.d.ts +3 -3
- package/lib/esm/server/http/sitemap.d.ts +1 -1
- package/lib/esm/server/http/static.d.ts +1 -1
- package/lib/esm/server/http/typescript.d.ts +1 -1
- package/lib/esm/test_all.d.ts +9 -9
- package/lib/esm/tsconfig.tsbuildinfo +1 -1
- package/package.json +11 -9
- package/src/assert.ts +5 -5
- package/src/components/button_bar.ts +28 -30
- package/src/components/inline_edit.ts +8 -7
- package/src/components/logger.ts +6 -6
- package/src/components/select.ts +7 -7
- package/src/components/test.ts +5 -0
- package/src/components/virtual_scroll.test.ts +9 -6
- package/src/components/virtual_scroll.ts +29 -24
- package/src/context.test.ts +4 -4
- package/src/context.ts +16 -11
- package/src/debounce.ts +9 -3
- package/src/diff.test.ts +4 -4
- package/src/diff.ts +14 -16
- package/src/dom/css/border.ts +11 -11
- package/src/dom/css/core.ts +1 -1
- package/src/dom/css/fstyle.ts +4 -4
- package/src/dom/css/sizing.ts +1 -1
- package/src/dom/dom.ts +57 -47
- package/src/dom/fc.test.ts +8 -8
- package/src/dom/fc.ts +32 -35
- package/src/dom/form/form.app.ts +9 -9
- package/src/dom/form/form.ts +25 -16
- package/src/dom/form/index.html +3 -2
- package/src/dom/html.test.ts +12 -10
- package/src/dom/html.ts +2 -3
- package/src/dom/observable.test.ts +6 -6
- package/src/dom/observable.ts +2 -2
- package/src/dom/provide.ts +1 -1
- package/src/dom/router/link.ts +3 -3
- package/src/dom/router/router.ts +5 -5
- package/src/dom/svg.ts +7 -6
- package/src/dom/test.ts +3 -0
- package/src/dom/types/css.ts +43 -61
- package/src/dom/types/html.ts +2 -4
- package/src/dom/xml.ts +2 -2
- package/src/equal.test.ts +3 -3
- package/src/equal.ts +27 -14
- package/src/flags.test.ts +2 -2
- package/src/flags.ts +2 -2
- package/src/fs.test.ts +5 -5
- package/src/fs.ts +26 -20
- package/src/fs_node.ts +4 -4
- package/src/fs_win.test.ts +1 -1
- package/src/generator.test.ts +4 -3
- package/src/generator.ts +1 -1
- package/src/hooks/_notes +4 -1
- package/src/index.html +7 -7
- package/src/lock.test.ts +4 -4
- package/src/lock.ts +8 -7
- package/src/log.ts +28 -18
- package/src/observable/event.ts +7 -7
- package/src/observable/observable.test.ts +3 -3
- package/src/observable/observable.ts +71 -52
- package/src/result.test.ts +7 -10
- package/src/result.ts +51 -47
- package/src/safe.ts +1 -1
- package/src/scope/describe.ts +12 -11
- package/src/scope/display/console.ts +4 -4
- package/src/scope/display/dom.ts +9 -9
- package/src/scope/display/junit.ts +21 -24
- package/src/scope/execute.ts +17 -12
- package/src/scope/expect.ts +22 -22
- package/src/scope/fix.ts +10 -7
- package/src/scope/index.ts +3 -3
- package/src/scope/scope.ts +2 -2
- package/src/scope/state.ts +2 -2
- package/src/server/http/apps.ts +5 -5
- package/src/server/http/css.ts +10 -26
- package/src/server/http/index.ts +30 -24
- package/src/server/http/response.ts +12 -5
- package/src/server/http/sitemap.ts +8 -8
- package/src/server/http/static.ts +9 -6
- package/src/server/http/typescript.ts +25 -25
- package/src/server/main.ts +7 -4
- package/src/test.mjs +8 -8
- package/src/test_all.ts +16 -13
- package/src/transpile.mjs +6 -18
- package/build/pico.css +0 -2466
- package/build/pico.css.map +0 -1
- package/lib/cjs/assert.js +0 -46
- package/lib/cjs/awaitable.js +0 -2
- package/lib/cjs/case.js +0 -9
- package/lib/cjs/components/button_bar.js +0 -29
- package/lib/cjs/components/inline_edit.js +0 -51
- package/lib/cjs/components/logger.js +0 -27
- package/lib/cjs/components/select.js +0 -6
- package/lib/cjs/components/test.js +0 -7
- package/lib/cjs/components/virtual_scroll.js +0 -102
- package/lib/cjs/components/virtual_scroll.test.js +0 -22
- package/lib/cjs/context.js +0 -48
- package/lib/cjs/context.test.js +0 -48
- package/lib/cjs/debounce.js +0 -12
- package/lib/cjs/diff.js +0 -58
- package/lib/cjs/diff.test.js +0 -41
- package/lib/cjs/display.js +0 -16
- package/lib/cjs/dom/css/border.js +0 -33
- package/lib/cjs/dom/css/constants.js +0 -31
- package/lib/cjs/dom/css/core.js +0 -31
- package/lib/cjs/dom/css/fstyle.js +0 -36
- package/lib/cjs/dom/css/sizing.js +0 -14
- package/lib/cjs/dom/dom.js +0 -110
- package/lib/cjs/dom/fc.js +0 -39
- package/lib/cjs/dom/fc.test.js +0 -23
- package/lib/cjs/dom/form/form.app.js +0 -27
- package/lib/cjs/dom/form/form.js +0 -49
- package/lib/cjs/dom/form/form.test.js +0 -1
- package/lib/cjs/dom/html.js +0 -119
- package/lib/cjs/dom/html.test.js +0 -60
- package/lib/cjs/dom/observable.js +0 -10
- package/lib/cjs/dom/observable.test.js +0 -35
- package/lib/cjs/dom/provide.js +0 -12
- package/lib/cjs/dom/router/link.js +0 -7
- package/lib/cjs/dom/router/router.js +0 -55
- package/lib/cjs/dom/svg.js +0 -69
- package/lib/cjs/dom/test.js +0 -13
- package/lib/cjs/dom/types/css.js +0 -24
- package/lib/cjs/dom/types/dom.js +0 -1
- package/lib/cjs/dom/types/html.js +0 -2
- package/lib/cjs/dom/xml.js +0 -8
- package/lib/cjs/equal.js +0 -48
- package/lib/cjs/equal.test.js +0 -22
- package/lib/cjs/flags.js +0 -52
- package/lib/cjs/flags.test.js +0 -37
- package/lib/cjs/fs.js +0 -235
- package/lib/cjs/fs.test.js +0 -86
- package/lib/cjs/fs_node.js +0 -50
- package/lib/cjs/fs_win.test.js +0 -10
- package/lib/cjs/generator.js +0 -14
- package/lib/cjs/generator.test.js +0 -26
- package/lib/cjs/is_browser.js +0 -4
- package/lib/cjs/loader-register.d.mts +0 -1
- package/lib/cjs/loader-register.d.ts +0 -1
- package/lib/cjs/loader-register.js +0 -4
- package/lib/cjs/loader-register.mjs +0 -4
- package/lib/cjs/loader.d.mts +0 -23
- package/lib/cjs/loader.mjs +0 -41
- package/lib/cjs/lock.js +0 -27
- package/lib/cjs/lock.test.js +0 -18
- package/lib/cjs/log.js +0 -98
- package/lib/cjs/observable/event.js +0 -61
- package/lib/cjs/observable/observable.js +0 -363
- package/lib/cjs/observable/observable.test.js +0 -65
- package/lib/cjs/package.json +0 -1
- package/lib/cjs/range.js +0 -11
- package/lib/cjs/result.js +0 -80
- package/lib/cjs/result.test.js +0 -78
- package/lib/cjs/safe.js +0 -14
- package/lib/cjs/scope/describe.js +0 -73
- package/lib/cjs/scope/display/console.js +0 -25
- package/lib/cjs/scope/display/dom.js +0 -30
- package/lib/cjs/scope/display/junit.js +0 -21
- package/lib/cjs/scope/execute.js +0 -91
- package/lib/cjs/scope/expect.js +0 -110
- package/lib/cjs/scope/fix.js +0 -26
- package/lib/cjs/scope/index.js +0 -15
- package/lib/cjs/scope/scope.js +0 -2
- package/lib/cjs/scope/state.js +0 -12
- package/lib/cjs/server/http/apps.js +0 -27
- package/lib/cjs/server/http/css.js +0 -54
- package/lib/cjs/server/http/index.js +0 -77
- package/lib/cjs/server/http/response.js +0 -45
- package/lib/cjs/server/http/sitemap.js +0 -46
- package/lib/cjs/server/http/static.js +0 -25
- package/lib/cjs/server/http/typescript.js +0 -44
- package/lib/cjs/server/main.js +0 -14
- package/lib/cjs/test.mjs +0 -28
- package/lib/cjs/test_all.js +0 -30
- package/lib/cjs/transpile.mjs +0 -22
- package/lib/esm/assert.js +0 -38
- package/lib/esm/awaitable.js +0 -1
- package/lib/esm/case.js +0 -5
- package/lib/esm/components/button_bar.js +0 -27
- package/lib/esm/components/inline_edit.js +0 -48
- package/lib/esm/components/logger.js +0 -22
- package/lib/esm/components/select.js +0 -3
- package/lib/esm/components/test.js +0 -3
- package/lib/esm/components/virtual_scroll.js +0 -94
- package/lib/esm/components/virtual_scroll.test.js +0 -20
- package/lib/esm/context.js +0 -43
- package/lib/esm/context.test.js +0 -46
- package/lib/esm/debounce.js +0 -8
- package/lib/esm/diff.js +0 -54
- package/lib/esm/diff.test.js +0 -39
- package/lib/esm/display.js +0 -11
- package/lib/esm/dom/css/border.js +0 -27
- package/lib/esm/dom/css/constants.js +0 -28
- package/lib/esm/dom/css/core.js +0 -24
- package/lib/esm/dom/css/fstyle.js +0 -32
- package/lib/esm/dom/css/sizing.js +0 -10
- package/lib/esm/dom/dom.js +0 -104
- package/lib/esm/dom/fc.js +0 -35
- package/lib/esm/dom/fc.test.js +0 -21
- package/lib/esm/dom/form/form.app.js +0 -23
- package/lib/esm/dom/form/form.js +0 -34
- package/lib/esm/dom/form/form.test.js +0 -1
- package/lib/esm/dom/html.js +0 -114
- package/lib/esm/dom/html.test.js +0 -58
- package/lib/esm/dom/observable.js +0 -6
- package/lib/esm/dom/observable.test.js +0 -33
- package/lib/esm/dom/provide.js +0 -7
- package/lib/esm/dom/router/link.js +0 -3
- package/lib/esm/dom/router/router.js +0 -52
- package/lib/esm/dom/svg.js +0 -65
- package/lib/esm/dom/test.js +0 -9
- package/lib/esm/dom/types/css.js +0 -23
- package/lib/esm/dom/types/dom.js +0 -1
- package/lib/esm/dom/types/html.js +0 -1
- package/lib/esm/dom/xml.js +0 -4
- package/lib/esm/equal.js +0 -41
- package/lib/esm/equal.test.js +0 -20
- package/lib/esm/flags.js +0 -48
- package/lib/esm/flags.test.js +0 -35
- package/lib/esm/fs.js +0 -226
- package/lib/esm/fs.test.js +0 -84
- package/lib/esm/fs_node.js +0 -45
- package/lib/esm/fs_win.test.js +0 -8
- package/lib/esm/generator.js +0 -10
- package/lib/esm/generator.test.js +0 -24
- package/lib/esm/is_browser.js +0 -1
- package/lib/esm/loader-register.d.mts +0 -1
- package/lib/esm/loader-register.mjs +0 -2
- package/lib/esm/loader.d.mts +0 -23
- package/lib/esm/loader.mjs +0 -36
- package/lib/esm/lock.js +0 -23
- package/lib/esm/lock.test.js +0 -16
- package/lib/esm/log.js +0 -88
- package/lib/esm/observable/event.js +0 -46
- package/lib/esm/observable/observable.js +0 -343
- package/lib/esm/observable/observable.test.js +0 -63
- package/lib/esm/range.js +0 -7
- package/lib/esm/result.js +0 -65
- package/lib/esm/result.test.js +0 -76
- package/lib/esm/safe.js +0 -10
- package/lib/esm/scope/describe.js +0 -60
- package/lib/esm/scope/display/console.js +0 -21
- package/lib/esm/scope/display/dom.js +0 -26
- package/lib/esm/scope/display/junit.js +0 -17
- package/lib/esm/scope/execute.js +0 -85
- package/lib/esm/scope/expect.js +0 -104
- package/lib/esm/scope/fix.js +0 -22
- package/lib/esm/scope/index.js +0 -3
- package/lib/esm/scope/scope.js +0 -1
- package/lib/esm/scope/state.js +0 -8
- package/lib/esm/server/http/apps.js +0 -23
- package/lib/esm/server/http/css.js +0 -50
- package/lib/esm/server/http/index.js +0 -73
- package/lib/esm/server/http/response.js +0 -40
- package/lib/esm/server/http/sitemap.js +0 -42
- package/lib/esm/server/http/static.js +0 -21
- package/lib/esm/server/http/typescript.js +0 -40
- package/lib/esm/server/main.js +0 -12
- package/lib/esm/test.mjs +0 -26
- package/lib/esm/test_all.js +0 -28
- package/lib/esm/transpile.mjs +0 -18
- package/src/components/test.js +0 -3
- package/src/loader-register.mjs +0 -3
- package/src/loader.mjs +0 -46
|
@@ -1,94 +0,0 @@
|
|
|
1
|
-
import { debounce } from "../debounce.js";
|
|
2
|
-
import { FC, State } from "../dom/fc.js";
|
|
3
|
-
import { div } from "../dom/html.js";
|
|
4
|
-
export function arrayAdapter(data) {
|
|
5
|
-
return (offset, limit) => data.slice(offset, offset + limit);
|
|
6
|
-
}
|
|
7
|
-
export function fillVirtualScrollSettings(settings) {
|
|
8
|
-
const { minIndex = 0, maxIndex = Number.MAX_SAFE_INTEGER, startIndex = 0, itemHeight = 20, count = maxIndex - minIndex + 1, tolerance = count, } = settings;
|
|
9
|
-
return { minIndex, maxIndex, startIndex, itemHeight, count, tolerance };
|
|
10
|
-
}
|
|
11
|
-
export function initialState(settings) {
|
|
12
|
-
// From Denis Hilt, https://blog.logrocket.com/virtual-scrolling-core-principles-and-basic-implementation-in-react/
|
|
13
|
-
const { minIndex, maxIndex, startIndex, itemHeight, count, tolerance } = settings;
|
|
14
|
-
const bufferedItems = count + 2 * tolerance;
|
|
15
|
-
const itemsAbove = Math.max(0, startIndex - tolerance - minIndex);
|
|
16
|
-
const viewportHeight = count * itemHeight;
|
|
17
|
-
const totalHeight = (maxIndex - minIndex + 1) * itemHeight;
|
|
18
|
-
const toleranceHeight = tolerance * itemHeight;
|
|
19
|
-
const bufferHeight = viewportHeight + 2 * toleranceHeight;
|
|
20
|
-
const topPaddingHeight = itemsAbove * itemHeight;
|
|
21
|
-
const bottomPaddingHeight = totalHeight - (topPaddingHeight + bufferHeight);
|
|
22
|
-
return {
|
|
23
|
-
scrollTop: 0,
|
|
24
|
-
settings,
|
|
25
|
-
viewportHeight,
|
|
26
|
-
totalHeight,
|
|
27
|
-
toleranceHeight,
|
|
28
|
-
bufferedItems,
|
|
29
|
-
topPaddingHeight,
|
|
30
|
-
bottomPaddingHeight,
|
|
31
|
-
data: [],
|
|
32
|
-
rows: [],
|
|
33
|
-
};
|
|
34
|
-
}
|
|
35
|
-
export function getData(minIndex, maxIndex, offset, limit, get) {
|
|
36
|
-
const start = Math.max(0, minIndex, offset);
|
|
37
|
-
const end = Math.min(maxIndex, offset + limit - 1);
|
|
38
|
-
const data = get(start, end - start);
|
|
39
|
-
return [...data];
|
|
40
|
-
}
|
|
41
|
-
export function doScroll(scrollTop, state, get) {
|
|
42
|
-
const { totalHeight, toleranceHeight, bufferedItems, settings: { itemHeight, minIndex, maxIndex }, } = state;
|
|
43
|
-
const index = minIndex + Math.floor((scrollTop - toleranceHeight) / itemHeight);
|
|
44
|
-
const data = getData(minIndex, maxIndex, index, bufferedItems, get);
|
|
45
|
-
const topPaddingHeight = Math.max((index - minIndex) * itemHeight, 0);
|
|
46
|
-
const bottomPaddingHeight = Math.max(totalHeight - (topPaddingHeight + data.length * itemHeight), 0);
|
|
47
|
-
return { scrollTop, topPaddingHeight, bottomPaddingHeight, data };
|
|
48
|
-
}
|
|
49
|
-
// export interface VirtualScroll<T, U extends HTMLElement> {
|
|
50
|
-
// state: VirtualScrollState<T>;
|
|
51
|
-
// rows: UHTMLElement<U>[];
|
|
52
|
-
// }
|
|
53
|
-
export const VirtualScroll = FC("virtual-scroll", (element, props) => {
|
|
54
|
-
const settings = fillVirtualScrollSettings(props.settings);
|
|
55
|
-
const state = (element[State] = {
|
|
56
|
-
...initialState(settings),
|
|
57
|
-
...element[State],
|
|
58
|
-
});
|
|
59
|
-
const scrollTo = ({ target } = { target: state }) => {
|
|
60
|
-
const scrollTop = target?.scrollTop ?? state.topPaddingHeight;
|
|
61
|
-
const updatedSate = {
|
|
62
|
-
...state,
|
|
63
|
-
...doScroll(scrollTop, state, props.get),
|
|
64
|
-
};
|
|
65
|
-
setState(updatedSate);
|
|
66
|
-
};
|
|
67
|
-
const viewportElement = div({
|
|
68
|
-
style: { height: `${state.viewportHeight}px`, overflowY: "scroll" },
|
|
69
|
-
events: { scroll: debounce(scrollTo, 0) },
|
|
70
|
-
});
|
|
71
|
-
setTimeout(() => {
|
|
72
|
-
viewportElement.scroll({ top: state.scrollTop });
|
|
73
|
-
});
|
|
74
|
-
const setState = (newState) => {
|
|
75
|
-
state.scrollTop = newState.scrollTop;
|
|
76
|
-
state.topPaddingHeight = newState.topPaddingHeight;
|
|
77
|
-
state.bottomPaddingHeight = newState.bottomPaddingHeight;
|
|
78
|
-
state.data = newState.data;
|
|
79
|
-
state.rows = state.data.map(props.row);
|
|
80
|
-
viewportElement.update(div({
|
|
81
|
-
class: "VirtualScroll__topPadding",
|
|
82
|
-
style: { height: `${state.topPaddingHeight}px` },
|
|
83
|
-
}), ...(state.rows ?? []).map((row, i) => div({
|
|
84
|
-
class: `VirtualScroll__item_${i}`,
|
|
85
|
-
style: { height: `${settings.itemHeight}px` },
|
|
86
|
-
}, row)), div({
|
|
87
|
-
class: "VirtualScroll__bottomPadding",
|
|
88
|
-
style: { height: `${state.bottomPaddingHeight}px` },
|
|
89
|
-
}));
|
|
90
|
-
};
|
|
91
|
-
scrollTo();
|
|
92
|
-
return viewportElement;
|
|
93
|
-
});
|
|
94
|
-
export default VirtualScroll;
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { State } from "../dom/fc.js";
|
|
2
|
-
import { div } from "../dom/html.js";
|
|
3
|
-
import { describe, it, expect } from "../scope/index.js";
|
|
4
|
-
import VirtualScroll, { arrayAdapter, } from "./virtual_scroll.js";
|
|
5
|
-
describe("VirtualScroll", () => {
|
|
6
|
-
it("tracks scroll position", () => {
|
|
7
|
-
const data = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9];
|
|
8
|
-
const props = {
|
|
9
|
-
settings: { count: 3, startIndex: 2 },
|
|
10
|
-
get: arrayAdapter(data),
|
|
11
|
-
row: (i) => div(`${i}`),
|
|
12
|
-
};
|
|
13
|
-
const scroll = VirtualScroll(props);
|
|
14
|
-
expect(scroll[State]?.bufferedItems).toBe(9);
|
|
15
|
-
expect(scroll[State]?.data).toEqual([0, 1, 2, 3, 4]);
|
|
16
|
-
//expect(scroll.state.topPaddingHeight).toBe(0);
|
|
17
|
-
expect(scroll[State]?.viewportHeight).toBe(60);
|
|
18
|
-
//expect(scroll.state.totalHeight).toBe(200);
|
|
19
|
-
});
|
|
20
|
-
});
|
package/lib/esm/context.js
DELETED
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
import { Ok, Err, isResult } from "./result.js";
|
|
2
|
-
export const Enter = Symbol("Context Enter");
|
|
3
|
-
export const Exit = Symbol("Context Exit");
|
|
4
|
-
export function using(context, operation, normalizeError = (e) => Err(e)) {
|
|
5
|
-
if (typeof context === "function") {
|
|
6
|
-
if (context.length === 1) {
|
|
7
|
-
operation = context;
|
|
8
|
-
context = {};
|
|
9
|
-
}
|
|
10
|
-
else {
|
|
11
|
-
context = context();
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
let result;
|
|
15
|
-
try {
|
|
16
|
-
context[Enter]();
|
|
17
|
-
const op = operation(context);
|
|
18
|
-
result = isResult(op) ? op : Ok(op);
|
|
19
|
-
}
|
|
20
|
-
catch (e) {
|
|
21
|
-
result = normalizeError(e);
|
|
22
|
-
}
|
|
23
|
-
finally {
|
|
24
|
-
context[Exit]();
|
|
25
|
-
}
|
|
26
|
-
return result;
|
|
27
|
-
}
|
|
28
|
-
export async function asyncUsing(context, operation, normalizeError = (e) => Err(e)) {
|
|
29
|
-
context = typeof context === "function" ? await context() : context;
|
|
30
|
-
let result;
|
|
31
|
-
try {
|
|
32
|
-
context[Enter]();
|
|
33
|
-
const op = await operation(context);
|
|
34
|
-
result = isResult(op) ? op : Ok(op);
|
|
35
|
-
}
|
|
36
|
-
catch (e) {
|
|
37
|
-
result = normalizeError(e);
|
|
38
|
-
}
|
|
39
|
-
finally {
|
|
40
|
-
context[Exit]();
|
|
41
|
-
}
|
|
42
|
-
return result;
|
|
43
|
-
}
|
package/lib/esm/context.test.js
DELETED
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
import { Enter, Exit, using } from "./context.js";
|
|
2
|
-
import { Err, isErr, isOk, Ok, unwrap } from "./result.js";
|
|
3
|
-
import { describe, it } from "./scope/describe.js";
|
|
4
|
-
import { expect } from "./scope/expect.js";
|
|
5
|
-
describe("Context", () => {
|
|
6
|
-
it("performs an operation using a context", () => {
|
|
7
|
-
const context = TestContext();
|
|
8
|
-
const result = using(context, () => Ok(5));
|
|
9
|
-
expect(unwrap(result)).toBe(5);
|
|
10
|
-
expect(context.initialized).toBe(true);
|
|
11
|
-
expect(context.completed).toBe(true);
|
|
12
|
-
});
|
|
13
|
-
it("reports the result of a thrown error", () => {
|
|
14
|
-
const context = TestContext();
|
|
15
|
-
const result = using(context, () => {
|
|
16
|
-
throw new Error("Failed");
|
|
17
|
-
});
|
|
18
|
-
expect(isErr(result)).toBe(true);
|
|
19
|
-
expect(Err(result)).toMatchObject({
|
|
20
|
-
message: "Failed",
|
|
21
|
-
});
|
|
22
|
-
});
|
|
23
|
-
it("passes the context to the operation", () => {
|
|
24
|
-
const op = using(TestContext, ({ initialized, completed }) => ({
|
|
25
|
-
initialized,
|
|
26
|
-
completed,
|
|
27
|
-
}));
|
|
28
|
-
expect(isOk(op)).toBe(true);
|
|
29
|
-
const { completed, initialized } = unwrap(op);
|
|
30
|
-
expect(initialized).toBe(true);
|
|
31
|
-
expect(completed).toBe(false);
|
|
32
|
-
});
|
|
33
|
-
});
|
|
34
|
-
function TestContext() {
|
|
35
|
-
const context = {
|
|
36
|
-
[Enter]: () => {
|
|
37
|
-
context.initialized = true;
|
|
38
|
-
},
|
|
39
|
-
[Exit]: () => {
|
|
40
|
-
context.completed = true;
|
|
41
|
-
},
|
|
42
|
-
initialized: false,
|
|
43
|
-
completed: false,
|
|
44
|
-
};
|
|
45
|
-
return context;
|
|
46
|
-
}
|
package/lib/esm/debounce.js
DELETED
package/lib/esm/diff.js
DELETED
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
import { range } from "./range.js";
|
|
2
|
-
import { isSome, None, Some } from "./result.js";
|
|
3
|
-
export const DiffA = Symbol("A");
|
|
4
|
-
export const DiffB = Symbol("B");
|
|
5
|
-
function doDiff(va, vb, k) {
|
|
6
|
-
if (Array.isArray(va)) {
|
|
7
|
-
// @ts-ignore
|
|
8
|
-
return diffArray(va, vb, k);
|
|
9
|
-
}
|
|
10
|
-
if (typeof va === "object") {
|
|
11
|
-
const d = diffObject(va, vb, k);
|
|
12
|
-
if (d.children.length === 0) {
|
|
13
|
-
return None();
|
|
14
|
-
}
|
|
15
|
-
else {
|
|
16
|
-
return Some(d);
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
if (Object.is(va, vb)) {
|
|
20
|
-
return None();
|
|
21
|
-
}
|
|
22
|
-
else {
|
|
23
|
-
// @ts-ignore
|
|
24
|
-
return { key: k, left: va, right: vb };
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
function diffArray(a, b, key) {
|
|
28
|
-
const indexes = Math.max(a.length, b.length);
|
|
29
|
-
const children = range(0, indexes)
|
|
30
|
-
.map((i) => doDiff(a[i], b[i], i))
|
|
31
|
-
.filter(isSome);
|
|
32
|
-
return children.length > 0 ? { key, children } : None();
|
|
33
|
-
}
|
|
34
|
-
function diffObject(a, b, key = "") {
|
|
35
|
-
const keys = new Set([...Object.keys(a), ...Object.keys(b)]);
|
|
36
|
-
const children = [...keys]
|
|
37
|
-
// @ts-ignore
|
|
38
|
-
.map((k) => doDiff(a[k], b[k], k))
|
|
39
|
-
.filter(isSome);
|
|
40
|
-
return {
|
|
41
|
-
key,
|
|
42
|
-
children,
|
|
43
|
-
};
|
|
44
|
-
}
|
|
45
|
-
export function diff(a, b) {
|
|
46
|
-
if (typeof a != "object" && !Object.is(a, b)) {
|
|
47
|
-
// @ts-ignore
|
|
48
|
-
return [{ key: "", left: a, right: b }];
|
|
49
|
-
}
|
|
50
|
-
return (Array.isArray(a)
|
|
51
|
-
? // @ts-ignore
|
|
52
|
-
diffArray(a, b, "") ?? { children: [] }
|
|
53
|
-
: diffObject(a, b, "")).children;
|
|
54
|
-
}
|
package/lib/esm/diff.test.js
DELETED
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import { diff } from "./diff.js";
|
|
2
|
-
import { describe, it } from "./scope/describe.js";
|
|
3
|
-
import { expect } from "./scope/expect.js";
|
|
4
|
-
describe("diff", () => {
|
|
5
|
-
it("diffs primitives", () => {
|
|
6
|
-
const diffed = diff(1, 2);
|
|
7
|
-
expect(diffed).toEqual([{ key: "", left: 1, right: 2 }]);
|
|
8
|
-
});
|
|
9
|
-
it("diffs objects", () => {
|
|
10
|
-
const diffed = diff({ a: 1, b: 2 }, { a: 2, b: 2 });
|
|
11
|
-
expect(diffed).toEqual([{ key: "a", left: 1, right: 2 }]);
|
|
12
|
-
});
|
|
13
|
-
it("diffs nested objects", () => {
|
|
14
|
-
const diffed = diff({ a: { c: 1 }, b: 2 }, { a: { c: 2 }, b: 2 });
|
|
15
|
-
expect(diffed).toEqual([
|
|
16
|
-
{ key: "a", children: [{ key: "c", left: 1, right: 2 }] },
|
|
17
|
-
]);
|
|
18
|
-
});
|
|
19
|
-
it("diffs missing sides", () => {
|
|
20
|
-
const diffed = diff({ a: 1 }, { b: 2 });
|
|
21
|
-
expect(diffed).toEqual([
|
|
22
|
-
{ key: "a", left: 1, right: undefined },
|
|
23
|
-
{ key: "b", left: undefined, right: 2 },
|
|
24
|
-
]);
|
|
25
|
-
});
|
|
26
|
-
it("diffs arrays", () => {
|
|
27
|
-
const diffed = diff([1, 2, 3], [1, 4, 3]);
|
|
28
|
-
expect(diffed).toEqual([{ key: 1, left: 2, right: 4 }]);
|
|
29
|
-
});
|
|
30
|
-
it("diffs objects in an array", () => {
|
|
31
|
-
const diffed = diff([{ a: { b: 1 } }, { a: { b: 2 } }, { a: { b: 3 } }], [{ a: { b: 1 } }, { a: { b: 4 } }, { a: { b: 3 } }]);
|
|
32
|
-
expect(diffed).toEqual([
|
|
33
|
-
{
|
|
34
|
-
key: 1,
|
|
35
|
-
children: [{ key: "a", children: [{ key: "b", left: 2, right: 4 }] }],
|
|
36
|
-
},
|
|
37
|
-
]);
|
|
38
|
-
});
|
|
39
|
-
});
|
package/lib/esm/display.js
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
export const isDisplay = (a) => typeof a?.toString === "function" ||
|
|
2
|
-
typeof a === "string";
|
|
3
|
-
export const display = (a) => {
|
|
4
|
-
if (isDisplay(a)) {
|
|
5
|
-
const str = a.toString();
|
|
6
|
-
if (str === "[object Object]")
|
|
7
|
-
return JSON.stringify(a);
|
|
8
|
-
return str;
|
|
9
|
-
}
|
|
10
|
-
return JSON.stringify(a);
|
|
11
|
-
};
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import { isSide, getSize, getSide } from "./core.js";
|
|
2
|
-
export function rounded(size = "", side = "") {
|
|
3
|
-
if (isSide(size)) {
|
|
4
|
-
side = size;
|
|
5
|
-
size = "";
|
|
6
|
-
}
|
|
7
|
-
const sized = getSize(size);
|
|
8
|
-
return getSide(side).reduce((prev, curr) => {
|
|
9
|
-
if (curr === "") {
|
|
10
|
-
prev.borderRadius = sized;
|
|
11
|
-
}
|
|
12
|
-
else {
|
|
13
|
-
// @ts-ignore
|
|
14
|
-
prev[`border${curr}Radius`] = sized;
|
|
15
|
-
}
|
|
16
|
-
return prev;
|
|
17
|
-
}, {});
|
|
18
|
-
}
|
|
19
|
-
export function border({ side = "", style = "solid", radius = "", width = 1, color = "black", }) {
|
|
20
|
-
return {};
|
|
21
|
-
}
|
|
22
|
-
export function inset(width, color1 = "gray", color2 = "lightgray") {
|
|
23
|
-
return {
|
|
24
|
-
...border({ side: "tl", width, color: color1, radius: "none" }),
|
|
25
|
-
...border({ side: "br", width, color: color2, radius: "none" }),
|
|
26
|
-
};
|
|
27
|
-
}
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
export const Sizes = {
|
|
2
|
-
none: "0px",
|
|
3
|
-
sm: "0.125rem",
|
|
4
|
-
"": "0.25rem",
|
|
5
|
-
md: "0.375rem",
|
|
6
|
-
lg: "0.5rem",
|
|
7
|
-
xl: "0.75rem",
|
|
8
|
-
"2xl": "1rem",
|
|
9
|
-
"3xl": "1.5rem",
|
|
10
|
-
full: "9999px",
|
|
11
|
-
};
|
|
12
|
-
export const Sides = {
|
|
13
|
-
"": "",
|
|
14
|
-
t: "Top",
|
|
15
|
-
r: "Right",
|
|
16
|
-
l: "Left",
|
|
17
|
-
b: "Bottom",
|
|
18
|
-
tl: "TopLeft",
|
|
19
|
-
tr: "TopRight",
|
|
20
|
-
bl: "BottomLeft",
|
|
21
|
-
br: "BottomRight",
|
|
22
|
-
};
|
|
23
|
-
export const Widths = {
|
|
24
|
-
"1/4": "25%",
|
|
25
|
-
"1/2": "50%",
|
|
26
|
-
"3/4": "75%",
|
|
27
|
-
full: "100%",
|
|
28
|
-
};
|
package/lib/esm/dom/css/core.js
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import { Sides, Sizes } from "./constants.js";
|
|
2
|
-
export function isSide(v) {
|
|
3
|
-
return Sides[v] !== undefined;
|
|
4
|
-
}
|
|
5
|
-
export function isSize(v) {
|
|
6
|
-
return Sizes[v] !== undefined;
|
|
7
|
-
}
|
|
8
|
-
export function getSize(size) {
|
|
9
|
-
return Sizes[size];
|
|
10
|
-
}
|
|
11
|
-
export function getSide(side) {
|
|
12
|
-
switch (side) {
|
|
13
|
-
case "t":
|
|
14
|
-
return [...getSide("tl"), ...getSide("tr")];
|
|
15
|
-
case "r":
|
|
16
|
-
return [...getSide("tr"), ...getSide("br")];
|
|
17
|
-
case "b":
|
|
18
|
-
return [...getSide("br"), ...getSide("bl")];
|
|
19
|
-
case "l":
|
|
20
|
-
return [...getSide("tl"), ...getSide("bl")];
|
|
21
|
-
default:
|
|
22
|
-
return [Sides[side]];
|
|
23
|
-
}
|
|
24
|
-
}
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import { dashCase } from "../../case.js";
|
|
2
|
-
export function compileFStyle(fstyle, prefix = "") {
|
|
3
|
-
const properties = [];
|
|
4
|
-
const rules = [];
|
|
5
|
-
for (const [key, value] of Object.entries(fstyle)) {
|
|
6
|
-
if (typeof value == "string") {
|
|
7
|
-
properties.push({ key, value });
|
|
8
|
-
}
|
|
9
|
-
else {
|
|
10
|
-
rules.push({ key, value });
|
|
11
|
-
}
|
|
12
|
-
}
|
|
13
|
-
let rule = "";
|
|
14
|
-
if (properties.length > 0) {
|
|
15
|
-
rule += `${prefix} {\n`;
|
|
16
|
-
for (const { key, value } of properties) {
|
|
17
|
-
rule += ` ${dashCase(key)}: ${value};\n`;
|
|
18
|
-
}
|
|
19
|
-
rule += "}\n\n";
|
|
20
|
-
}
|
|
21
|
-
for (const { key, value } of rules) {
|
|
22
|
-
if (key.startsWith("@media")) {
|
|
23
|
-
rule += `${key} {\n`;
|
|
24
|
-
rule += compileFStyle(value, " ");
|
|
25
|
-
rule += `}\n\n`;
|
|
26
|
-
}
|
|
27
|
-
else {
|
|
28
|
-
rule += compileFStyle(value, `${prefix} ${key}`);
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
return rule;
|
|
32
|
-
}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { Widths } from "./constants.js";
|
|
2
|
-
export function width(amount, block) {
|
|
3
|
-
if (amount === undefined && Widths[block] !== undefined) {
|
|
4
|
-
amount = block;
|
|
5
|
-
}
|
|
6
|
-
return {
|
|
7
|
-
...(block === "inline" ? { display: "inline-block" } : {}),
|
|
8
|
-
width: Widths[amount] ?? "0",
|
|
9
|
-
};
|
|
10
|
-
}
|
package/lib/esm/dom/dom.js
DELETED
|
@@ -1,104 +0,0 @@
|
|
|
1
|
-
const Events = Symbol("events");
|
|
2
|
-
export const CLEAR = Symbol("Clear children");
|
|
3
|
-
function isAttrs(attrs) {
|
|
4
|
-
if (!attrs) {
|
|
5
|
-
return false;
|
|
6
|
-
}
|
|
7
|
-
if (typeof attrs === "object") {
|
|
8
|
-
return !attrs.nodeType;
|
|
9
|
-
}
|
|
10
|
-
return false;
|
|
11
|
-
}
|
|
12
|
-
export function normalizeArguments(attrs, children = [], defaultAttrs = {}) {
|
|
13
|
-
let attributes;
|
|
14
|
-
if (isAttrs(attrs)) {
|
|
15
|
-
attributes = attrs;
|
|
16
|
-
}
|
|
17
|
-
else {
|
|
18
|
-
if (attrs !== undefined) {
|
|
19
|
-
children.unshift(attrs);
|
|
20
|
-
}
|
|
21
|
-
attributes = defaultAttrs;
|
|
22
|
-
}
|
|
23
|
-
return [attributes, children.flat()];
|
|
24
|
-
}
|
|
25
|
-
export function up(element, attrs, ...children) {
|
|
26
|
-
return update(element, ...normalizeArguments(attrs, children));
|
|
27
|
-
}
|
|
28
|
-
export function update(element, attrs, children) {
|
|
29
|
-
// Track events, to remove later
|
|
30
|
-
const $events = (element[Events] ??= new Map());
|
|
31
|
-
const { style = {}, events = {}, ...rest } = attrs;
|
|
32
|
-
Object.entries(events).forEach(([k, v]) => {
|
|
33
|
-
if (v === null) {
|
|
34
|
-
if ($events.has(k)) {
|
|
35
|
-
const listener = $events.get(k);
|
|
36
|
-
element.removeEventListener(k, listener);
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
else if (v !== undefined) {
|
|
40
|
-
element.addEventListener(k, v);
|
|
41
|
-
$events.set(k, v);
|
|
42
|
-
}
|
|
43
|
-
});
|
|
44
|
-
const _style = element.style;
|
|
45
|
-
if (_style) {
|
|
46
|
-
if (typeof style === "string") {
|
|
47
|
-
_style.cssText = style;
|
|
48
|
-
}
|
|
49
|
-
else {
|
|
50
|
-
Object.entries(style).forEach(([k, v]) => {
|
|
51
|
-
// @ts-ignore Object.entries is unable to statically look into args
|
|
52
|
-
_style[k] = v;
|
|
53
|
-
});
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
Object.entries(rest).forEach(([k, v]) => {
|
|
57
|
-
if (k === "class") {
|
|
58
|
-
v = Array.isArray(v)
|
|
59
|
-
? v
|
|
60
|
-
: (typeof v === "string" ? v : `${v}`).split(/\s+/m);
|
|
61
|
-
v
|
|
62
|
-
.filter((s) => s !== "")
|
|
63
|
-
.forEach((c) => {
|
|
64
|
-
if (c.startsWith("!")) {
|
|
65
|
-
element.classList.remove(c.substring(1));
|
|
66
|
-
}
|
|
67
|
-
else {
|
|
68
|
-
element.classList.add(c);
|
|
69
|
-
}
|
|
70
|
-
});
|
|
71
|
-
return;
|
|
72
|
-
}
|
|
73
|
-
const useNamespace = element.namespaceURI &&
|
|
74
|
-
element.namespaceURI != "http://www.w3.org/1999/xhtml";
|
|
75
|
-
const remove = !v;
|
|
76
|
-
if (useNamespace) {
|
|
77
|
-
if (remove) {
|
|
78
|
-
element.removeAttributeNS(element.namespaceURI, k);
|
|
79
|
-
}
|
|
80
|
-
else if (v === true) {
|
|
81
|
-
element.setAttributeNS(element.namespaceURI, k, k);
|
|
82
|
-
}
|
|
83
|
-
else {
|
|
84
|
-
element.setAttributeNS(element.namespaceURI, k, v);
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
else {
|
|
88
|
-
if (remove) {
|
|
89
|
-
element.removeAttribute(k);
|
|
90
|
-
}
|
|
91
|
-
else if (v === true) {
|
|
92
|
-
element.setAttribute(k, k);
|
|
93
|
-
}
|
|
94
|
-
else {
|
|
95
|
-
element.setAttribute(k, v);
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
});
|
|
99
|
-
if (children?.length > 0) {
|
|
100
|
-
element.replaceChildren(...(children[0] === CLEAR ? [] : children));
|
|
101
|
-
}
|
|
102
|
-
element.update ??= (attrs, ...children) => update(element, ...normalizeArguments(attrs, children));
|
|
103
|
-
return element;
|
|
104
|
-
}
|
package/lib/esm/dom/fc.js
DELETED
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import { CLEAR, normalizeArguments, update, } from "./dom.js";
|
|
2
|
-
export const State = Symbol();
|
|
3
|
-
export function FC(name, component) {
|
|
4
|
-
class FCImpl extends HTMLElement {
|
|
5
|
-
constructor() {
|
|
6
|
-
super();
|
|
7
|
-
}
|
|
8
|
-
[State] = {};
|
|
9
|
-
#attrs = {};
|
|
10
|
-
#children = [];
|
|
11
|
-
update(attrs, ...children) {
|
|
12
|
-
[attrs, children] = normalizeArguments(attrs, children);
|
|
13
|
-
if (children[0] === CLEAR) {
|
|
14
|
-
this.#children = [];
|
|
15
|
-
}
|
|
16
|
-
else if (children.length > 0) {
|
|
17
|
-
this.#children = children;
|
|
18
|
-
}
|
|
19
|
-
this.#attrs = { ...this.#attrs, ...attrs };
|
|
20
|
-
// Apply updates from the attrs to the dom node itself
|
|
21
|
-
update(this, this.#attrs, []);
|
|
22
|
-
// Re-run the component function using new element, attrs, and children.
|
|
23
|
-
const replace = [component(this, this.#attrs, this.#children)];
|
|
24
|
-
this.replaceChildren(...replace.flat());
|
|
25
|
-
return this;
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
customElements.define(name, FCImpl);
|
|
29
|
-
const ctor = (attrs, ...children) => {
|
|
30
|
-
const element = document.createElement(name);
|
|
31
|
-
element.update(attrs, ...children);
|
|
32
|
-
return element;
|
|
33
|
-
};
|
|
34
|
-
return ctor;
|
|
35
|
-
}
|
package/lib/esm/dom/fc.test.js
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect } from "../scope/index.js";
|
|
2
|
-
import { button, div, form, input, label, small } from "./html.js";
|
|
3
|
-
import { FC } from "./fc.js";
|
|
4
|
-
describe("FC", () => {
|
|
5
|
-
it("creates FCs", () => {
|
|
6
|
-
const Input = FC("fc-input", (el, attrs, children) => label(attrs.placeholder ?? attrs.name, input(attrs), ...children));
|
|
7
|
-
const f = form({ action: "#", method: "POST" }, div({ class: "grid" }, Input({
|
|
8
|
-
name: "firstName",
|
|
9
|
-
placeholder: "First Name",
|
|
10
|
-
required: true,
|
|
11
|
-
}), Input({
|
|
12
|
-
name: "lastName",
|
|
13
|
-
placeholder: "Last Name",
|
|
14
|
-
required: true,
|
|
15
|
-
})), Input({ name: "email", type: "email", placeholder: "E-Mail" }, small("We'll never share your information.")), button({ type: "submit" }, "Submit"));
|
|
16
|
-
// document.body.appendChild(f);
|
|
17
|
-
expect(f.children.length).toBe(3);
|
|
18
|
-
expect(f.querySelectorAll("input[required]").length).toBe(2);
|
|
19
|
-
expect(f.querySelectorAll('input[name="firstName"]').length).toBe(1);
|
|
20
|
-
});
|
|
21
|
-
});
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import { article, button, div, main, small } from "../html.js";
|
|
2
|
-
import { Form, Input } from "./form.js";
|
|
3
|
-
export const App = () => main({ class: "container" }, article(Form({
|
|
4
|
-
events: {
|
|
5
|
-
submit(event) {
|
|
6
|
-
console.log("Should see fields for firstname, lastname, email, etc");
|
|
7
|
-
console.log(event);
|
|
8
|
-
},
|
|
9
|
-
},
|
|
10
|
-
}, div({ class: "grid" }, Input({ id: "firstname", placeholder: "First name" }), Input({ id: "lastname", placeholder: "Last name" })), Input({
|
|
11
|
-
id: "email",
|
|
12
|
-
type: "email",
|
|
13
|
-
placeholder: "Email address",
|
|
14
|
-
required: true,
|
|
15
|
-
}, small("We will never share your email with anyone.")), button({ type: "submit" }, "Submit"), div({ class: "grid" }, Input({ id: "valid", placeholder: "Valid", "aria-invalid": "false" }), Input({
|
|
16
|
-
id: "invalid",
|
|
17
|
-
placeholder: "Invalid",
|
|
18
|
-
"aria-invalid": "true",
|
|
19
|
-
}), Input({ id: "disabled", placeholder: "Disabled", disabled: true }), Input({ id: "readonly", value: "Readonly", readOnly: true }))
|
|
20
|
-
// Dropdown({id: 'fruit', label: "Fruit", placeholder: "Select a fruit...", options: ['Banana', 'Watermelon', 'Apple', 'Orange', 'Mango']}),
|
|
21
|
-
// Radios({legend: 'Size', options: {small: 'Small', medium: 'Medium', large: 'Large', extralarge: "Extra Large"}, checked: 'small'}),
|
|
22
|
-
// Checkboxes({options: {terms: 'I agree to the Terms and Conditions', termsSharing: {label: 'I agree to share my information with partners', disabled: true, checked: true}}),
|
|
23
|
-
)));
|
package/lib/esm/dom/form/form.js
DELETED
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import { form, input, label, option, select } from "../html.js";
|
|
2
|
-
export const Form = (attrs, ...children) => {
|
|
3
|
-
if (attrs.events?.submit) {
|
|
4
|
-
const submit = attrs.events.submit;
|
|
5
|
-
attrs.events.submit = (event) => {
|
|
6
|
-
event.preventDefault();
|
|
7
|
-
submit(event);
|
|
8
|
-
};
|
|
9
|
-
}
|
|
10
|
-
return form(attrs, ...children);
|
|
11
|
-
};
|
|
12
|
-
export const Input = (attrs, ...children) => label(input(attrs), ...children);
|
|
13
|
-
export const Select = (attrs) => label({ style: attrs.style ?? {} }, select({ events: attrs.events ?? {} }, ...prepareOptions(attrs.options, attrs.selected).map(Option)));
|
|
14
|
-
export const Button = () => { };
|
|
15
|
-
const prepareOptions = (attrs, selected) => Array.isArray(attrs)
|
|
16
|
-
? attrs.map((value) => ({
|
|
17
|
-
value,
|
|
18
|
-
label: value,
|
|
19
|
-
selected: selected == value,
|
|
20
|
-
}))
|
|
21
|
-
: Object.entries(attrs).map(([value, label]) => typeof label === "string"
|
|
22
|
-
? { value, label, selected: selected === value }
|
|
23
|
-
: { value, ...label });
|
|
24
|
-
export const Option = (attrs) => option(attrs);
|
|
25
|
-
export const Dropdown = (attrs, ...options) => Select({
|
|
26
|
-
...attrs,
|
|
27
|
-
options: typeof options[0] == "string" ? options : options[0],
|
|
28
|
-
});
|
|
29
|
-
export const Radios = () => { };
|
|
30
|
-
export const Checks = () => { };
|
|
31
|
-
export const Switches = () => { };
|
|
32
|
-
export const Radio = (attrs) => Input({ type: "radio" });
|
|
33
|
-
export const Checkbox = (attrs) => Input({ type: "checkbox" });
|
|
34
|
-
export const Switch = () => Checkbox({ role: "switch" });
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";
|