@brandup/ui-app 1.0.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.
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sources":["../../../brandup-ui/dist/mjs/index.js"],"sourcesContent":["const ElemAttributeName = \"uiElement\";\nconst ElemPropertyName = \"brandupUiElement\";\nconst CommandAttributeName = \"command\";\nconst CommandExecutingCssClassName = \"executing\";\nclass UIElement {\n __element = null;\n __events = {};\n __commandHandlers = {};\n // Element members\n get element() { return this.__element; }\n setElement(elem) {\n if (!elem)\n throw \"Not set value elem.\";\n if (this.__element || UIElement.hasElement(elem))\n throw \"UIElement already defined\";\n this.__element = elem;\n this.__element[ElemPropertyName] = this;\n this.__element.dataset[ElemAttributeName] = this.typeName;\n this.defineEvent(\"command\", { cancelable: false, bubbles: true });\n this._onRenderElement(elem);\n }\n // static members\n static hasElement(elem) {\n return !!elem.dataset[ElemAttributeName];\n }\n // HTMLElement event members\n defineEvent(eventName, eventOptions) {\n this.__events[eventName] = eventOptions ? eventOptions : null;\n }\n raiseEvent(eventName, eventArgs) {\n if (!(eventName in this.__events))\n throw new Error(`Not found event \"${eventName}\".`);\n const eventOptions = this.__events[eventName];\n const eventInit = {};\n if (eventOptions) {\n if (eventOptions.bubbles)\n eventInit.bubbles = eventOptions.bubbles;\n if (eventOptions.cancelable)\n eventInit.cancelable = eventOptions.cancelable;\n if (eventOptions.composed)\n eventInit.composed = eventOptions.composed;\n }\n eventInit.detail = eventArgs ? eventArgs : {};\n const event = new CustomEvent(eventName, eventInit);\n return this.dispatchEvent(event);\n }\n addEventListener(type, listener, options) {\n this.__element?.addEventListener(type, listener, options);\n }\n removeEventListener(type, listener, options) {\n this.__element?.removeEventListener(type, listener, options);\n }\n dispatchEvent(event) {\n if (!this.__element)\n throw new Error(\"HTMLElement is not defined.\");\n return this.__element.dispatchEvent(event);\n }\n // Command members\n registerCommand(name, execute, canExecute) {\n name = this.verifyCommandName(name);\n this.__commandHandlers[name] = {\n name: name,\n execute,\n canExecute,\n isExecuting: false\n };\n }\n registerAsyncCommand(name, delegate, canExecute) {\n name = this.verifyCommandName(name);\n this.__commandHandlers[name] = {\n name: name,\n delegate,\n canExecute,\n isExecuting: false\n };\n }\n hasCommand(name) {\n return name.toLowerCase() in this.__commandHandlers;\n }\n execCommand(name, elem) {\n if (!this.__element)\n throw new Error(\"UIElement is not set HTMLElement.\");\n const key = name.toLowerCase();\n if (!(key in this.__commandHandlers))\n throw new Error(`Command \"${name}\" is not registered.`);\n const context = {\n target: elem,\n uiElem: this,\n transparent: false\n };\n const handler = this.__commandHandlers[key];\n if (handler.isExecuting)\n return { result: CommandsExecStatus.AlreadyExecuting, context };\n handler.isExecuting = true;\n if (!this._onCanExecCommand(name, elem)) {\n handler.isExecuting = false;\n return { result: CommandsExecStatus.NotAllow, context };\n }\n if (handler.canExecute && !handler.canExecute(elem, context)) {\n handler.isExecuting = false;\n return { result: CommandsExecStatus.NotAllow, context };\n }\n this.raiseEvent(\"command\", {\n name: handler.name,\n uiElem: this,\n elem: this.__element\n });\n if (handler.execute) {\n // Если команда синхронная.\n try {\n handler.execute(elem, context);\n }\n finally {\n handler.isExecuting = false;\n }\n }\n else if (handler.delegate) {\n // Если команда асинхронная.\n elem.classList.add(CommandExecutingCssClassName);\n let timeoutId = 0;\n const endFunc = () => {\n handler.isExecuting = false;\n elem.classList.remove(CommandExecutingCssClassName);\n };\n const asyncContext = {\n target: elem,\n uiElem: this,\n transparent: context.transparent,\n complate: () => {\n clearTimeout(timeoutId);\n endFunc();\n }\n };\n const handlerResult = handler.delegate(asyncContext);\n if (handlerResult && handlerResult instanceof Promise)\n handlerResult.finally(() => asyncContext.complate());\n if (handler.isExecuting && asyncContext.timeout) {\n timeoutId = window.setTimeout(() => {\n if (asyncContext.timeoutCallback)\n asyncContext.timeoutCallback();\n endFunc();\n }, asyncContext.timeout);\n }\n context.transparent = asyncContext.transparent;\n }\n else\n throw new Error(\"Not set command execute flow.\");\n return { result: CommandsExecStatus.Success, context: context };\n }\n verifyCommandName(name) {\n const key = name.toLowerCase();\n if (key in this.__commandHandlers)\n throw new Error(`Command \"${name}\" already registered.`);\n return key;\n }\n _onRenderElement(_elem) {\n return;\n }\n _onCanExecCommand(_name, _elem) {\n return true;\n }\n destroy() {\n const elem = this.__element;\n if (!elem)\n return;\n this.__element = null;\n delete elem.dataset[ElemAttributeName];\n delete elem[ElemPropertyName];\n }\n}\nvar CommandsExecStatus;\n(function (CommandsExecStatus) {\n CommandsExecStatus[CommandsExecStatus[\"NotAllow\"] = 1] = \"NotAllow\";\n CommandsExecStatus[CommandsExecStatus[\"AlreadyExecuting\"] = 2] = \"AlreadyExecuting\";\n CommandsExecStatus[CommandsExecStatus[\"Success\"] = 3] = \"Success\";\n})(CommandsExecStatus || (CommandsExecStatus = {}));\nconst fundUiElementByCommand = (elem, commandName) => {\n while (elem) {\n if (elem.dataset[ElemAttributeName]) {\n const uiElem = elem[ElemPropertyName];\n if (uiElem.hasCommand(commandName))\n return uiElem;\n }\n if (typeof elem.parentElement === \"undefined\")\n elem = elem.parentNode;\n else if (elem.parentElement)\n elem = elem.parentElement;\n else\n break;\n }\n return null;\n};\nconst commandClickHandler = (e) => {\n let commandElem = e.target;\n while (commandElem) {\n if (commandElem.dataset[CommandAttributeName])\n break;\n if (commandElem === e.currentTarget)\n return;\n commandElem = commandElem.parentElement;\n }\n if (!commandElem)\n return;\n const commandName = commandElem.dataset[CommandAttributeName];\n if (!commandName)\n throw new Error(\"Command data attribute is not have value.\");\n const uiElem = fundUiElementByCommand(commandElem, commandName);\n if (uiElem === null) {\n console.warn(`Not find handler for command \"${commandName}\".`);\n }\n else {\n const commandResult = uiElem.execCommand(commandName, commandElem);\n if (commandResult.context.transparent)\n return;\n }\n e.preventDefault();\n e.stopPropagation();\n e.stopImmediatePropagation();\n};\nwindow.addEventListener(\"click\", commandClickHandler, false);\n\nexport { CommandAttributeName, CommandExecutingCssClassName, CommandsExecSt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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
@@ -0,0 +1,226 @@
1
+ import { UIElement } from '@brandup/ui';
2
+
3
+ interface EnvironmentModel {
4
+ basePath: string;
5
+ [key: string]: any;
6
+ }
7
+ interface ApplicationModel {
8
+ [key: string]: any;
9
+ }
10
+ interface QueryParams {
11
+ [key: string]: string | string[];
12
+ }
13
+
14
+ interface Middleware {
15
+ readonly name: string;
16
+ start?: MiddlewareMethod;
17
+ loaded?: MiddlewareMethod;
18
+ navigate?: MiddlewareMethod;
19
+ submit?: MiddlewareMethod;
20
+ stop?: MiddlewareMethod;
21
+ [key: string]: MiddlewareMethod | any;
22
+ }
23
+ type MiddlewareMethod<TContext extends InvokeContext = any> = (context: TContext, next: MiddlewareNext) => Promise<void>;
24
+ type MiddlewareNext = () => Promise<void>;
25
+ interface InvokeContext {
26
+ readonly app: Application;
27
+ readonly data: ContextData;
28
+ }
29
+ interface ContextData {
30
+ [key: string]: any;
31
+ }
32
+ interface StartContext<TApplication extends Application = Application, TData extends ContextData = ContextData> extends InvokeContext {
33
+ readonly app: TApplication;
34
+ readonly data: TData;
35
+ }
36
+ interface StopContext<TApplication extends Application = Application, TData extends ContextData = ContextData> extends InvokeContext {
37
+ readonly app: TApplication;
38
+ readonly data: TData;
39
+ }
40
+ interface NavigateContext<TApplication extends Application = Application, TData extends ContextData = ContextData> extends InvokeContext {
41
+ readonly app: TApplication;
42
+ readonly data: TData;
43
+ /** Source navigation event. */
44
+ readonly source: NavigateSource;
45
+ /** Full url for navigation. */
46
+ readonly url: string;
47
+ /** Scheme, host and port. */
48
+ readonly origin: string;
49
+ /** Path of navigation url. */
50
+ readonly path: string;
51
+ /** Query parameters of navigation url. */
52
+ readonly query: URLSearchParams;
53
+ /** Hash of navigation url. */
54
+ readonly hash: string | null;
55
+ /** Replace current navigation entry. */
56
+ /** Navigation origin is different of current page origin. */
57
+ readonly external: boolean;
58
+ replace: boolean;
59
+ }
60
+ /**
61
+ * Navigation event source.
62
+ * first - first navigation from run.
63
+ * nav - from nav app method.
64
+ * submit - from submit app method. For only get submit.
65
+ */
66
+ type NavigateSource = "first" | "nav" | "submit";
67
+ interface SubmitContext<TApplication extends Application = Application, TData extends ContextData = ContextData> extends NavigateContext<TApplication, TData> {
68
+ readonly form: HTMLFormElement;
69
+ readonly button: HTMLButtonElement | null;
70
+ readonly method: SubmitMethod;
71
+ readonly enctype: string;
72
+ }
73
+ type SubmitMethod = "GET" | "POST" | "PUT" | "DELETE" | "PATCH" | string;
74
+
75
+ declare class MiddlewareInvoker {
76
+ readonly middleware: Middleware;
77
+ private __next;
78
+ constructor(middleware: Middleware);
79
+ next(middleware: Middleware): void;
80
+ invoke<TContext extends InvokeContext>(method: string, context: TContext): Promise<void>;
81
+ private __invoke;
82
+ }
83
+
84
+ /**
85
+ * Base application class.
86
+ */
87
+ declare class Application<TModel extends ApplicationModel = ApplicationModel> extends UIElement {
88
+ readonly env: EnvironmentModel;
89
+ readonly model: TModel;
90
+ private readonly __invoker;
91
+ private __isInitialized;
92
+ private __isDestroy;
93
+ private __middlewares;
94
+ private __lastNav;
95
+ constructor(env: EnvironmentModel, model: TModel);
96
+ get typeName(): string;
97
+ /** Middleware methods invoker. */
98
+ get invoker(): MiddlewareInvoker;
99
+ /**
100
+ * @param middlewares Initialize application with middlewares. Using in ApplicationBuilder.
101
+ */
102
+ initialize(middlewares: Array<Middleware>): void;
103
+ protected onInitialize(): void;
104
+ /**
105
+ * Get middleware by type.
106
+ * @param type Type of middleware.
107
+ * @returns Middleware instance.
108
+ */
109
+ middleware<T extends Middleware>(name: string): T;
110
+ /**
111
+ * Run application.
112
+ * @param contextData Run context data.
113
+ * @param element HTMLElement of application. Default is document.body.
114
+ * @returns Promise of runned result.
115
+ */
116
+ run<TData extends ContextData>(contextData?: TData | null, element?: HTMLElement): Promise<NavigateContext<this, TData>>;
117
+ /**
118
+ * Navigate application to url.
119
+ * @param options Navigate options.
120
+ * @returns Promise of navigated result.
121
+ */
122
+ nav<TData extends ContextData>(options?: NavigationOptions<TData> | string | null): Promise<NavigateContext<this, TData>>;
123
+ /**
124
+ * Submit application form.
125
+ * @param options Submit options.
126
+ * @returns Promise of submitted result.
127
+ */
128
+ submit<TData extends ContextData>(options: SubmitOptions<TData> | HTMLFormElement): Promise<SubmitContext<this, TData>>;
129
+ /**
130
+ * Reload page with nav.
131
+ */
132
+ reload(): Promise<NavigateContext<this, ContextData>>;
133
+ /**
134
+ * Global reload page in browser.
135
+ */
136
+ restart(): void;
137
+ destroy<TData extends ContextData = ContextData>(contextData?: TData | null): Promise<StopContext<Application, TData>>;
138
+ /**
139
+ * Generate url of application base url.
140
+ * @param path Add optional path of base url.
141
+ * @param query Add optional query params.
142
+ * @param hash Add optional hash.
143
+ * @returns Relative url with base path.
144
+ */
145
+ buildUrl(path?: string, query?: QueryParams | URLSearchParams | FormData, hash?: string): string;
146
+ }
147
+ interface NavigationOptions<TData extends ContextData = ContextData> {
148
+ url?: string | null;
149
+ query?: QueryParams | URLSearchParams | FormData;
150
+ replace?: boolean;
151
+ data?: TData;
152
+ callback?: (result: CallbackResult<NavigateContext<Application, TData>>) => void | null;
153
+ }
154
+ interface SubmitOptions<TData extends ContextData = ContextData> {
155
+ form: HTMLFormElement;
156
+ button?: HTMLButtonElement | null;
157
+ query?: QueryParams | URLSearchParams;
158
+ data?: TData;
159
+ callback?: (result: CallbackResult<SubmitContext<Application, TData>>) => void;
160
+ }
161
+ interface CallbackResult<TContext extends InvokeContext> {
162
+ status: CallbackStatus;
163
+ context: TContext;
164
+ }
165
+ type CallbackStatus = "success" | "error";
166
+
167
+ declare class ApplicationBuilder<TModel extends ApplicationModel> {
168
+ private __appType;
169
+ private __middlewares;
170
+ useApp(appType: typeof Application<TModel>): this;
171
+ useMiddleware(middleware: ((...params: Array<any>) => Middleware) | Middleware, ...params: Array<any>): this;
172
+ build(env: EnvironmentModel, model: TModel): Application<TModel>;
173
+ }
174
+
175
+ interface ParsedUrl {
176
+ full: string;
177
+ relative: string;
178
+ origin: string;
179
+ path: string;
180
+ query: URLSearchParams;
181
+ hash: string | null;
182
+ external: boolean;
183
+ }
184
+ declare const _default$1: {
185
+ parseUrl: (url: string | null) => ParsedUrl;
186
+ extendQuery: (url: ParsedUrl, query: QueryParams | URLSearchParams | FormData) => void;
187
+ buildUrl: (basePath: string, path?: string, query?: QueryParams | URLSearchParams | FormData, hash?: string) => string;
188
+ };
189
+
190
+ type url_ParsedUrl = ParsedUrl;
191
+ declare namespace url {
192
+ export { type url_ParsedUrl as ParsedUrl, _default$1 as default };
193
+ }
194
+
195
+ interface Constants {
196
+ readonly LoadingElementClass: string;
197
+ readonly NavUrlClassName: string;
198
+ readonly FormClassName: string;
199
+ readonly NavUrlAttributeName: string;
200
+ readonly NavUrlReplaceAttributeName: string;
201
+ readonly NavIgnoreAttributeName: string;
202
+ readonly STATE_CLASS: {
203
+ readonly LOADING: string;
204
+ readonly LOADED: string;
205
+ readonly READY: string;
206
+ };
207
+ }
208
+ declare const result: Constants;
209
+
210
+ declare namespace constants {
211
+ export { result as default };
212
+ }
213
+
214
+ declare const _default: {
215
+ window: Window & typeof globalThis;
216
+ document: Document;
217
+ body: HTMLElement;
218
+ location: Location;
219
+ reload: () => void;
220
+ };
221
+
222
+ declare namespace browser {
223
+ export { _default as default };
224
+ }
225
+
226
+ export { Application, ApplicationBuilder, type ApplicationModel, browser as BROWSER, constants as CONSTANTS, type CallbackResult, type CallbackStatus, type ContextData, type EnvironmentModel, type InvokeContext, type Middleware, type MiddlewareMethod, type MiddlewareNext, type NavigateContext, type NavigateSource, type NavigationOptions, type QueryParams, type StartContext, type StopContext, type SubmitContext, type SubmitMethod, type SubmitOptions, url as UrlHelper };
package/package.json ADDED
@@ -0,0 +1,50 @@
1
+ {
2
+ "name": "@brandup/ui-app",
3
+ "description": "Basic infrastructure framework for web applications.",
4
+ "keywords": [
5
+ "brandup",
6
+ "typescript",
7
+ "ui",
8
+ "app"
9
+ ],
10
+ "author": {
11
+ "name": "Dmitry Kovyazin",
12
+ "email": "it@brandup.online"
13
+ },
14
+ "homepage": "https://github.com/brandup-online/brandup-ui",
15
+ "repository": {
16
+ "type": "git",
17
+ "url": "https://github.com/brandup-online/brandup-ui.git"
18
+ },
19
+ "bugs": {
20
+ "url": "https://github.com/brandup-online/brandup-ui/issues",
21
+ "email": "it@brandup.online"
22
+ },
23
+ "main": "dist/cjs/index.js",
24
+ "module": "dist/mjs/index.js",
25
+ "types": "dist/types.d.ts",
26
+ "license": "Apache-2.0",
27
+ "version": "1.0.1",
28
+ "dependencies": {
29
+ "@brandup/ui": "^1.0.1"
30
+ },
31
+ "devDependencies": {
32
+ "@rollup/plugin-commonjs": "^25.0.8",
33
+ "@rollup/plugin-node-resolve": "^15.2.3",
34
+ "@rollup/plugin-terser": "^0.4.4",
35
+ "rollup": "^4.19.0",
36
+ "rollup-plugin-dts": "^6.1.1",
37
+ "rollup-plugin-peer-deps-external": "^2.2.4",
38
+ "rollup-plugin-typescript2": "^0.36.0",
39
+ "tslib": "^2.6.3",
40
+ "typescript": "^5.5.3"
41
+ },
42
+ "files": [
43
+ "dist",
44
+ "README.md"
45
+ ],
46
+ "scripts": {
47
+ "build": "rollup -c --bundleConfigAsCjs",
48
+ "watch": "rollup -c -w --bundleConfigAsCjs"
49
+ }
50
+ }