@davidsouther/jiffies 1.1.0 → 2.0.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/{build → lib/cjs}/assert.d.ts +23 -23
- package/lib/cjs/assert.js +40 -0
- package/{build → lib/cjs}/case.d.ts +1 -1
- package/lib/cjs/case.js +9 -0
- package/{build → lib/cjs}/components/button_bar.d.ts +8 -8
- package/lib/cjs/components/button_bar.js +29 -0
- package/{build → lib/cjs}/components/inline_edit.d.ts +12 -12
- package/lib/cjs/components/inline_edit.js +51 -0
- package/{build → lib/cjs}/components/logger.d.ts +6 -6
- package/lib/cjs/components/logger.js +27 -0
- package/lib/cjs/components/select.d.ts +10 -0
- package/lib/cjs/components/select.js +6 -0
- package/lib/cjs/components/test.d.ts +1 -0
- package/lib/cjs/components/test.js +7 -0
- package/{build → lib/cjs}/components/virtual_scroll.d.ts +40 -40
- package/lib/cjs/components/virtual_scroll.js +102 -0
- package/{build → lib/cjs}/components/virtual_scroll.test.d.ts +1 -1
- package/lib/cjs/components/virtual_scroll.test.js +22 -0
- package/{build → lib/cjs}/context.d.ts +15 -15
- package/lib/cjs/context.js +48 -0
- package/{build → lib/cjs}/context.test.d.ts +1 -1
- package/lib/cjs/context.test.js +48 -0
- package/{build → lib/cjs}/debounce.d.ts +1 -1
- package/lib/cjs/debounce.js +11 -0
- package/lib/cjs/diff.d.ts +15 -0
- package/lib/cjs/diff.js +58 -0
- package/{build/components/test.d.ts → lib/cjs/diff.test.d.ts} +1 -1
- package/lib/cjs/diff.test.js +41 -0
- package/{build → lib/cjs}/display.d.ts +5 -5
- package/lib/cjs/display.js +16 -0
- package/{build → lib/cjs}/dom/css/border.d.ts +11 -11
- package/lib/cjs/dom/css/border.js +33 -0
- package/{build → lib/cjs}/dom/css/constants.d.ts +31 -31
- package/lib/cjs/dom/css/constants.js +31 -0
- package/{build → lib/cjs}/dom/css/core.d.ts +5 -5
- package/lib/cjs/dom/css/core.js +31 -0
- package/{build → lib/cjs}/dom/css/fstyle.d.ts +5 -5
- package/lib/cjs/dom/css/fstyle.js +36 -0
- package/{build → lib/cjs}/dom/css/sizing.d.ts +5 -5
- package/lib/cjs/dom/css/sizing.js +14 -0
- package/{build → lib/cjs}/dom/dom.d.ts +27 -26
- package/lib/cjs/dom/dom.js +110 -0
- package/{build → lib/cjs}/dom/fc.d.ts +14 -14
- package/lib/cjs/dom/fc.js +39 -0
- package/{build → lib/cjs}/dom/fc.test.d.ts +1 -1
- package/lib/cjs/dom/fc.test.js +23 -0
- package/{build → lib/cjs}/dom/form/form.app.d.ts +1 -1
- package/lib/cjs/dom/form/form.app.js +27 -0
- package/{build → lib/cjs}/dom/form/form.d.ts +26 -26
- package/lib/cjs/dom/form/form.js +49 -0
- package/{build → lib/cjs}/dom/form/form.test.d.ts +0 -0
- package/{build → lib/cjs}/dom/form/form.test.js +1 -1
- package/{build → lib/cjs}/dom/html.d.ts +113 -113
- package/lib/cjs/dom/html.js +119 -0
- package/{build → lib/cjs}/dom/html.test.d.ts +1 -1
- package/lib/cjs/dom/html.test.js +60 -0
- package/lib/cjs/dom/observable.d.ts +2 -0
- package/lib/cjs/dom/observable.js +10 -0
- package/{build/observable → lib/cjs/dom}/observable.test.d.ts +1 -1
- package/lib/cjs/dom/observable.test.js +35 -0
- package/{build → lib/cjs}/dom/provide.d.ts +3 -3
- package/lib/cjs/dom/provide.js +12 -0
- package/{build → lib/cjs}/dom/router/link.d.ts +6 -6
- package/lib/cjs/dom/router/link.js +7 -0
- package/{build → lib/cjs}/dom/router/router.d.ts +12 -12
- package/lib/cjs/dom/router/router.js +52 -0
- package/{build → lib/cjs}/dom/svg.d.ts +64 -64
- package/lib/cjs/dom/svg.js +69 -0
- package/lib/cjs/dom/test.d.ts +1 -0
- package/lib/cjs/dom/test.js +13 -0
- package/{build → lib/cjs}/dom/types/css.d.ts +6612 -6612
- package/lib/cjs/dom/types/css.js +24 -0
- package/{build → lib/cjs}/dom/types/dom.d.ts +0 -0
- package/{build → lib/cjs}/dom/types/dom.js +1 -1
- package/{build → lib/cjs}/dom/types/html.d.ts +616 -616
- package/lib/cjs/dom/types/html.js +2 -0
- package/{build → lib/cjs}/dom/xml.d.ts +1 -1
- package/lib/cjs/dom/xml.js +8 -0
- package/{build → lib/cjs}/equal.d.ts +5 -5
- package/lib/cjs/equal.js +43 -0
- package/{build → lib/cjs}/equal.test.d.ts +1 -1
- package/lib/cjs/equal.test.js +22 -0
- package/{build → lib/cjs}/flags.d.ts +7 -7
- package/lib/cjs/flags.js +52 -0
- package/{build → lib/cjs}/flags.test.d.ts +1 -1
- package/lib/cjs/flags.test.js +37 -0
- package/{build → lib/cjs}/fs.d.ts +48 -48
- package/lib/cjs/fs.js +151 -0
- package/{build → lib/cjs}/fs.test.d.ts +1 -1
- package/lib/cjs/fs.test.js +45 -0
- package/{build → lib/cjs}/generator.d.ts +1 -1
- package/lib/cjs/generator.js +14 -0
- package/{build → lib/cjs}/generator.test.d.ts +1 -1
- package/lib/cjs/generator.test.js +26 -0
- package/{build → lib/cjs}/is_browser.d.ts +1 -1
- package/lib/cjs/is_browser.js +4 -0
- package/{build → lib/cjs}/loader.d.mts +22 -22
- package/lib/cjs/loader.mjs +40 -0
- package/{build → lib/cjs}/lock.d.ts +1 -1
- package/lib/cjs/lock.js +27 -0
- package/{build → lib/cjs}/lock.test.d.ts +1 -1
- package/lib/cjs/lock.test.js +18 -0
- package/{build → lib/cjs}/log.d.ts +26 -26
- package/lib/cjs/log.js +54 -0
- package/lib/cjs/observable/event.d.ts +35 -0
- package/lib/cjs/observable/event.js +61 -0
- package/lib/cjs/observable/observable.d.ts +132 -0
- package/lib/cjs/observable/observable.js +363 -0
- package/lib/cjs/observable/observable.test.d.ts +1 -0
- package/lib/cjs/observable/observable.test.js +65 -0
- package/{build → lib/cjs}/range.d.ts +1 -1
- package/lib/cjs/range.js +11 -0
- package/{build → lib/cjs}/result.d.ts +31 -31
- package/lib/cjs/result.js +80 -0
- package/{build → lib/cjs}/result.test.d.ts +1 -1
- package/lib/cjs/result.test.js +73 -0
- package/{build → lib/cjs}/safe.d.ts +1 -1
- package/lib/cjs/safe.js +14 -0
- package/{build → lib/cjs}/scope/describe.d.ts +18 -18
- package/lib/cjs/scope/describe.js +73 -0
- package/{build → lib/cjs}/scope/display/console.d.ts +2 -2
- package/lib/cjs/scope/display/console.js +25 -0
- package/{build → lib/cjs}/scope/display/dom.d.ts +3 -3
- package/lib/cjs/scope/display/dom.js +30 -0
- package/{build → lib/cjs}/scope/display/junit.d.ts +2 -2
- package/lib/cjs/scope/display/junit.js +21 -0
- package/{build → lib/cjs}/scope/execute.d.ts +12 -12
- package/lib/cjs/scope/execute.js +91 -0
- package/{build → lib/cjs}/scope/expect.d.ts +23 -23
- package/lib/cjs/scope/expect.js +114 -0
- package/{build → lib/cjs}/scope/fix.d.ts +4 -4
- package/lib/cjs/scope/fix.js +26 -0
- package/{build → lib/cjs}/scope/index.d.ts +3 -3
- package/lib/cjs/scope/index.js +15 -0
- package/{build → lib/cjs}/scope/scope.d.ts +17 -17
- package/lib/cjs/scope/scope.js +2 -0
- package/lib/cjs/scope/state.d.ts +1 -0
- package/lib/cjs/scope/state.js +11 -0
- package/{build → lib/cjs}/server/http/apps.d.ts +5 -5
- package/lib/cjs/server/http/apps.js +27 -0
- package/{build → lib/cjs}/server/http/css.d.ts +5 -5
- package/lib/cjs/server/http/css.js +54 -0
- package/{build → lib/cjs}/server/http/index.d.ts +21 -21
- package/lib/cjs/server/http/index.js +77 -0
- package/{build → lib/cjs}/server/http/response.d.ts +4 -4
- package/lib/cjs/server/http/response.js +45 -0
- package/{build → lib/cjs}/server/http/sitemap.d.ts +2 -2
- package/lib/cjs/server/http/sitemap.js +46 -0
- package/{build → lib/cjs}/server/http/static.d.ts +2 -2
- package/lib/cjs/server/http/static.js +25 -0
- package/{build → lib/cjs}/server/http/typescript.d.ts +5 -5
- package/lib/cjs/server/http/typescript.js +44 -0
- package/{build → lib/cjs}/server/main.d.ts +2 -2
- package/lib/cjs/server/main.js +14 -0
- package/{build → lib/cjs}/test.d.mts +2 -2
- package/lib/cjs/test.mjs +28 -0
- package/{build → lib/cjs}/test_all.d.ts +9 -7
- package/lib/cjs/test_all.js +30 -0
- package/{build → lib/cjs}/transpile.d.mts +3 -3
- package/lib/cjs/transpile.mjs +22 -0
- package/lib/cjs/tsconfig.tsbuildinfo +1 -0
- package/lib/esm/assert.d.ts +23 -0
- package/{build → lib/esm}/assert.js +33 -33
- package/lib/esm/case.d.ts +1 -0
- package/{build → lib/esm}/case.js +5 -5
- package/lib/esm/components/button_bar.d.ts +8 -0
- package/{build → lib/esm}/components/button_bar.js +27 -27
- package/lib/esm/components/inline_edit.d.ts +12 -0
- package/{build → lib/esm}/components/inline_edit.js +48 -48
- package/lib/esm/components/logger.d.ts +6 -0
- package/{build → lib/esm}/components/logger.js +22 -22
- package/lib/esm/components/select.d.ts +10 -0
- package/{build → lib/esm}/components/select.js +3 -3
- package/lib/esm/components/test.d.ts +1 -0
- package/lib/esm/components/test.js +3 -0
- package/lib/esm/components/virtual_scroll.d.ts +40 -0
- package/{build → lib/esm}/components/virtual_scroll.js +94 -94
- package/lib/esm/components/virtual_scroll.test.d.ts +1 -0
- package/{build → lib/esm}/components/virtual_scroll.test.js +20 -21
- package/lib/esm/context.d.ts +15 -0
- package/{build → lib/esm}/context.js +43 -43
- package/lib/esm/context.test.d.ts +1 -0
- package/{build → lib/esm}/context.test.js +46 -46
- package/lib/esm/debounce.d.ts +1 -0
- package/{build → lib/esm}/debounce.js +7 -7
- package/lib/esm/diff.d.ts +15 -0
- package/lib/esm/diff.js +54 -0
- package/lib/esm/diff.test.d.ts +1 -0
- package/lib/esm/diff.test.js +39 -0
- package/lib/esm/display.d.ts +5 -0
- package/{build → lib/esm}/display.js +11 -11
- package/lib/esm/dom/css/border.d.ts +11 -0
- package/{build → lib/esm}/dom/css/border.js +27 -27
- package/lib/esm/dom/css/constants.d.ts +31 -0
- package/{build → lib/esm}/dom/css/constants.js +28 -28
- package/lib/esm/dom/css/core.d.ts +5 -0
- package/{build → lib/esm}/dom/css/core.js +24 -24
- package/lib/esm/dom/css/fstyle.d.ts +5 -0
- package/{build → lib/esm}/dom/css/fstyle.js +32 -32
- package/lib/esm/dom/css/sizing.d.ts +5 -0
- package/{build → lib/esm}/dom/css/sizing.js +10 -10
- package/lib/esm/dom/dom.d.ts +27 -0
- package/{build → lib/esm}/dom/dom.js +104 -95
- package/lib/esm/dom/fc.d.ts +14 -0
- package/{build → lib/esm}/dom/fc.js +35 -36
- package/lib/esm/dom/fc.test.d.ts +1 -0
- package/{build → lib/esm}/dom/fc.test.js +21 -21
- package/lib/esm/dom/form/form.app.d.ts +1 -0
- package/{build → lib/esm}/dom/form/form.app.js +23 -23
- package/lib/esm/dom/form/form.d.ts +26 -0
- package/{build → lib/esm}/dom/form/form.js +34 -34
- package/lib/esm/dom/form/form.test.d.ts +0 -0
- package/lib/esm/dom/form/form.test.js +1 -0
- package/lib/esm/dom/html.d.ts +113 -0
- package/{build → lib/esm}/dom/html.js +114 -114
- package/lib/esm/dom/html.test.d.ts +1 -0
- package/{build → lib/esm}/dom/html.test.js +58 -58
- package/lib/esm/dom/observable.d.ts +2 -0
- package/lib/esm/dom/observable.js +6 -0
- package/lib/esm/dom/observable.test.d.ts +1 -0
- package/lib/esm/dom/observable.test.js +33 -0
- package/lib/esm/dom/provide.d.ts +3 -0
- package/{build → lib/esm}/dom/provide.js +7 -7
- package/lib/esm/dom/router/link.d.ts +6 -0
- package/{build → lib/esm}/dom/router/link.js +3 -3
- package/lib/esm/dom/router/router.d.ts +12 -0
- package/{build → lib/esm}/dom/router/router.js +49 -49
- package/lib/esm/dom/svg.d.ts +64 -0
- package/{build → lib/esm}/dom/svg.js +65 -65
- package/lib/esm/dom/test.d.ts +1 -0
- package/lib/esm/dom/test.js +9 -0
- package/lib/esm/dom/types/css.d.ts +6612 -0
- package/{build → lib/esm}/dom/types/css.js +23 -23
- package/lib/esm/dom/types/dom.d.ts +0 -0
- package/lib/esm/dom/types/dom.js +1 -0
- package/lib/esm/dom/types/html.d.ts +616 -0
- package/{build → lib/esm}/dom/types/html.js +1 -1
- package/lib/esm/dom/xml.d.ts +1 -0
- package/{build → lib/esm}/dom/xml.js +4 -4
- package/lib/esm/equal.d.ts +5 -0
- package/{build → lib/esm}/equal.js +37 -37
- package/lib/esm/equal.test.d.ts +1 -0
- package/{build → lib/esm}/equal.test.js +20 -20
- package/lib/esm/flags.d.ts +7 -0
- package/{build → lib/esm}/flags.js +48 -48
- package/lib/esm/flags.test.d.ts +1 -0
- package/{build → lib/esm}/flags.test.js +35 -35
- package/lib/esm/fs.d.ts +48 -0
- package/{build → lib/esm}/fs.js +144 -144
- package/lib/esm/fs.test.d.ts +1 -0
- package/{build → lib/esm}/fs.test.js +43 -43
- package/lib/esm/generator.d.ts +1 -0
- package/{build → lib/esm}/generator.js +10 -10
- package/lib/esm/generator.test.d.ts +1 -0
- package/{build → lib/esm}/generator.test.js +24 -24
- package/lib/esm/is_browser.d.ts +1 -0
- package/{build → lib/esm}/is_browser.js +1 -1
- package/lib/esm/loader.d.mts +22 -0
- package/{build → lib/esm}/loader.mjs +35 -35
- package/lib/esm/lock.d.ts +1 -0
- package/{build → lib/esm}/lock.js +23 -23
- package/lib/esm/lock.test.d.ts +1 -0
- package/{build → lib/esm}/lock.test.js +16 -16
- package/lib/esm/log.d.ts +26 -0
- package/{build → lib/esm}/log.js +46 -46
- package/lib/esm/observable/event.d.ts +35 -0
- package/lib/esm/observable/event.js +46 -0
- package/lib/esm/observable/observable.d.ts +132 -0
- package/lib/esm/observable/observable.js +343 -0
- package/lib/esm/observable/observable.test.d.ts +1 -0
- package/lib/esm/observable/observable.test.js +63 -0
- package/lib/esm/range.d.ts +1 -0
- package/{build → lib/esm}/range.js +7 -7
- package/lib/esm/result.d.ts +31 -0
- package/{build → lib/esm}/result.js +65 -65
- package/lib/esm/result.test.d.ts +1 -0
- package/{build → lib/esm}/result.test.js +71 -71
- package/lib/esm/safe.d.ts +1 -0
- package/{build → lib/esm}/safe.js +10 -10
- package/lib/esm/scope/describe.d.ts +18 -0
- package/{build → lib/esm}/scope/describe.js +60 -61
- package/lib/esm/scope/display/console.d.ts +2 -0
- package/{build → lib/esm}/scope/display/console.js +21 -21
- package/lib/esm/scope/display/dom.d.ts +3 -0
- package/{build → lib/esm}/scope/display/dom.js +26 -26
- package/lib/esm/scope/display/junit.d.ts +2 -0
- package/{build → lib/esm}/scope/display/junit.js +17 -17
- package/lib/esm/scope/execute.d.ts +12 -0
- package/{build → lib/esm}/scope/execute.js +85 -85
- package/lib/esm/scope/expect.d.ts +23 -0
- package/{build → lib/esm}/scope/expect.js +108 -108
- package/lib/esm/scope/fix.d.ts +4 -0
- package/{build → lib/esm}/scope/fix.js +22 -22
- package/lib/esm/scope/index.d.ts +3 -0
- package/{build → lib/esm}/scope/index.js +3 -3
- package/lib/esm/scope/scope.d.ts +17 -0
- package/{build → lib/esm}/scope/scope.js +1 -1
- package/lib/esm/scope/state.d.ts +1 -0
- package/lib/esm/scope/state.js +7 -0
- package/lib/esm/server/http/apps.d.ts +5 -0
- package/{build → lib/esm}/server/http/apps.js +23 -23
- package/lib/esm/server/http/css.d.ts +5 -0
- package/{build → lib/esm}/server/http/css.js +50 -50
- package/lib/esm/server/http/index.d.ts +21 -0
- package/{build → lib/esm}/server/http/index.js +73 -73
- package/lib/esm/server/http/response.d.ts +4 -0
- package/{build → lib/esm}/server/http/response.js +40 -40
- package/lib/esm/server/http/sitemap.d.ts +2 -0
- package/{build → lib/esm}/server/http/sitemap.js +42 -42
- package/lib/esm/server/http/static.d.ts +2 -0
- package/{build → lib/esm}/server/http/static.js +21 -21
- package/lib/esm/server/http/typescript.d.ts +5 -0
- package/{build → lib/esm}/server/http/typescript.js +40 -40
- package/lib/esm/server/main.d.ts +2 -0
- package/{build → lib/esm}/server/main.js +12 -9
- package/lib/esm/test.d.mts +2 -0
- package/lib/esm/test.mjs +26 -0
- package/lib/esm/test_all.d.ts +9 -0
- package/{build → lib/esm}/test_all.js +28 -18
- package/lib/esm/transpile.d.mts +3 -0
- package/{build → lib/esm}/transpile.mjs +18 -18
- package/lib/esm/tsconfig.tsbuildinfo +1 -0
- package/package.json +13 -14
- package/src/assert.ts +1 -1
- package/src/components/button_bar.ts +3 -3
- package/src/components/inline_edit.ts +3 -3
- package/src/components/logger.ts +3 -3
- package/src/components/select.ts +3 -3
- package/src/components/test.js +3 -2
- package/src/context.ts +3 -3
- package/src/diff.ts +2 -2
- package/src/dom/css/border.ts +3 -3
- package/src/dom/css/core.ts +1 -1
- package/src/dom/css/fstyle.ts +2 -2
- package/src/dom/css/sizing.ts +1 -1
- package/src/dom/dom.ts +1 -1
- package/src/dom/fc.test.ts +3 -3
- package/src/dom/fc.ts +1 -1
- package/src/dom/form/form.app.ts +2 -2
- package/src/dom/form/form.ts +3 -3
- package/src/dom/html.test.ts +3 -3
- package/src/dom/html.ts +1 -1
- package/src/dom/observable.test.ts +6 -6
- package/src/dom/observable.ts +1 -1
- package/src/dom/provide.ts +1 -1
- package/src/dom/router/link.ts +2 -2
- package/src/dom/router/router.ts +2 -2
- package/src/dom/svg.ts +1 -1
- package/src/dom/test.ts +8 -6
- package/src/dom/types/html.ts +1 -1
- package/src/equal.ts +1 -1
- package/src/flags.ts +1 -1
- package/src/fs.ts +4 -4
- package/src/index.html +6 -6
- package/src/observable/event.ts +2 -2
- package/src/observable/observable.test.ts +2 -2
- package/src/observable/observable.ts +72 -12
- package/src/pico/_variables.scss +1 -1
- package/src/pico/layout/_sectioning.scss +2 -0
- package/src/result.ts +1 -1
- package/src/scope/describe.ts +2 -5
- package/src/scope/display/console.ts +4 -4
- package/src/scope/display/dom.ts +6 -6
- package/src/scope/display/junit.ts +3 -3
- package/src/scope/execute.ts +2 -2
- package/src/scope/expect.ts +3 -3
- package/src/scope/state.ts +10 -0
- package/src/server/http/sitemap.ts +1 -1
- package/src/server/main.ts +9 -2
- package/src/test.mjs +22 -18
- package/src/test_all.ts +10 -0
- package/build/components/select.d.ts +0 -13
- package/build/components/test.js +0 -2
- package/build/dom/test.d.ts +0 -1
- package/build/dom/test.js +0 -2
- package/build/observable/observable.d.ts +0 -83
- package/build/observable/observable.js +0 -148
- package/build/observable/observable.test.js +0 -21
- package/build/test.mjs +0 -23
|
@@ -1,10 +1,10 @@
|
|
|
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
|
-
}
|
|
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
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { Properties } from "./types/css.js";
|
|
2
|
+
declare const Events: unique symbol;
|
|
3
|
+
export declare const CLEAR: unique symbol;
|
|
4
|
+
export declare type EventHandler = EventListenerOrEventListenerObject;
|
|
5
|
+
export declare type DenormChildren = Node | string | typeof CLEAR;
|
|
6
|
+
export declare type DOMElement = Element & DocumentAndElementEventHandlers & ElementCSSInlineStyle;
|
|
7
|
+
export declare type DomAttrs = {
|
|
8
|
+
class: string | string[];
|
|
9
|
+
style: Partial<Properties> | string;
|
|
10
|
+
role: "button" | "list" | "listbox";
|
|
11
|
+
events: Partial<{
|
|
12
|
+
[K in keyof HTMLElementEventMap]: EventHandler | null;
|
|
13
|
+
}>;
|
|
14
|
+
};
|
|
15
|
+
export declare type Attrs<E extends Omit<Element, "update">, S = {}> = Partial<Omit<E, "style"> & S & DomAttrs>;
|
|
16
|
+
export declare type DenormAttrs<E extends Omit<Element, "update">, S = {}> = Attrs<E, S> | DenormChildren;
|
|
17
|
+
declare global {
|
|
18
|
+
interface Element {
|
|
19
|
+
[Events]: Map<string, EventHandler>;
|
|
20
|
+
update(attrs?: DenormAttrs<Element>, ...children: DenormChildren[]): this;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
export declare type DOMUpdates<E extends Element = Element> = [DenormAttrs<E>, ...DenormChildren[]] | DenormChildren[];
|
|
24
|
+
export declare function normalizeArguments<E extends Element>(attrs?: DenormAttrs<E>, children?: DenormChildren[], defaultAttrs?: Attrs<E>): [Attrs<E>, DenormChildren[]];
|
|
25
|
+
export declare function up<E extends Element>(element: Omit<E, "update">, attrs?: DenormAttrs<E>, ...children: DenormChildren[]): E;
|
|
26
|
+
export declare function update(element: Omit<Element, "update">, attrs: Attrs<Element>, children: DenormChildren[]): Element;
|
|
27
|
+
export {};
|
|
@@ -1,95 +1,104 @@
|
|
|
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 === "
|
|
8
|
-
return
|
|
9
|
-
}
|
|
10
|
-
return
|
|
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
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
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
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { DenormChildren, DomAttrs } from "./dom.js";
|
|
2
|
+
export declare type Attrs<S> = S & Partial<DomAttrs>;
|
|
3
|
+
export declare const State: unique symbol;
|
|
4
|
+
export interface FCComponent<P extends object, S extends object> extends Element {
|
|
5
|
+
[State]?: Partial<S>;
|
|
6
|
+
update(attrs?: Partial<Attrs<P> & DomAttrs> | DenormChildren, ...children: DenormChildren[]): this;
|
|
7
|
+
}
|
|
8
|
+
export interface RenderFn<P extends object, S extends object> {
|
|
9
|
+
(el: FCComponent<P, S>, attrs: Attrs<P>, children: DenormChildren[]): Element | Element[];
|
|
10
|
+
}
|
|
11
|
+
export interface FCComponentCtor<P extends object, S extends object> {
|
|
12
|
+
(attrs?: Attrs<P> | DenormChildren, ...children: DenormChildren[]): FCComponent<P, S>;
|
|
13
|
+
}
|
|
14
|
+
export declare function FC<P extends object, S extends object = {}>(name: string, component: RenderFn<P, S>): FCComponentCtor<P, S>;
|
|
@@ -1,36 +1,35 @@
|
|
|
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
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
this
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
element
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
}
|
|
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
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
import { describe, it, expect } from "../scope/index.js";
|
|
2
|
-
import { FC } from "./fc.js";
|
|
3
|
-
import { button, div, form, input, label, small } from "./html.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
|
+
import { describe, it, expect } from "../scope/index.js";
|
|
2
|
+
import { FC } from "./fc.js";
|
|
3
|
+
import { button, div, form, input, label, small } from "./html.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
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const App: () => HTMLElement;
|
|
@@ -1,23 +1,23 @@
|
|
|
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
|
-
)));
|
|
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
|
+
)));
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { DenormChildren } from "../dom.js";
|
|
2
|
+
import { label } from "../html.js";
|
|
3
|
+
import { FormAttributes, InputAttributes, LabelAttributes, OptionAttributes, SelectAttributes } from "../types/html";
|
|
4
|
+
export declare const Form: (attrs: FormAttributes, ...children: DenormChildren[]) => HTMLFormElement;
|
|
5
|
+
export declare const Input: (attrs: InputAttributes, ...children: DenormChildren[]) => HTMLLabelElement;
|
|
6
|
+
export declare const Select: (attrs: {
|
|
7
|
+
options: string[] | {};
|
|
8
|
+
selected?: string;
|
|
9
|
+
} & SelectAttributes & LabelAttributes) => HTMLLabelElement;
|
|
10
|
+
export declare const Button: () => void;
|
|
11
|
+
declare const prepareOptions: (attrs: string[] | Record<string, string | {
|
|
12
|
+
label: string;
|
|
13
|
+
disabled?: boolean | undefined;
|
|
14
|
+
selected?: boolean | undefined;
|
|
15
|
+
}>, selected?: string) => Parameters<typeof Option>[0][];
|
|
16
|
+
export declare const Option: (attrs: OptionAttributes) => HTMLOptionElement;
|
|
17
|
+
export declare const Dropdown: (attrs: SelectAttributes | {
|
|
18
|
+
selected?: string;
|
|
19
|
+
}, ...options: Parameters<typeof prepareOptions>[0][]) => HTMLLabelElement;
|
|
20
|
+
export declare const Radios: () => void;
|
|
21
|
+
export declare const Checks: () => void;
|
|
22
|
+
export declare const Switches: () => void;
|
|
23
|
+
export declare const Radio: (attrs: Omit<InputAttributes, "type">) => HTMLLabelElement;
|
|
24
|
+
export declare const Checkbox: (attrs: Omit<InputAttributes, "type">) => HTMLLabelElement;
|
|
25
|
+
export declare const Switch: () => HTMLLabelElement;
|
|
26
|
+
export {};
|
|
@@ -1,34 +1,34 @@
|
|
|
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
|
+
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" });
|
|
File without changes
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";
|