amateras 0.6.0 → 0.7.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.
- package/index.ts +1 -0
- package/package.json +31 -30
- package/packages/core/package.json +32 -0
- package/packages/core/src/env.browser.ts +21 -0
- package/packages/core/src/env.node.ts +21 -0
- package/packages/core/src/global.ts +18 -0
- package/{src/core.ts → packages/core/src/index.ts} +42 -30
- package/{src → packages/core/src}/lib/assignProperties.ts +1 -1
- package/packages/core/src/lib/chain.ts +17 -0
- package/packages/core/src/lib/dom.ts +20 -0
- package/packages/core/src/main.ts +4 -0
- package/{src → packages/core/src}/node/$Element.ts +22 -10
- package/{src → packages/core/src}/node/$EventTarget.ts +13 -10
- package/{src → packages/core/src}/node/$HTMLElement.ts +1 -1
- package/{src → packages/core/src}/node/$Node.ts +7 -11
- package/{src → packages/core/src}/node/$Virtual.ts +5 -5
- package/packages/css/package.json +17 -0
- package/{ext/css/src/lib → packages/css/src/ext}/colors/amber.ts +2 -2
- package/{ext/css/src/lib → packages/css/src/ext}/colors/blackwhite.ts +2 -2
- package/{ext/css/src/lib → packages/css/src/ext}/colors/blue.ts +2 -2
- package/{ext/css/src/lib → packages/css/src/ext}/colors/cyan.ts +2 -2
- package/{ext/css/src/lib → packages/css/src/ext}/colors/emerald.ts +2 -2
- package/{ext/css/src/lib → packages/css/src/ext}/colors/fuchsia.ts +2 -2
- package/{ext/css/src/lib → packages/css/src/ext}/colors/gray.ts +2 -2
- package/{ext/css/src/lib → packages/css/src/ext}/colors/green.ts +2 -2
- package/{ext/css/src/lib → packages/css/src/ext}/colors/indigo.ts +2 -2
- package/{ext/css/src/lib → packages/css/src/ext}/colors/lime.ts +2 -2
- package/{ext/css/src/lib → packages/css/src/ext}/colors/neutral.ts +2 -2
- package/{ext/css/src/lib → packages/css/src/ext}/colors/orange.ts +2 -2
- package/{ext/css/src/lib → packages/css/src/ext}/colors/pink.ts +2 -2
- package/{ext/css/src/lib → packages/css/src/ext}/colors/purple.ts +2 -2
- package/{ext/css/src/lib → packages/css/src/ext}/colors/red.ts +2 -2
- package/{ext/css/src/lib → packages/css/src/ext}/colors/rose.ts +2 -2
- package/{ext/css/src/lib → packages/css/src/ext}/colors/sky.ts +2 -2
- package/{ext/css/src/lib → packages/css/src/ext}/colors/slate.ts +2 -2
- package/{ext/css/src/lib → packages/css/src/ext}/colors/stone.ts +2 -2
- package/{ext/css/src/lib → packages/css/src/ext}/colors/teal.ts +2 -2
- package/{ext/css/src/lib → packages/css/src/ext}/colors/violet.ts +2 -2
- package/{ext/css/src/lib → packages/css/src/ext}/colors/yellow.ts +2 -2
- package/{ext/css/src/lib → packages/css/src/ext}/colors/zinc.ts +2 -2
- package/packages/css/src/ext/container.ts +32 -0
- package/packages/css/src/ext/keyframes.ts +54 -0
- package/packages/css/src/ext/media.ts +32 -0
- package/packages/css/src/ext/property.ts +48 -0
- package/packages/css/src/ext/variable.ts +51 -0
- package/{ext → packages}/css/src/index.ts +107 -183
- package/{ext → packages}/css/src/lib/colorAssign.ts +1 -1
- package/packages/css/src/lib/utils.ts +11 -0
- package/{ext → packages}/css/src/structure/$CSSContainerRule.ts +1 -1
- package/{ext → packages}/css/src/structure/$CSSKeyframesRule.ts +0 -1
- package/{ext → packages}/css/src/structure/$CSSMediaRule.ts +1 -1
- package/packages/css/src/structure/$CSSProperty.ts +19 -0
- package/{ext → packages}/css/src/structure/$CSSRule.ts +1 -1
- package/{ext → packages}/css/src/structure/$CSSStyleRule.ts +1 -1
- package/packages/css/src/structure/$CSSVariable.ts +30 -0
- package/packages/dom/package.json +20 -0
- package/packages/dom/src/lib/HTMLElementMap.ts +213 -0
- package/packages/dom/src/lib/assignAttributes.ts +16 -0
- package/packages/dom/src/structure/CSS.ts +7 -0
- package/packages/dom/src/structure/CSSStyleSheet.ts +10 -0
- package/packages/dom/src/structure/DOMTokenList.ts +19 -0
- package/packages/dom/src/structure/Document.ts +36 -0
- package/packages/dom/src/structure/Element.ts +106 -0
- package/packages/dom/src/structure/HTMLElement.ts +34 -0
- package/packages/dom/src/structure/History.ts +11 -0
- package/packages/dom/src/structure/Location.ts +9 -0
- package/packages/dom/src/structure/Node.ts +51 -0
- package/packages/dom/src/structure/NodeList.ts +10 -0
- package/packages/dom/src/structure/Storage.ts +8 -0
- package/packages/dom/src/structure/Text.ts +20 -0
- package/packages/dom/src/structure/Window.ts +14 -0
- package/packages/dom/src/structure/html/HTMLAbbrElement.ts +16 -0
- package/packages/dom/src/structure/html/HTMLAddressElement.ts +16 -0
- package/packages/dom/src/structure/html/HTMLAnchorElement.ts +25 -0
- package/packages/dom/src/structure/html/HTMLAreaElement.ts +26 -0
- package/packages/dom/src/structure/html/HTMLArticleElement.ts +16 -0
- package/packages/dom/src/structure/html/HTMLAsideElement.ts +16 -0
- package/packages/dom/src/structure/html/HTMLAudioElement.ts +16 -0
- package/packages/dom/src/structure/html/HTMLBDIElement.ts +16 -0
- package/packages/dom/src/structure/html/HTMLBDOElement.ts +16 -0
- package/packages/dom/src/structure/html/HTMLBElement.ts +16 -0
- package/packages/dom/src/structure/html/HTMLBRElement.ts +17 -0
- package/packages/dom/src/structure/html/HTMLBaseElement.ts +18 -0
- package/packages/dom/src/structure/html/HTMLBodyElement.ts +22 -0
- package/packages/dom/src/structure/html/HTMLButtonElement.ts +26 -0
- package/packages/dom/src/structure/html/HTMLCanvasElement.ts +18 -0
- package/packages/dom/src/structure/html/HTMLCiteElement.ts +16 -0
- package/packages/dom/src/structure/html/HTMLCodeElement.ts +16 -0
- package/packages/dom/src/structure/html/HTMLDDElement.ts +16 -0
- package/packages/dom/src/structure/html/HTMLDFNElement.ts +16 -0
- package/packages/dom/src/structure/html/HTMLDListElement.ts +17 -0
- package/packages/dom/src/structure/html/HTMLDTElement.ts +16 -0
- package/packages/dom/src/structure/html/HTMLDataElement.ts +17 -0
- package/packages/dom/src/structure/html/HTMLDataListElement.ts +16 -0
- package/packages/dom/src/structure/html/HTMLDetailsElement.ts +17 -0
- package/packages/dom/src/structure/html/HTMLDialogElement.ts +18 -0
- package/packages/dom/src/structure/html/HTMLDivElement.ts +17 -0
- package/packages/dom/src/structure/html/HTMLEMElement.ts +16 -0
- package/packages/dom/src/structure/html/HTMLEmbedElement.ts +20 -0
- package/packages/dom/src/structure/html/HTMLFieldSetElement.ts +19 -0
- package/packages/dom/src/structure/html/HTMLFigCaptionElement.ts +16 -0
- package/packages/dom/src/structure/html/HTMLFigureElement.ts +16 -0
- package/packages/dom/src/structure/html/HTMLFooterElement.ts +16 -0
- package/packages/dom/src/structure/html/HTMLFormElement.ts +24 -0
- package/packages/dom/src/structure/html/HTMLHGroupElement.ts +16 -0
- package/packages/dom/src/structure/html/HTMLHRElement.ts +21 -0
- package/packages/dom/src/structure/html/HTMLHeadElement.ts +16 -0
- package/packages/dom/src/structure/html/HTMLHeaderElement.ts +16 -0
- package/packages/dom/src/structure/html/HTMLHeadingElement.ts +17 -0
- package/packages/dom/src/structure/html/HTMLHtmlElement.ts +18 -0
- package/packages/dom/src/structure/html/HTMLIElement.ts +16 -0
- package/packages/dom/src/structure/html/HTMLIFrameElement.ts +31 -0
- package/packages/dom/src/structure/html/HTMLImageElement.ts +38 -0
- package/packages/dom/src/structure/html/HTMLInputElement.ts +55 -0
- package/packages/dom/src/structure/html/HTMLKBDElement.ts +16 -0
- package/packages/dom/src/structure/html/HTMLLIElement.ts +18 -0
- package/packages/dom/src/structure/html/HTMLLabelElement.ts +18 -0
- package/packages/dom/src/structure/html/HTMLLegendElement.ts +17 -0
- package/packages/dom/src/structure/html/HTMLLinkElement.ts +31 -0
- package/packages/dom/src/structure/html/HTMLMainElement.ts +16 -0
- package/packages/dom/src/structure/html/HTMLMapElement.ts +17 -0
- package/packages/dom/src/structure/html/HTMLMarkElement.ts +16 -0
- package/packages/dom/src/structure/html/HTMLMediaElement.ts +48 -0
- package/packages/dom/src/structure/html/HTMLMenuElement.ts +18 -0
- package/packages/dom/src/structure/html/HTMLMetaElement.ts +22 -0
- package/packages/dom/src/structure/html/HTMLMeterElement.ts +23 -0
- package/packages/dom/src/structure/html/HTMLModElement.ts +18 -0
- package/packages/dom/src/structure/html/HTMLNavElement.ts +16 -0
- package/packages/dom/src/structure/html/HTMLNoscriptElement.ts +16 -0
- package/packages/dom/src/structure/html/HTMLOListElement.ts +20 -0
- package/packages/dom/src/structure/html/HTMLObjectElement.ts +34 -0
- package/packages/dom/src/structure/html/HTMLOptGroupElement.ts +18 -0
- package/packages/dom/src/structure/html/HTMLOptionElement.ts +20 -0
- package/packages/dom/src/structure/html/HTMLOutputElement.ts +20 -0
- package/packages/dom/src/structure/html/HTMLParagraphElement.ts +17 -0
- package/packages/dom/src/structure/html/HTMLPictureElement.ts +16 -0
- package/packages/dom/src/structure/html/HTMLPreElement.ts +17 -0
- package/packages/dom/src/structure/html/HTMLProgressElement.ts +19 -0
- package/packages/dom/src/structure/html/HTMLQuoteElement.ts +17 -0
- package/packages/dom/src/structure/html/HTMLRPElement.ts +16 -0
- package/packages/dom/src/structure/html/HTMLRTElement.ts +16 -0
- package/packages/dom/src/structure/html/HTMLRubyElement.ts +16 -0
- package/packages/dom/src/structure/html/HTMLSElement.ts +16 -0
- package/packages/dom/src/structure/html/HTMLSampElement.ts +16 -0
- package/packages/dom/src/structure/html/HTMLScriptElement.ts +27 -0
- package/packages/dom/src/structure/html/HTMLSectionElement.ts +16 -0
- package/packages/dom/src/structure/html/HTMLSelectElement.ts +27 -0
- package/packages/dom/src/structure/html/HTMLSlotElement.ts +17 -0
- package/packages/dom/src/structure/html/HTMLSmallElement.ts +16 -0
- package/packages/dom/src/structure/html/HTMLSourceElement.ts +21 -0
- package/packages/dom/src/structure/html/HTMLSpanElement.ts +16 -0
- package/packages/dom/src/structure/html/HTMLStrongElement.ts +16 -0
- package/packages/dom/src/structure/html/HTMLStyleElement.ts +18 -0
- package/packages/dom/src/structure/html/HTMLSubElement.ts +16 -0
- package/packages/dom/src/structure/html/HTMLSummaryElement.ts +16 -0
- package/packages/dom/src/structure/html/HTMLSupElement.ts +16 -0
- package/packages/dom/src/structure/html/HTMLTableCaptionElement.ts +17 -0
- package/packages/dom/src/structure/html/HTMLTableCellElement.ts +31 -0
- package/packages/dom/src/structure/html/HTMLTableColElement.ts +23 -0
- package/packages/dom/src/structure/html/HTMLTableElement.ts +26 -0
- package/packages/dom/src/structure/html/HTMLTableRowElement.ts +23 -0
- package/packages/dom/src/structure/html/HTMLTableSectionElement.ts +20 -0
- package/packages/dom/src/structure/html/HTMLTemplateElement.ts +17 -0
- package/packages/dom/src/structure/html/HTMLTextAreaElement.ts +33 -0
- package/packages/dom/src/structure/html/HTMLTimeElement.ts +17 -0
- package/packages/dom/src/structure/html/HTMLTitleElement.ts +17 -0
- package/packages/dom/src/structure/html/HTMLTrackElement.ts +21 -0
- package/packages/dom/src/structure/html/HTMLUElement.ts +16 -0
- package/packages/dom/src/structure/html/HTMLUListElement.ts +18 -0
- package/packages/dom/src/structure/html/HTMLVarElement.ts +16 -0
- package/packages/dom/src/structure/html/HTMLVideoElement.ts +22 -0
- package/packages/dom/src/structure/html/HTMLWBRElement.ts +16 -0
- package/packages/html/package.json +18 -0
- package/{ext/html/html.ts → packages/html/src/index.ts} +1 -1
- package/{ext/html → packages/html/src}/node/$Anchor.ts +3 -3
- package/packages/html/src/node/$Canvas.ts +38 -0
- package/{ext/html → packages/html/src}/node/$Dialog.ts +3 -3
- package/{ext/html → packages/html/src}/node/$Form.ts +3 -3
- package/{ext/html → packages/html/src}/node/$Image.ts +3 -3
- package/{ext/html → packages/html/src}/node/$Input.ts +3 -3
- package/{ext/html → packages/html/src}/node/$Label.ts +3 -3
- package/{ext/html → packages/html/src}/node/$Media.ts +3 -3
- package/{ext/html → packages/html/src}/node/$OptGroup.ts +3 -3
- package/{ext/html → packages/html/src}/node/$Option.ts +3 -3
- package/{ext/html → packages/html/src}/node/$Select.ts +3 -3
- package/{ext/html → packages/html/src}/node/$TextArea.ts +3 -3
- package/packages/i18n/package.json +19 -0
- package/{ext → packages}/i18n/src/index.ts +6 -14
- package/{ext → packages}/i18n/src/structure/I18n.ts +2 -2
- package/{ext → packages}/i18n/src/structure/I18nDictionary.ts +1 -1
- package/{ext → packages}/i18n/src/structure/I18nTranslation.ts +10 -4
- package/packages/idb/package.json +19 -0
- package/{ext → packages}/idb/src/index.ts +2 -2
- package/{ext → packages}/idb/src/lib/$IDBRequest.ts +1 -1
- package/{ext → packages}/idb/src/structure/$IDB.ts +1 -1
- package/{ext → packages}/idb/src/structure/$IDBCursor.ts +1 -1
- package/{ext → packages}/idb/src/structure/$IDBIndex.ts +1 -1
- package/{ext → packages}/idb/src/structure/$IDBStore.ts +1 -1
- package/{ext → packages}/idb/src/structure/$IDBStoreBase.ts +1 -1
- package/{ext → packages}/idb/src/structure/$IDBTransaction.ts +1 -1
- package/{ext → packages}/idb/src/structure/builder/$IDBBuilder.ts +1 -2
- package/{ext → packages}/idb/src/structure/builder/$IDBStoreBuilder.ts +1 -1
- package/packages/markdown/package.json +19 -0
- package/{ext → packages}/markdown/src/lib/util.ts +1 -1
- package/{ext → packages}/markdown/src/structure/MarkdownLexer.ts +2 -2
- package/{ext → packages}/markdown/src/structure/MarkdownParser.ts +2 -1
- package/{ext → packages}/markdown/src/syntax/alert.ts +1 -1
- package/{ext → packages}/markdown/src/syntax/codeblock.ts +1 -1
- package/{ext → packages}/markdown/src/syntax/link.ts +2 -2
- package/{ext → packages}/markdown/src/syntax/list.ts +1 -1
- package/{ext → packages}/markdown/src/syntax/table.ts +1 -1
- package/packages/router/package.json +19 -0
- package/{ext → packages}/router/src/index.ts +4 -5
- package/{ext → packages}/router/src/node/Page.ts +8 -4
- package/{ext → packages}/router/src/node/Router.ts +79 -58
- package/{ext → packages}/router/src/node/RouterAnchor.ts +2 -2
- package/{ext → packages}/router/src/structure/PageBuilder.ts +3 -3
- package/{ext → packages}/router/src/structure/Route.ts +1 -1
- package/packages/signal/package.json +18 -0
- package/packages/signal/src/index.ts +221 -0
- package/{ext → packages}/signal/src/structure/Signal.ts +1 -1
- package/{ext → packages}/ui/lib/VirtualScroll.ts +5 -5
- package/{ext → packages}/ui/node/Accordian.ts +4 -4
- package/packages/ui/node/Carousel.ts +20 -0
- package/{ext → packages}/ui/node/Form.ts +7 -6
- package/packages/ui/node/Modal.ts +45 -0
- package/{ext → packages}/ui/node/Table.ts +1 -1
- package/{ext → packages}/ui/node/Tabs.ts +28 -13
- package/{ext → packages}/ui/node/Toast.ts +2 -2
- package/packages/ui/node/Waterfall.ts +94 -0
- package/packages/ui/package.json +21 -0
- package/packages/utils/package.json +17 -0
- package/{src → packages/utils/src}/global.ts +5 -18
- package/{src/lib/native.ts → packages/utils/src/index.ts} +34 -1
- package/tsconfig.json +1 -1
- package/ext/css/package.json +0 -9
- package/ext/css/src/structure/$CSSVariable.ts +0 -12
- package/ext/html/node/$Canvas.ts +0 -16
- package/ext/i18n/package.json +0 -10
- package/ext/idb/package.json +0 -13
- package/ext/markdown/package.json +0 -15
- package/ext/router/package.json +0 -10
- package/ext/signal/package.json +0 -9
- package/ext/signal/src/index.ts +0 -128
- package/ext/ssr/env.ts +0 -61
- package/ext/ssr/index.ts +0 -49
- package/ext/ssr/package.json +0 -10
- package/ext/ui/node/Waterfall.ts +0 -72
- package/ext/ui/package.json +0 -11
- package/src/index.ts +0 -2
- package/src/lib/chain.ts +0 -13
- package/src/lib/debounce.ts +0 -7
- package/src/lib/env.ts +0 -2
- package/src/lib/randomId.ts +0 -9
- package/src/lib/sleep.ts +0 -3
- package/src/lib/toArray.ts +0 -9
- package/src/lib/trycatch.ts +0 -17
- package/src/lib/uppercase.ts +0 -3
- /package/{src/node.ts → packages/core/src/lib/assignNodeProperties.ts} +0 -0
- /package/{ext → packages}/css/README.md +0 -0
- /package/{ext/css/src/lib → packages/css/src/ext}/colors.ts +0 -0
- /package/{ext → packages}/css/src/structure/$CSSDeclaration.ts +0 -0
- /package/{ext → packages}/i18n/README.md +0 -0
- /package/{ext → packages}/idb/README.md +0 -0
- /package/{ext → packages}/idb/src/core.ts +0 -0
- /package/{ext → packages}/markdown/README.md +0 -0
- /package/{ext → packages}/markdown/src/index.ts +0 -0
- /package/{ext → packages}/markdown/src/lib/type.ts +0 -0
- /package/{ext → packages}/markdown/src/structure/Markdown.ts +0 -0
- /package/{ext → packages}/markdown/src/syntax/blockquote.ts +0 -0
- /package/{ext → packages}/markdown/src/syntax/bold.ts +0 -0
- /package/{ext → packages}/markdown/src/syntax/code.ts +0 -0
- /package/{ext → packages}/markdown/src/syntax/heading.ts +0 -0
- /package/{ext → packages}/markdown/src/syntax/horizontalRule.ts +0 -0
- /package/{ext → packages}/markdown/src/syntax/image.ts +0 -0
- /package/{ext → packages}/markdown/src/syntax/italic.ts +0 -0
- /package/{ext → packages}/markdown/src/syntax/text.ts +0 -0
- /package/{ext → packages}/router/README.md +0 -0
- /package/{ext → packages}/signal/README.md +0 -0
- /package/{ext → packages}/ui/node/Grid.ts +0 -0
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@amateras/router",
|
|
3
|
+
"peerDependencies": {
|
|
4
|
+
"@amateras/core": "workspace:*",
|
|
5
|
+
"@amateras/html": "workspace:*",
|
|
6
|
+
"@amateras/utils": "workspace:*"
|
|
7
|
+
},
|
|
8
|
+
"imports": {
|
|
9
|
+
"#structure/*": "./src/structure/*.ts",
|
|
10
|
+
"#lib/*": "./src/lib/*.ts",
|
|
11
|
+
"#node/*": "./src/node/*.ts"
|
|
12
|
+
},
|
|
13
|
+
"exports": {
|
|
14
|
+
".": "./src/index.ts",
|
|
15
|
+
"./structure/*": "./src/structure/*.ts",
|
|
16
|
+
"./lib/*": "./src/lib/*.ts",
|
|
17
|
+
"./node/*": "./src/node/*.ts"
|
|
18
|
+
}
|
|
19
|
+
}
|
|
@@ -2,13 +2,12 @@ import type { Page } from "#node/Page";
|
|
|
2
2
|
import { Router } from "#node/Router";
|
|
3
3
|
import { PageBuilder } from "#structure/PageBuilder";
|
|
4
4
|
import { Route, type RouteBuilder, type RouteParams } from "#structure/Route";
|
|
5
|
-
import {
|
|
6
|
-
import type { AnchorTarget } from "../../html/node/$Anchor";
|
|
5
|
+
import { _Object_assign, _bind, forEach } from "@amateras/utils";
|
|
6
|
+
import type { AnchorTarget } from "../../html/src/node/$Anchor";
|
|
7
7
|
|
|
8
|
-
declare module 'amateras/core' {
|
|
9
|
-
// export function $(nodeName: 'ra'): RouterAnchor;
|
|
8
|
+
declare module '@amateras/core' {
|
|
10
9
|
export namespace $ {
|
|
11
|
-
export function route<Params extends RouteParams = []>(builder: (page: Page<Params>) => Page<Params
|
|
10
|
+
export function route<Params extends RouteParams = []>(builder: (page: Page<Params>) => OrPromise<Page<Params>>): PageBuilder<Params>;
|
|
12
11
|
export function open(url: string | URL | Nullish, target?: AnchorTarget): typeof Router;
|
|
13
12
|
export function replace(url: string | URL | Nullish): typeof Router;
|
|
14
13
|
export function back(): typeof Router;
|
|
@@ -1,17 +1,20 @@
|
|
|
1
1
|
import type { RouteParams } from "#structure/Route";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
2
|
+
import { chain } from "@amateras/core/lib/chain";
|
|
3
|
+
import { $HTMLElement } from "@amateras/core/node/$HTMLElement";
|
|
4
|
+
import { _null } from "@amateras/utils";
|
|
4
5
|
import type { Router } from "./Router";
|
|
5
|
-
|
|
6
|
+
|
|
6
7
|
|
|
7
8
|
export class Page<Params extends RouteParams = []> extends $HTMLElement {
|
|
8
9
|
params: PageParamsResolver<Params>;
|
|
9
10
|
router: null | Router = _null
|
|
10
11
|
#pageTitle: string | null = _null;
|
|
11
12
|
built = false;
|
|
12
|
-
|
|
13
|
+
pathId: string;
|
|
14
|
+
constructor(pathId: string, params: PageParamsResolver<Params>) {
|
|
13
15
|
super('page');
|
|
14
16
|
this.params = params;
|
|
17
|
+
this.pathId = pathId;
|
|
15
18
|
}
|
|
16
19
|
|
|
17
20
|
pageTitle(): string | null;
|
|
@@ -19,6 +22,7 @@ export class Page<Params extends RouteParams = []> extends $HTMLElement {
|
|
|
19
22
|
pageTitle(title?: string | null) {
|
|
20
23
|
return chain(this, arguments, () => this.#pageTitle, title, title => this.#pageTitle = title)
|
|
21
24
|
}
|
|
25
|
+
|
|
22
26
|
}
|
|
23
27
|
|
|
24
28
|
export type PageParams = { [key: string]: string }
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { $HTMLElement } from "amateras/node/$HTMLElement";
|
|
2
1
|
import { Route, type RouteBuilder, type RoutePath, type RouteParamsResolver, type RouteParams, type RouteParamsStrings, type AsyncPageBuilder } from "../structure/Route";
|
|
3
|
-
import {
|
|
4
|
-
import { _instanceof, startsWith, _JSON_parse, forEach, _Object_entries, _JSON_stringify, _Object_assign, isFunction, _null } from "../../../../src/lib/native";
|
|
5
|
-
import type { AnchorTarget } from "../../../html/node/$Anchor";
|
|
2
|
+
import type { AnchorTarget } from "../../../html/src/node/$Anchor";
|
|
6
3
|
import { Page, type PageParams } from "./Page";
|
|
7
4
|
import type { PageBuilder, PageBuilderFunction } from "#structure/PageBuilder";
|
|
5
|
+
import { _document } from "@amateras/core/env";
|
|
6
|
+
import { $HTMLElement } from "@amateras/core/node/$HTMLElement";
|
|
7
|
+
import { _instanceof, startsWith, _JSON_parse, forEach, _Object_entries, _JSON_stringify, isFunction } from "@amateras/utils";
|
|
8
8
|
// history index
|
|
9
9
|
let index = 0;
|
|
10
10
|
const _addEventListener = addEventListener;
|
|
@@ -38,15 +38,20 @@ const historyHandler = async (path: string | URL | Nullish, mode: 1 | 2, target?
|
|
|
38
38
|
scrollRecord();
|
|
39
39
|
if (mode === PUSH) index += 1;
|
|
40
40
|
Router.direction = FORWARD;
|
|
41
|
+
Router.prevUrl = toURL(_location.href);
|
|
41
42
|
_history[mode === PUSH ? 'pushState' : 'replaceState']({index}, '' , url);
|
|
43
|
+
Router.url = url;
|
|
42
44
|
forEach(Router.routers, router => router.resolve(path))
|
|
43
45
|
}
|
|
44
46
|
// disable browser scroll restoration
|
|
45
47
|
_history.scrollRestoration = 'manual';
|
|
46
48
|
|
|
49
|
+
type RouteData = { route: Route, params: PageParams, pathId: string }
|
|
47
50
|
export class Router extends $HTMLElement {
|
|
48
51
|
static direction: 'back' | 'forward' = FORWARD;
|
|
49
52
|
static routers = new Set<Router>();
|
|
53
|
+
static url: URL = toURL(_location.href);
|
|
54
|
+
static prevUrl: URL | null = null;
|
|
50
55
|
routes = new Map<RoutePath, Route>();
|
|
51
56
|
pages = new Map<string, Page>();
|
|
52
57
|
constructor(page?: Page) {
|
|
@@ -85,6 +90,8 @@ export class Router extends $HTMLElement {
|
|
|
85
90
|
if (index > stateIndex) Router.direction = BACK;
|
|
86
91
|
if (index < stateIndex) Router.direction = FORWARD;
|
|
87
92
|
index = stateIndex;
|
|
93
|
+
Router.prevUrl = Router.url;
|
|
94
|
+
Router.url = toURL(_location.href);
|
|
88
95
|
this.resolve(_location.href);
|
|
89
96
|
}
|
|
90
97
|
_addEventListener('popstate', resolve);
|
|
@@ -94,73 +101,37 @@ export class Router extends $HTMLElement {
|
|
|
94
101
|
return this;
|
|
95
102
|
}
|
|
96
103
|
|
|
97
|
-
async resolve(path: string | URL): Promise<this> {
|
|
104
|
+
async resolve(path: string | URL, force = false): Promise<this> {
|
|
98
105
|
const {pathname, href} = toURL(path);
|
|
99
|
-
const
|
|
100
|
-
|
|
101
|
-
const searchRoute = (routes: typeof this.routes, targetPath: string): RouteData[] => {
|
|
102
|
-
let targetPathSplit = split(targetPath);
|
|
103
|
-
if (!routes.size) return [];
|
|
104
|
-
// check each route
|
|
105
|
-
for (const [_, route] of routes) {
|
|
106
|
-
// check each path pass
|
|
107
|
-
routePathLoop: for (const [path, paramsHandle] of route.paths) {
|
|
108
|
-
let routePathSplit = split(path);
|
|
109
|
-
let targetPathNodePosition = 0;
|
|
110
|
-
let params: { [key: string]: string } = isFunction(paramsHandle) ? paramsHandle() : paramsHandle ?? {};
|
|
111
|
-
let pathId = '';
|
|
112
|
-
// check each path node
|
|
113
|
-
pathNodeLoop: for (let i = 0; i < routePathSplit.length; i++) {
|
|
114
|
-
// reset target path node position
|
|
115
|
-
targetPathNodePosition = i;
|
|
116
|
-
const routeNode = routePathSplit[i];
|
|
117
|
-
const targetNode = targetPathSplit[i];
|
|
118
|
-
// path node undefined, break path loop
|
|
119
|
-
if (!routeNode || !targetNode) continue routePathLoop;
|
|
120
|
-
// path node is params node
|
|
121
|
-
if (routeNode.includes(':')) {
|
|
122
|
-
// target not matched
|
|
123
|
-
if (targetNode === '/') continue routePathLoop;
|
|
124
|
-
const [prefix, paramName] = routeNode.split(':') as [string, string];
|
|
125
|
-
if (!startsWith(targetNode, prefix)) continue routePathLoop;
|
|
126
|
-
params[paramName] = targetNode.replace(`${prefix}`, '');
|
|
127
|
-
pathId += targetNode;
|
|
128
|
-
continue pathNodeLoop;
|
|
129
|
-
}
|
|
130
|
-
// path node not matched, next path
|
|
131
|
-
if (routeNode !== targetNode) continue routePathLoop;
|
|
132
|
-
pathId += targetNode;
|
|
133
|
-
}
|
|
134
|
-
// target path node longer than route, next route
|
|
135
|
-
if (targetPathSplit[targetPathNodePosition + 1] && !route.routes.size) continue routePathLoop;
|
|
136
|
-
// all path node passed, route found
|
|
137
|
-
return [{route, params, pathId}, ...searchRoute(route.routes, targetPathSplit.slice(targetPathNodePosition + 1).join('/'))]
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
// no route passed
|
|
141
|
-
const notfound = routes.get('notfound');
|
|
142
|
-
if (notfound) return [{route: notfound, params: {}, pathId: 'notfound'}]
|
|
143
|
-
return [];
|
|
144
|
-
}
|
|
145
|
-
const routes = searchRoute(this.routes, pathname);
|
|
106
|
+
const routes = this.getRoutes(this.routes, pathname);
|
|
107
|
+
const routerPageMap = new Map<Router, Page>();
|
|
146
108
|
let prevRouter: Router | null = this;
|
|
109
|
+
let pathIdStr = '';
|
|
110
|
+
let paramsData = {}
|
|
147
111
|
await forEach(routes, async ({route, params, pathId}) => {
|
|
112
|
+
pathIdStr += pathId;
|
|
113
|
+
paramsData = {...paramsData, ...params}
|
|
148
114
|
// skip route group
|
|
149
115
|
const builderResolver = route.builder;
|
|
150
116
|
if (!builderResolver) return;
|
|
151
117
|
// get page from cache or create new page
|
|
152
|
-
const page = route.pages.get(pathId) ?? new Page(
|
|
118
|
+
const page = route.pages.get(pathId) ?? new Page(pathIdStr, paramsData);
|
|
153
119
|
// resolve builder
|
|
154
120
|
if (!page.built) await builderResolver.build(page);
|
|
155
121
|
page.built = true;
|
|
156
|
-
// set
|
|
157
|
-
|
|
158
|
-
// check location is still same, page parent is not router before insert page
|
|
159
|
-
if (href === _location.href && page.parentNode !== prevRouter?.node) prevRouter?.content(page);
|
|
122
|
+
// set router to page map
|
|
123
|
+
if (prevRouter) routerPageMap.set(prevRouter, page)
|
|
160
124
|
// set cache
|
|
161
|
-
route.pages.set(pathId, page);
|
|
125
|
+
if (!force) route.pages.set(pathId, page);
|
|
162
126
|
prevRouter = page.router;
|
|
163
127
|
})
|
|
128
|
+
|
|
129
|
+
forEach(routerPageMap, ([router, page]) => {
|
|
130
|
+
// set title
|
|
131
|
+
_document && (_document.title = page.pageTitle() ?? _document.title ?? '');
|
|
132
|
+
// check location is still same, page parent is not router before insert page
|
|
133
|
+
if (force || (href === _location.href && page.parentNode !== router.node)) router.content(page);
|
|
134
|
+
})
|
|
164
135
|
// handle scroll restoration
|
|
165
136
|
let { x, y } = Router.scroll ?? {x: 0, y: 0};
|
|
166
137
|
scrollTo(x, y);
|
|
@@ -168,6 +139,56 @@ export class Router extends $HTMLElement {
|
|
|
168
139
|
this.dispatchEvent(new Event('routeopen', {bubbles: true}));
|
|
169
140
|
return this;
|
|
170
141
|
}
|
|
142
|
+
|
|
143
|
+
protected getRoutes(routes: typeof this.routes, targetPath: string): RouteData[] {
|
|
144
|
+
const split = (p: string) => p.replaceAll(/\/+/g, '/').replace(/^\//, '').split('/').map(path => `/${path}`);
|
|
145
|
+
let targetPathSplit = split(targetPath);
|
|
146
|
+
if (!routes.size) return [];
|
|
147
|
+
// check each route
|
|
148
|
+
for (const [_, route] of routes) {
|
|
149
|
+
// check each path pass
|
|
150
|
+
routePathLoop: for (const [path, paramsHandle] of route.paths) {
|
|
151
|
+
let routePathSplit = split(path);
|
|
152
|
+
let targetPathNodePosition = 0;
|
|
153
|
+
let params: { [key: string]: string } = isFunction(paramsHandle) ? paramsHandle() : paramsHandle ?? {};
|
|
154
|
+
let pathId = '';
|
|
155
|
+
// check each path node
|
|
156
|
+
pathNodeLoop: for (let i = 0; i < routePathSplit.length; i++) {
|
|
157
|
+
// reset target path node position
|
|
158
|
+
targetPathNodePosition = i;
|
|
159
|
+
const routeNode = routePathSplit[i];
|
|
160
|
+
const targetNode = targetPathSplit[i];
|
|
161
|
+
// path node undefined, break path loop
|
|
162
|
+
if (!routeNode || !targetNode) continue routePathLoop;
|
|
163
|
+
// path node is params node
|
|
164
|
+
if (routeNode.includes(':')) {
|
|
165
|
+
// target not matched
|
|
166
|
+
if (targetNode === '/') continue routePathLoop;
|
|
167
|
+
const [prefix, paramName] = routeNode.split(':') as [string, string];
|
|
168
|
+
if (!startsWith(targetNode, prefix)) continue routePathLoop;
|
|
169
|
+
params[paramName] = targetNode.replace(`${prefix}`, '');
|
|
170
|
+
pathId += targetNode;
|
|
171
|
+
continue pathNodeLoop;
|
|
172
|
+
}
|
|
173
|
+
// path node not matched, next path
|
|
174
|
+
if (routeNode !== targetNode) continue routePathLoop;
|
|
175
|
+
pathId += targetNode;
|
|
176
|
+
}
|
|
177
|
+
// target path node longer than route, next route
|
|
178
|
+
if (targetPathSplit[targetPathNodePosition + 1] && !route.routes.size) continue routePathLoop;
|
|
179
|
+
// all path node passed, route found
|
|
180
|
+
return [{route, params, pathId}, ...this.getRoutes(route.routes, targetPathSplit.slice(targetPathNodePosition + 1).join('/'))]
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
// no route passed
|
|
184
|
+
const notfound = routes.get('notfound');
|
|
185
|
+
if (notfound) return [{route: notfound, params: {}, pathId: 'notfound'}]
|
|
186
|
+
return [];
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
protected getPage() {
|
|
190
|
+
|
|
191
|
+
}
|
|
171
192
|
}
|
|
172
193
|
|
|
173
194
|
export interface Router {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { $Anchor } from "
|
|
1
|
+
import { $Anchor } from "@amateras/html/node/$Anchor";
|
|
2
2
|
|
|
3
3
|
export class RouterAnchor extends $Anchor {
|
|
4
4
|
constructor() {
|
|
@@ -13,7 +13,7 @@ export class RouterAnchor extends $Anchor {
|
|
|
13
13
|
}
|
|
14
14
|
}
|
|
15
15
|
|
|
16
|
-
declare module 'amateras/core' {
|
|
16
|
+
declare module '@amateras/core' {
|
|
17
17
|
export namespace $ {
|
|
18
18
|
export interface $NodeMap {
|
|
19
19
|
'ra': typeof RouterAnchor;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { Page
|
|
2
|
-
import {
|
|
3
|
-
import
|
|
1
|
+
import { Page } from "#node/Page";
|
|
2
|
+
import type { $NodeContentResolver } from "@amateras/core/node/$Node";
|
|
3
|
+
import { _instanceof, _Promise } from "@amateras/utils";
|
|
4
4
|
import type { AsyncPageBuilder, RouteParams } from "./Route";
|
|
5
5
|
|
|
6
6
|
export class PageBuilder<Params extends RouteParams = any> {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Page } from "#node/Page";
|
|
2
|
-
import {
|
|
2
|
+
import { _null, _instanceof, isUndefined } from "@amateras/utils";
|
|
3
3
|
import { PageBuilder, type PageBuilderFunction } from "./PageBuilder";
|
|
4
4
|
|
|
5
5
|
export class Route<Path extends RoutePath = RoutePath, Params extends RouteParams = []> {
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@amateras/signal",
|
|
3
|
+
"peerDependencies": {
|
|
4
|
+
"@amateras/core": "workspace:*",
|
|
5
|
+
"@amateras/utils": "workspace:*"
|
|
6
|
+
},
|
|
7
|
+
"imports": {
|
|
8
|
+
"#structure/*": "./src/structure/*.ts",
|
|
9
|
+
"#lib/*": "./src/lib/*.ts",
|
|
10
|
+
"#node/*": "./src/node/*.ts"
|
|
11
|
+
},
|
|
12
|
+
"exports": {
|
|
13
|
+
".": "./src/index.ts",
|
|
14
|
+
"./structure/*": "./src/structure/*.ts",
|
|
15
|
+
"./lib/*": "./src/lib/*.ts",
|
|
16
|
+
"./node/*": "./src/node/*.ts"
|
|
17
|
+
}
|
|
18
|
+
}
|
|
@@ -0,0 +1,221 @@
|
|
|
1
|
+
import { Signal } from "#structure/Signal";
|
|
2
|
+
import { $Node, $Text, type $NodeContentResolver } from "@amateras/core/node/$Node";
|
|
3
|
+
import { _instanceof, isObject, _JSON_stringify, _Object_assign, forEach, _null, _Object_defineProperty, _Object_entries, isNull, isFunction, _Promise, toArray } from "@amateras/utils";
|
|
4
|
+
|
|
5
|
+
// handle $Node content process
|
|
6
|
+
$Node.processors.add((_, content) => {
|
|
7
|
+
const signal = (content as SignalFunction<any>)?.signal;
|
|
8
|
+
if (_instanceof(signal, Signal)) {
|
|
9
|
+
const signalValue = (content as SignalFunction<any>)();
|
|
10
|
+
const signalHandler = (resolver: any): $NodeContentResolver<any> => {
|
|
11
|
+
if (_instanceof(resolver, _Promise)) {
|
|
12
|
+
return resolver.then(signalHandler) as any;
|
|
13
|
+
}
|
|
14
|
+
else if (_instanceof(resolver, $Node)) {
|
|
15
|
+
// handler signal $Node result
|
|
16
|
+
let node = resolver;
|
|
17
|
+
const set = (value: any) => {
|
|
18
|
+
node.replace(value);
|
|
19
|
+
node = value;
|
|
20
|
+
}
|
|
21
|
+
signal.subscribe(set);
|
|
22
|
+
return [resolver];
|
|
23
|
+
} else {
|
|
24
|
+
// handler signal other type result
|
|
25
|
+
const $text = new $Text()
|
|
26
|
+
const set = (value: any) => $text.textContent(isObject(value) ? _JSON_stringify(value) : value);
|
|
27
|
+
signal.subscribe(set);
|
|
28
|
+
set(resolver);
|
|
29
|
+
return [$text];
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
return signalHandler(signalValue);
|
|
33
|
+
}
|
|
34
|
+
})
|
|
35
|
+
|
|
36
|
+
// handle $Node native method setter
|
|
37
|
+
$Node.setters.add((value, set) => {
|
|
38
|
+
const signal = value?.signal;
|
|
39
|
+
if (isFunction(value) && _instanceof(signal, Signal)) {
|
|
40
|
+
signal.subscribe(set);
|
|
41
|
+
return value();
|
|
42
|
+
}
|
|
43
|
+
})
|
|
44
|
+
|
|
45
|
+
declare module '@amateras/core' {
|
|
46
|
+
export namespace $ {
|
|
47
|
+
export function signal<T>(value: T): SignalFunction<T>;
|
|
48
|
+
export function compute<T>(process: (untrack: UntrackHandler) => T): ComputeFunction<T>;
|
|
49
|
+
export function effect(process: (untrack: UntrackHandler) => void): void;
|
|
50
|
+
export function await<K, O extends SignalAwaitOptions<K, unknown>>(signalFn: SignalFunction<OrPromise<K>> | ComputeFunction<OrPromise<K>>, options: O): O[keyof O];
|
|
51
|
+
export interface $NodeContentMap {
|
|
52
|
+
signalFn: SignalFunction<any>;
|
|
53
|
+
computeFn: ComputeFunction<any>;
|
|
54
|
+
}
|
|
55
|
+
export interface $NodeParameterMap<T> {
|
|
56
|
+
// Distribute T type
|
|
57
|
+
signalFn: T extends any ? SignalFunction<Narrow<T>> : never;
|
|
58
|
+
computeFn: T extends any ? ComputeFunction<Narrow<T>> : never;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
type SignalObject<T> = T extends Array<any> ? {} : T extends object ? { [key in keyof T as `${string & key}$`]: SignalFunction<T[key]> } : {};
|
|
64
|
+
type SignalValue<T> = T extends Promise<infer R> ? T | R : T;
|
|
65
|
+
export type SignalPromiseState = 'await' | 'then' | 'catch';
|
|
66
|
+
export type SignalAwaitOptions<T, R> = {
|
|
67
|
+
await: R | (() => R);
|
|
68
|
+
then: R | ((value: T) => R);
|
|
69
|
+
catch: R | ((error: any) => R);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
export type SignalFunction<T> = {
|
|
73
|
+
(): T;
|
|
74
|
+
signal: Signal<T>;
|
|
75
|
+
set: (newValue: SignalValue<T> | ((oldValue: T) => SignalValue<T>)) => SignalFunction<T>;
|
|
76
|
+
value: () => T;
|
|
77
|
+
state: SignalPromiseState;
|
|
78
|
+
await: <R>(resolver: R) => AwaitFunction<T, R>
|
|
79
|
+
} & SignalObject<T>;
|
|
80
|
+
|
|
81
|
+
export type ComputeFunction<T> = {
|
|
82
|
+
(): T;
|
|
83
|
+
signal: Signal<T>;
|
|
84
|
+
state: SignalPromiseState;
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
export type AwaitFunction<T, R> = {
|
|
88
|
+
(): R;
|
|
89
|
+
then<D>(resolver: (value: Awaited<T>) => D): AwaitFunction<T, R | D>;
|
|
90
|
+
then<D>(resolver: D): AwaitFunction<T, R | D>;
|
|
91
|
+
catch<D>(resolver: (error: any) => D): AwaitFunction<T, R | D>;
|
|
92
|
+
catch<D>(resolver: D): AwaitFunction<T, R | D>;
|
|
93
|
+
} & ComputeFunction<T>
|
|
94
|
+
|
|
95
|
+
export type SignalListener = (signal: Signal<any>) => void;
|
|
96
|
+
export type UntrackHandler = <T>(fn: () => T) => T
|
|
97
|
+
|
|
98
|
+
const signalComputeListeners = new Set<SignalListener>();
|
|
99
|
+
const signalEffectListeners = new Set<SignalListener>();
|
|
100
|
+
const signalFnMap = new Map<any, SignalFunction<any> | ComputeFunction<any>>();
|
|
101
|
+
|
|
102
|
+
// experiment feature
|
|
103
|
+
const nestedComputeFn = (value: any, parentSignalFn: SignalFunction<any> | ComputeFunction<any>) => {
|
|
104
|
+
if (isObject(value) && !isNull(value)) {
|
|
105
|
+
forEach(_Object_entries(value), ([key, val]) => {
|
|
106
|
+
const cachedFn = signalFnMap.get(val);
|
|
107
|
+
const val$ = cachedFn ?? $.compute(() => parentSignalFn()[key]);
|
|
108
|
+
if (!cachedFn && isObject(val)) {
|
|
109
|
+
signalFnMap.set(val, val$);
|
|
110
|
+
nestedComputeFn(val, val$)
|
|
111
|
+
}
|
|
112
|
+
_Object_defineProperty(parentSignalFn, `${key}$`, {value: val$});
|
|
113
|
+
})
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
const AWAIT = 'await';
|
|
118
|
+
const THEN = 'then';
|
|
119
|
+
const CATCH = 'catch';
|
|
120
|
+
|
|
121
|
+
_Object_assign($, {
|
|
122
|
+
// signal function
|
|
123
|
+
signal<T>(value: T): SignalFunction<T> {
|
|
124
|
+
const signal = new Signal<T>(value);
|
|
125
|
+
const signalFn = function () {
|
|
126
|
+
forEach([...signalComputeListeners, ...signalEffectListeners], fn => fn(signal));
|
|
127
|
+
return signal.value();
|
|
128
|
+
} as SignalFunction<T>
|
|
129
|
+
nestedComputeFn(value, signalFn);
|
|
130
|
+
if (_instanceof(value, _Promise)) {
|
|
131
|
+
value.catch(err => {
|
|
132
|
+
signalFn.state = CATCH;
|
|
133
|
+
signal.value(err);
|
|
134
|
+
}).then(v => {
|
|
135
|
+
signalFn.state = THEN;
|
|
136
|
+
signal.value(v as any);
|
|
137
|
+
})
|
|
138
|
+
}
|
|
139
|
+
_Object_assign(signalFn, {
|
|
140
|
+
signal,
|
|
141
|
+
set: (newValue: T) => (signal.value(newValue), signalFn),
|
|
142
|
+
value: () => signal.value(),
|
|
143
|
+
state: _instanceof(value, _Promise) ? AWAIT : THEN,
|
|
144
|
+
|
|
145
|
+
await(awaitResolver: any) {
|
|
146
|
+
let thenResolver: any = _null
|
|
147
|
+
let catchResolver: any = _null
|
|
148
|
+
const awaitFn = $.compute(untrack => {
|
|
149
|
+
const value = signalFn();
|
|
150
|
+
return untrack(() => {
|
|
151
|
+
switch (signalFn.state) {
|
|
152
|
+
case AWAIT: return isFunction(awaitResolver) ? awaitResolver() : awaitResolver;
|
|
153
|
+
case THEN: return isFunction(thenResolver) ? thenResolver(value as any) : thenResolver;
|
|
154
|
+
case CATCH: return isFunction(catchResolver) ? catchResolver(value) : catchResolver;
|
|
155
|
+
}
|
|
156
|
+
})
|
|
157
|
+
})
|
|
158
|
+
|
|
159
|
+
_Object_assign(awaitFn, {
|
|
160
|
+
then(resolver: any) {
|
|
161
|
+
thenResolver = resolver;
|
|
162
|
+
return awaitFn;
|
|
163
|
+
},
|
|
164
|
+
catch(resolver: any) {
|
|
165
|
+
catchResolver = resolver;
|
|
166
|
+
return awaitFn;
|
|
167
|
+
}
|
|
168
|
+
})
|
|
169
|
+
|
|
170
|
+
return awaitFn;
|
|
171
|
+
}
|
|
172
|
+
})
|
|
173
|
+
return signalFn
|
|
174
|
+
},
|
|
175
|
+
|
|
176
|
+
// compute function
|
|
177
|
+
compute<T>(process: (untrack: UntrackHandler) => T): ComputeFunction<T> {
|
|
178
|
+
let subscribed = false;
|
|
179
|
+
const signalFn: SignalFunction<any> = $.signal(_null);
|
|
180
|
+
const computeFn = () => {
|
|
181
|
+
if (!subscribed) return signalFn.set(subscribe()).value();
|
|
182
|
+
else return signalFn.set(process(untrack)).value();
|
|
183
|
+
}
|
|
184
|
+
const untrack = <T>(fn: () => T) => {
|
|
185
|
+
if (subscribed) return fn();
|
|
186
|
+
signalComputeListeners.delete(signalListener);
|
|
187
|
+
const result = fn();
|
|
188
|
+
signalComputeListeners.add(signalListener);
|
|
189
|
+
return result;
|
|
190
|
+
}
|
|
191
|
+
const signalListener = (signal: Signal<any>) =>
|
|
192
|
+
signal.subscribe(() => signalFn.set(process(untrack)))
|
|
193
|
+
const subscribe = () => {
|
|
194
|
+
signalComputeListeners.add(signalListener);
|
|
195
|
+
const result = process(untrack);
|
|
196
|
+
signalComputeListeners.delete(signalListener);
|
|
197
|
+
subscribed = true;
|
|
198
|
+
return result;
|
|
199
|
+
}
|
|
200
|
+
_Object_assign(computeFn, { signal: signalFn.signal });
|
|
201
|
+
return computeFn as ComputeFunction<T>
|
|
202
|
+
},
|
|
203
|
+
|
|
204
|
+
// effect
|
|
205
|
+
effect(process: (untrack: UntrackHandler) => void) {
|
|
206
|
+
let subscribed = false;
|
|
207
|
+
const signalListener = (signal: Signal<any>) =>
|
|
208
|
+
signal.subscribe(_ => process(untrack));
|
|
209
|
+
const untrack = <T>(fn: () => T) => {
|
|
210
|
+
if (subscribed) return fn();
|
|
211
|
+
signalEffectListeners.delete(signalListener);
|
|
212
|
+
const result = fn();
|
|
213
|
+
signalEffectListeners.add(signalListener);
|
|
214
|
+
return result;
|
|
215
|
+
}
|
|
216
|
+
signalEffectListeners.add(signalListener);
|
|
217
|
+
process(untrack);
|
|
218
|
+
signalEffectListeners.delete(signalListener);
|
|
219
|
+
subscribed = true;
|
|
220
|
+
},
|
|
221
|
+
})
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import
|
|
3
|
-
import { $
|
|
4
|
-
import {
|
|
5
|
-
import
|
|
1
|
+
import { _document } from "@amateras/core/env";
|
|
2
|
+
import { $HTMLElement } from "@amateras/core/node/$HTMLElement";
|
|
3
|
+
import type { $Node } from "@amateras/core/node/$Node";
|
|
4
|
+
import type { $Virtual } from "@amateras/core/node/$Virtual";
|
|
5
|
+
import { _Array_from, _instanceof, forEach } from "@amateras/utils";
|
|
6
6
|
|
|
7
7
|
export const VirtualScroll = ($parent: $Virtual, scroller: $Node = $(_document)) => {
|
|
8
8
|
scroller.on('scroll', () => render($parent), true);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { $HTMLElement } from "amateras/node/$HTMLElement";
|
|
3
|
-
import type { $Node, $NodeContentResolver } from "amateras/node/$Node";
|
|
4
|
-
import {
|
|
1
|
+
import { chain } from "@amateras/core/lib/chain";
|
|
2
|
+
import { $HTMLElement } from "@amateras/core/node/$HTMLElement";
|
|
3
|
+
import type { $Node, $NodeContentResolver } from "@amateras/core/node/$Node";
|
|
4
|
+
import { _Array_from, _instanceof, forEach, isNull } from "@amateras/utils";
|
|
5
5
|
|
|
6
6
|
const [ACCORDIAN, ACCORDIAN_ITEM, ACCORDIAN_TRIGGER, ACCORDIAN_CONTENT, ACCORDIAN_CONTAINER] = ['accordian', 'accordian-item', 'accordian-trigger', 'accordian-content', 'accordian-container'] as const;
|
|
7
7
|
forEach([
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { chain } from "@amateras/core/lib/chain";
|
|
2
|
+
import { $HTMLElement } from "@amateras/core/node/$HTMLElement";
|
|
3
|
+
|
|
4
|
+
const CAROUSEL = 'carousel';
|
|
5
|
+
const CAROUSEL_ITEM = 'carousel-item';
|
|
6
|
+
|
|
7
|
+
export class Carousel extends $HTMLElement {
|
|
8
|
+
constructor() {
|
|
9
|
+
super(CAROUSEL);
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export class CarouselItem extends $HTMLElement {
|
|
15
|
+
constructor() {
|
|
16
|
+
super(CAROUSEL_ITEM)
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export type CarouselDirection = 'horizontal' | 'vertical';
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import { $
|
|
2
|
-
import { $
|
|
3
|
-
import { $
|
|
4
|
-
import { $Input } from
|
|
5
|
-
import
|
|
6
|
-
import { _instanceof, _undefined } from
|
|
1
|
+
import { $HTMLElement } from "@amateras/core/node/$HTMLElement";
|
|
2
|
+
import type { $Node } from "@amateras/core/node/$Node";
|
|
3
|
+
import { $Form } from "@amateras/html/node/$Form";
|
|
4
|
+
import { $Input } from "@amateras/html/node/$Input";
|
|
5
|
+
import { $Label } from "@amateras/html/node/$Label";
|
|
6
|
+
import { _instanceof, _undefined } from "@amateras/utils";
|
|
7
|
+
|
|
7
8
|
|
|
8
9
|
export class Form extends $Form {
|
|
9
10
|
constructor() {
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { $HTMLElement } from "@amateras/core/node/$HTMLElement";
|
|
2
|
+
import { forEach, isNull } from "@amateras/utils";
|
|
3
|
+
const MODAL = 'modal';
|
|
4
|
+
const MODAL_CONTENT = 'modal-content'
|
|
5
|
+
|
|
6
|
+
forEach([
|
|
7
|
+
`${MODAL}{display:flex;justify-content:center;align-items:center;position:fixed;top:0;left:0;height:100%;width:100%;background:#00000050}`,
|
|
8
|
+
`${MODAL_CONTENT}{display:block;}`
|
|
9
|
+
], $.style)
|
|
10
|
+
export class Modal extends $HTMLElement {
|
|
11
|
+
name?: string;
|
|
12
|
+
constructor(name?: string) {
|
|
13
|
+
super(MODAL);
|
|
14
|
+
this.name = name;
|
|
15
|
+
if (name)
|
|
16
|
+
$(window).on('routeopen', e => {
|
|
17
|
+
const url = new URL(location.href);
|
|
18
|
+
const param = url.searchParams.get(name);
|
|
19
|
+
if (isNull(param)) return this.close();
|
|
20
|
+
this.open();
|
|
21
|
+
})
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
open() {
|
|
25
|
+
$(document.body).insert(this);
|
|
26
|
+
this.once('click', e => {
|
|
27
|
+
if ($(e) === $(e.target)) {
|
|
28
|
+
if (!this.name) this.close();
|
|
29
|
+
else history.back();
|
|
30
|
+
}
|
|
31
|
+
})
|
|
32
|
+
return this;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
close() {
|
|
36
|
+
this.remove();
|
|
37
|
+
return this;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export class ModalContent extends $HTMLElement {
|
|
42
|
+
constructor() {
|
|
43
|
+
super(MODAL_CONTENT);
|
|
44
|
+
}
|
|
45
|
+
}
|