brew-js-react 0.1.0-beta

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (44) hide show
  1. package/README.md +5 -0
  2. package/app.js +11 -0
  3. package/dialog.d.ts +33 -0
  4. package/dialog.js +83 -0
  5. package/dist/brew-js-react.js +1060 -0
  6. package/dist/brew-js-react.js.map +1 -0
  7. package/dist/brew-js-react.min.js +2 -0
  8. package/dist/brew-js-react.min.js.map +1 -0
  9. package/entry.js +2 -0
  10. package/hooks.d.ts +20 -0
  11. package/hooks.js +34 -0
  12. package/include/zeta-dom/dom.js +3 -0
  13. package/include/zeta-dom/domUtil.js +1 -0
  14. package/include/zeta-dom/events.js +1 -0
  15. package/include/zeta-dom/util.js +1 -0
  16. package/index.d.ts +4 -0
  17. package/index.js +4 -0
  18. package/mixin.d.ts +48 -0
  19. package/mixin.js +64 -0
  20. package/mixins/AnimateMixin.d.ts +9 -0
  21. package/mixins/AnimateMixin.js +31 -0
  22. package/mixins/AnimateSequenceItemMixin.d.ts +5 -0
  23. package/mixins/AnimateSequenceItemMixin.js +15 -0
  24. package/mixins/AnimateSequenceMixin.d.ts +6 -0
  25. package/mixins/AnimateSequenceMixin.js +29 -0
  26. package/mixins/ClassNameMixin.d.ts +12 -0
  27. package/mixins/ClassNameMixin.js +41 -0
  28. package/mixins/FlyoutMixin.d.ts +14 -0
  29. package/mixins/FlyoutMixin.js +95 -0
  30. package/mixins/FocusStateMixin.d.ts +3 -0
  31. package/mixins/FocusStateMixin.js +24 -0
  32. package/mixins/LoadingStateMixin.d.ts +3 -0
  33. package/mixins/LoadingStateMixin.js +27 -0
  34. package/mixins/Mixin.d.ts +47 -0
  35. package/mixins/Mixin.js +61 -0
  36. package/mixins/ScrollableMixin.d.ts +17 -0
  37. package/mixins/ScrollableMixin.js +46 -0
  38. package/mixins/StatefulMixin.d.ts +23 -0
  39. package/mixins/StatefulMixin.js +71 -0
  40. package/mixins/StaticAttributeMixin.d.ts +5 -0
  41. package/mixins/StaticAttributeMixin.js +13 -0
  42. package/package.json +46 -0
  43. package/view.d.ts +33 -0
  44. package/view.js +92 -0
@@ -0,0 +1,29 @@
1
+ import { definePrototype, extend } from "../include/zeta-dom/util.js";
2
+ import AnimateMixin from "./AnimateMixin.js";
3
+ import AnimateSequenceItemMixin from "./AnimateSequenceItemMixin.js";
4
+
5
+ const AnimateSequenceMixinSuper = AnimateMixin.prototype;
6
+ var animateSequenceMixinCounter = 0;
7
+
8
+ export default function AnimateSequenceMixin() {
9
+ AnimateMixin.call(this);
10
+ this.className = 'brew-anim-' + (++animateSequenceMixinCounter);
11
+ this.item = new AnimateSequenceItemMixin(this.className);
12
+ }
13
+
14
+ definePrototype(AnimateSequenceMixin, AnimateMixin, {
15
+ reset: function () {
16
+ this.item.reset();
17
+ return AnimateSequenceMixinSuper.reset.call(this);
18
+ },
19
+ getCustomAttributes: function () {
20
+ return extend({}, AnimateSequenceMixinSuper.getCustomAttributes.call(this), {
21
+ 'animate-sequence': '.' + this.className
22
+ });
23
+ },
24
+ clone: function () {
25
+ return extend(AnimateSequenceMixinSuper.clone.call(this), {
26
+ item: this.item.ref.getMixin()
27
+ });
28
+ }
29
+ });
@@ -0,0 +1,12 @@
1
+ import StatefulMixin from "./StatefulMixin";
2
+
3
+ export interface ClassNameMixinState extends MixinState {
4
+ classNames: Record<string, boolean>;
5
+ }
6
+
7
+ export default class ClassNameMixin extends StatefulMixin {
8
+ constructor(classNames: string[] = []);
9
+
10
+ protected onClassNameUpdated(element: HTMLElement, prevState: Record<string, boolean>, state: Record<string, boolean>): void;
11
+ }
12
+
@@ -0,0 +1,41 @@
1
+ import { definePrototype, each, equal, extend } from "../include/zeta-dom/util.js";
2
+ import dom from "../include/zeta-dom/dom.js";
3
+ import StatefulMixin from "./StatefulMixin.js";
4
+
5
+ const ClassNameMixinSuper = StatefulMixin.prototype;
6
+
7
+ export default function ClassNameMixin(classNames) {
8
+ StatefulMixin.call(this);
9
+ this.classNames = classNames || [];
10
+ }
11
+
12
+ definePrototype(ClassNameMixin, StatefulMixin, {
13
+ getClassNames: function () {
14
+ return [this.state.classNames];
15
+ },
16
+ initState: function () {
17
+ return {
18
+ element: null,
19
+ classNames: {}
20
+ };
21
+ },
22
+ initElement: function (element, state) {
23
+ var self = this;
24
+ dom.watchAttributes(element, ['class'], function (nodes) {
25
+ if (nodes.includes(element)) {
26
+ const prev = extend({}, state.classNames);
27
+ each(self.classNames, function (i, v) {
28
+ state.classNames[v] = element.classList.contains(v);
29
+ });
30
+ if (!equal(prev, state.classNames)) {
31
+ self.onClassNameUpdated(element, prev, state.classNames);
32
+ }
33
+ }
34
+ });
35
+ },
36
+ clone: function () {
37
+ return extend(ClassNameMixinSuper.clone.call(this), { classNames: this.classNames });
38
+ },
39
+ onClassNameUpdated: function (element, prevState, state) {
40
+ }
41
+ });
@@ -0,0 +1,14 @@
1
+ import ClassNameMixin from "./ClassNameMixin";
2
+ import { AnimationEffect } from "./AnimateMixin";
3
+
4
+ export default class FlyoutMixin extends ClassNameMixin {
5
+ readonly isFlyoutOpened: boolean;
6
+ readonly animating: boolean;
7
+ readonly visible: boolean;
8
+ readonly toggle: ClassNameMixin;
9
+
10
+ withEffects(...effects: AnimationEffect[]): this;
11
+ onOpen(callback: () => void): Zeta.UnregisterCallback;
12
+ onToggleState(callback: (state: boolean) => void): Zeta.UnregisterCallback;
13
+ onVisibilityChanged(callback: (state: boolean) => void): Zeta.UnregisterCallback;
14
+ }
@@ -0,0 +1,95 @@
1
+ import { defineAliasProperty, definePrototype, each, extend, makeArray } from "../include/zeta-dom/util.js";
2
+ import { app } from "../app.js";
3
+ import ClassNameMixin from "./ClassNameMixin.js";
4
+
5
+ const FlyoutMixinSuper = ClassNameMixin.prototype;
6
+ var flyoutMixinCounter = 0;
7
+
8
+ export default function FlyoutMixin() {
9
+ ClassNameMixin.call(this, ['open', 'closing', 'tweening-in', 'tweening-out']);
10
+ this.isFlyoutOpened = false;
11
+ this.animating = false;
12
+ this.visible = false;
13
+ this.toggle = new ClassNameMixin(['target-opened']);
14
+ }
15
+
16
+ definePrototype(FlyoutMixin, ClassNameMixin, {
17
+ reset: function () {
18
+ this.toggle.reset();
19
+ return FlyoutMixinSuper.reset.call(this);
20
+ },
21
+ next: function () {
22
+ this.effects = undefined;
23
+ return FlyoutMixinSuper.next.call(this);
24
+ },
25
+ withEffects: function () {
26
+ this.effects = makeArray(arguments);
27
+ return this;
28
+ },
29
+ getCustomAttributes: function () {
30
+ return extend({}, FlyoutMixinSuper.getCustomAttributes.call(this), {
31
+ 'is-flyout': ''
32
+ }, this.effects && {
33
+ 'animate-on': 'open',
34
+ 'animate-in': this.effects.join(' '),
35
+ 'animate-out': ''
36
+ });
37
+ },
38
+ onOpen: function (callback) {
39
+ return this.onToggleState(function (opened) {
40
+ if (opened) {
41
+ return callback();
42
+ }
43
+ });
44
+ },
45
+ onToggleState: function (callback) {
46
+ return this.watch('isFlyoutOpened', callback);
47
+ },
48
+ onVisibilityChanged: function (callback) {
49
+ return this.watch('visible', callback);
50
+ },
51
+ initElement: function (element, state) {
52
+ var self = this;
53
+ FlyoutMixinSuper.initElement.call(self, element, state);
54
+ if (!element.id) {
55
+ element.id = 'flyout-' + (++flyoutMixinCounter);
56
+ }
57
+ app.on(element, {
58
+ animationstart: function () {
59
+ self.animating = true;
60
+ },
61
+ animationcomplete: function () {
62
+ self.animating = false;
63
+ },
64
+ }, true);
65
+ setImmediate(function () {
66
+ each(self.toggle.elements(), function (i, v) {
67
+ v.setAttribute('toggle', '#' + element.id);
68
+ });
69
+ });
70
+ },
71
+ clone: function () {
72
+ var mixin = extend(FlyoutMixinSuper.clone.call(this), {
73
+ toggle: this.toggle.ref.getMixin()
74
+ });
75
+ defineAliasProperty(mixin, 'isFlyoutOpened', this);
76
+ return mixin;
77
+ },
78
+ onClassNameUpdated: function (element, prevState, state) {
79
+ var self = this;
80
+ var isAdded = function (v) {
81
+ return prevState[v] !== state[v] && state[v];
82
+ };
83
+ var isRemoved = function (v) {
84
+ return prevState[v] !== state[v] && !state[v];
85
+ };
86
+ if (isAdded('open')) {
87
+ self.isFlyoutOpened = true;
88
+ self.visible = true;
89
+ } else if (isAdded('closing') || isAdded('tweening-out')) {
90
+ self.isFlyoutOpened = false;
91
+ } else if (isRemoved('open')) {
92
+ self.visible = false;
93
+ }
94
+ }
95
+ });
@@ -0,0 +1,3 @@
1
+ import ClassNameMixin from "./ClassNameMixin";
2
+
3
+ export default class FocusStateMixin extends ClassNameMixin { }
@@ -0,0 +1,24 @@
1
+ import { definePrototype } from "../include/zeta-dom/util.js";
2
+ import { setClass } from "../include/zeta-dom/domUtil.js";
3
+ import dom from "../include/zeta-dom/dom.js";
4
+ import ClassNameMixin from "./ClassNameMixin.js";
5
+
6
+ const FocusStateMixinSuper = ClassNameMixin.prototype;
7
+
8
+ export default function FocusStateMixin() {
9
+ ClassNameMixin.call(this, ['focused']);
10
+ }
11
+
12
+ definePrototype(FocusStateMixin, ClassNameMixin, {
13
+ initElement: function (element, state) {
14
+ FocusStateMixinSuper.initElement.call(this, element, state);
15
+ dom.on(element, {
16
+ focusin: function () {
17
+ setClass(element, 'focused', true);
18
+ },
19
+ focusout: function () {
20
+ setClass(element, 'focused', false);
21
+ }
22
+ });
23
+ }
24
+ });
@@ -0,0 +1,3 @@
1
+ import ClassNameMixin from "./ClassNameMixin";
2
+
3
+ export default class LoadingStateMixin extends ClassNameMixin { }
@@ -0,0 +1,27 @@
1
+ import { definePrototype } from "../include/zeta-dom/util.js";
2
+ import { setClass } from "../include/zeta-dom/domUtil.js";
3
+ import dom from "../include/zeta-dom/dom.js";
4
+ import ClassNameMixin from "./ClassNameMixin.js";
5
+
6
+ const LoadingStateMixinSuper = ClassNameMixin.prototype;
7
+
8
+ export default function LoadingStateMixin() {
9
+ ClassNameMixin.call(this, ['loading']);
10
+ }
11
+
12
+ definePrototype(LoadingStateMixin, ClassNameMixin, {
13
+ initElement: function (element, state) {
14
+ LoadingStateMixinSuper.initElement.call(this, element, state);
15
+ dom.on(element, {
16
+ asyncStart: function () {
17
+ setClass(element, 'loading', true);
18
+ },
19
+ asyncEnd: function () {
20
+ setClass(element, 'loading', false);
21
+ },
22
+ cancelled: function () {
23
+ setClass(element, 'loading', false);
24
+ }
25
+ });
26
+ }
27
+ });
@@ -0,0 +1,47 @@
1
+ import React from "react";
2
+ import { ClassName, ClassNameProvider } from "zeta-dom-react";
3
+ import StaticAttributeMixin from "./StaticAttributeMixin";
4
+
5
+ interface MixinProps {
6
+ ref: React.RefCallback<Element>;
7
+ className: string;
8
+ }
9
+
10
+ export default abstract class Mixin implements ClassNameProvider {
11
+ static readonly scrollableTarget: StaticAttributeMixin;
12
+
13
+ static readonly use(ref: React.ForwardedRef<any>, ...args: (Mixin | string)[]): MixinProps;
14
+ static readonly use(ref: Mixin, ...args: (Mixin | string)[]): MixinProps;
15
+ static readonly use(...args: Mixin[]): MixinProps;
16
+
17
+ /**
18
+ * @private Internal use.
19
+ */
20
+ next(): this;
21
+ /**
22
+ * @private Internal use.
23
+ */
24
+ getRef(): React.RefCallback<Element>;
25
+ /**
26
+ * @private Internal use.
27
+ */
28
+ getClassNames(): ClassName[];
29
+ /**
30
+ * @private Internal use.
31
+ */
32
+ getCustomAttributes(): Zeta.Dictionary<string>;
33
+
34
+ /**
35
+ * Watches a property on the object.
36
+ * @param prop Property name.
37
+ * @param handler Callback to be fired and the property is changed.
38
+ * @param fireInit Optionally fire the handler immediately.
39
+ */
40
+ watch<P extends keyof this>(prop: P, handler?: (this: this, newValue: this[P], oldValue: this[P], prop: P, obj: this) => void, fireInit?: boolean): Zeta.UnregisterCallback;
41
+ /**
42
+ * Watches a property and resolves when the property is changed.
43
+ * @param prop Property name.
44
+ * @param handler Callback to be fired when the property is changed.
45
+ */
46
+ watchOnce<P extends keyof this>(prop: P, handler?: (this: this, newValue: this[P], oldValue: this[P], prop: P, obj: this) => void): Promise<this[P]>;
47
+ }
@@ -0,0 +1,61 @@
1
+ import { classNames } from "zeta-dom-react";
2
+ import { combineFn, define, definePrototype, each, extend, makeArray, noop, watchable } from "../include/zeta-dom/util.js";
3
+ import StaticAttributeMixin from "./StaticAttributeMixin.js";
4
+
5
+ export default function Mixin() {
6
+ }
7
+
8
+ definePrototype(Mixin, {
9
+ next: function () {
10
+ },
11
+ getRef: function () {
12
+ return noop;
13
+ },
14
+ getClassNames: function () {
15
+ return [];
16
+ },
17
+ getCustomAttributes: function () {
18
+ return {};
19
+ }
20
+ });
21
+ watchable(Mixin.prototype);
22
+
23
+ define(Mixin, {
24
+ get scrollableTarget() {
25
+ return new StaticAttributeMixin({ 'scrollable-target': '' });
26
+ },
27
+ use: function () {
28
+ const args = makeArray(arguments);
29
+ const ref = args[0];
30
+ const props = {};
31
+ const mixins = args.filter(function (v) {
32
+ return v instanceof Mixin;
33
+ });
34
+ const refs = mixins.map(function (v) {
35
+ return v.getRef();
36
+ });
37
+ if (ref && !(ref instanceof Mixin)) {
38
+ if (typeof ref !== 'function') {
39
+ refs.push(function (v) {
40
+ ref.current = v;
41
+ });
42
+ } else {
43
+ refs.push(ref);
44
+ }
45
+ args.shift();
46
+ } else if (!ref) {
47
+ args.shift();
48
+ }
49
+ each(mixins, function (i, v) {
50
+ extend(props, v.getCustomAttributes());
51
+ });
52
+ extend(props, {
53
+ ref: combineFn(refs),
54
+ className: classNames.apply(null, args)
55
+ });
56
+ each(mixins, function (i, v) {
57
+ v.next();
58
+ });
59
+ return props;
60
+ }
61
+ });
@@ -0,0 +1,17 @@
1
+ import ClassNameMixin from "./ClassNameMixin";
2
+ import StaticAttributeMixin from "./StaticAttributeMixin";
3
+
4
+ export interface ScrollableMixinOptions {
5
+ direction?: 'x-only' | 'y-only' | 'both';
6
+ handle?: 'auto' | 'scrollbar' | 'content';
7
+ paged?: 'always' | 'landscape' | 'portrait';
8
+ pagedItemSelector?: string;
9
+ }
10
+
11
+ export default class ScrollableMixin extends ClassNameMixin {
12
+ readonly target: StaticAttributeMixin;
13
+ readonly pageIndex: number;
14
+
15
+ withOptions(options?: ScrollableMixinOptions): this;
16
+ onPageIndexChanged(callback: (index: number) => void): Zeta.UnregisterCallback;
17
+ }
@@ -0,0 +1,46 @@
1
+ import { defineAliasProperty, definePrototype, extend } from "../include/zeta-dom/util.js";
2
+ import { app } from "../app.js";
3
+ import Mixin from "./Mixin.js";
4
+ import ClassNameMixin from "./ClassNameMixin.js";
5
+
6
+ const ScrollableMixinSuper = ClassNameMixin.prototype;
7
+
8
+ export default function ScrollableMixin() {
9
+ ClassNameMixin.call(this, ['scrollable-x', 'scrollable-x-l', 'scrollable-x-r', 'scrollable-y', 'scrollable-y-d', 'scrollable-y-u']);
10
+ this.target = Mixin.scrollableTarget;
11
+ this.pageIndex = 0;
12
+ }
13
+
14
+ definePrototype(ScrollableMixin, ClassNameMixin, {
15
+ withOptions: function (options) {
16
+ this.options = options;
17
+ return this;
18
+ },
19
+ getCustomAttributes: function () {
20
+ var options = this.options || {};
21
+ return extend({}, ScrollableMixinSuper.getCustomAttributes.call(this), {
22
+ 'scrollable': [options.direction || 'both', options.handle || 'auto'].join(' '),
23
+ }, options.paged && {
24
+ 'var': '{ pageIndex: 0 }',
25
+ 'scroller-snap-page': options.paged,
26
+ 'scroller-page': options.pagedItemSelector,
27
+ 'scroller-state': 'pageIndex'
28
+ });
29
+ },
30
+ onPageIndexChanged: function (callback) {
31
+ return this.watch('pageIndex', callback);
32
+ },
33
+ initElement: function (element, state) {
34
+ var self = this;
35
+ app.on(element, 'statechange', function (e) {
36
+ if ('pageIndex' in e.newValues) {
37
+ extend(self, { pageIndex: e.newValues.pageIndex });
38
+ }
39
+ }, true);
40
+ },
41
+ clone: function () {
42
+ var mixin = ScrollableMixinSuper.clone.call(this);
43
+ defineAliasProperty(mixin, 'pageIndex', this);
44
+ return mixin;
45
+ }
46
+ });
@@ -0,0 +1,23 @@
1
+ import React from "react";
2
+ import Mixin from "./Mixin";
3
+
4
+ interface MixinState {
5
+ element: HTMLElement | null;
6
+ ref?: MixinRef;
7
+ }
8
+
9
+ export interface MixinRef<T extends StatefulMixin = StatefulMixin> { }
10
+
11
+ export default abstract class StatefulMixin extends Mixin {
12
+ get ref(): MixinRef<typeof this>;
13
+ protected get state(): MixinState;
14
+
15
+ reset(): this;
16
+ next(): this;
17
+ getRef(): React.RefCallback<HTMLElement>;
18
+ elements(): HTMLElement[];
19
+
20
+ protected initState(): MixinState;
21
+ protected initElement(element: HTMLElement, state: MixinState): void;
22
+ protected clone(): this;
23
+ }
@@ -0,0 +1,71 @@
1
+ import { definePrototype, inherit, randomId, values } from "../include/zeta-dom/util.js";
2
+ import Mixin from "./Mixin.js";
3
+
4
+ function MixinRefImpl(mixin) {
5
+ this.mixin = mixin;
6
+ }
7
+
8
+ definePrototype(MixinRefImpl, {
9
+ getMixin: function () {
10
+ return this.mixin;
11
+ }
12
+ });
13
+
14
+ export default function StatefulMixin() {
15
+ Mixin.call(this);
16
+ this.states = {};
17
+ this.prefix = '';
18
+ this.counter = 0;
19
+ }
20
+
21
+ definePrototype(StatefulMixin, Mixin, {
22
+ get ref() {
23
+ const state = this.state;
24
+ this.next();
25
+ return state.ref || (state.ref = new MixinRefImpl(this.clone()));
26
+ },
27
+ get state() {
28
+ const self = this;
29
+ const key = self.prefix + self.counter;
30
+ return self.states[key] || (self.states[key] = self.initState());
31
+ },
32
+ reset: function () {
33
+ this.counter = 0;
34
+ return this;
35
+ },
36
+ next: function () {
37
+ this.counter++;
38
+ return this;
39
+ },
40
+ getRef: function () {
41
+ const self = this;
42
+ const state = self.state;
43
+ return function (current) {
44
+ if (current !== state.element) {
45
+ state.element = current;
46
+ if (current) {
47
+ self.initElement(current, state);
48
+ }
49
+ }
50
+ };
51
+ },
52
+ elements: function () {
53
+ return values(this.states).map(function (v) {
54
+ return v.element;
55
+ }).filter(function (v) {
56
+ return v;
57
+ });
58
+ },
59
+ initState: function () {
60
+ return { element: null };
61
+ },
62
+ initElement: function (element, state) {
63
+ },
64
+ clone: function () {
65
+ return inherit(Object.getPrototypeOf(this), {
66
+ states: this.states,
67
+ prefix: randomId() + '.',
68
+ counter: 0
69
+ });
70
+ }
71
+ });
@@ -0,0 +1,5 @@
1
+ import Mixin from "./Mixin";
2
+
3
+ export default class StaticAttributeMixin extends Mixin {
4
+ constructor(attributes: Record<string, string> = {});
5
+ }
@@ -0,0 +1,13 @@
1
+ import { definePrototype, extend } from "../include/zeta-dom/util.js";
2
+ import Mixin from "./Mixin.js";
3
+
4
+ export default function StaticAttributeMixin(attributes) {
5
+ Mixin.call(this);
6
+ this.attributes = attributes || {};
7
+ }
8
+
9
+ definePrototype(StaticAttributeMixin, Mixin, {
10
+ getCustomAttributes: function () {
11
+ return extend({}, this.attributes);
12
+ }
13
+ });
package/package.json ADDED
@@ -0,0 +1,46 @@
1
+ {
2
+ "name": "brew-js-react",
3
+ "version": "0.1.0-beta",
4
+ "description": "",
5
+ "type": "module",
6
+ "main": "index.js",
7
+ "types": "index.d.ts",
8
+ "scripts": {
9
+ "build": "webpack",
10
+ "version": "npm run build && git add -A dist",
11
+ "release": "node ./npm-publish.cjs"
12
+ },
13
+ "author": "misonou",
14
+ "license": "ISC",
15
+ "repository": "github:misonou/brew-react",
16
+ "dependencies": {
17
+ "brew-js": "^0.2.1",
18
+ "react": "^16.14.0",
19
+ "react-dom": "^16.14.0",
20
+ "zeta-dom": "^0.1.13",
21
+ "zeta-dom-react": "^0.1.0-beta"
22
+ },
23
+ "devDependencies": {
24
+ "@babel/core": "^7.12.3",
25
+ "@babel/preset-env": "^7.12.1",
26
+ "@jest/globals": "^26.6.2",
27
+ "@types/jest": "^26.0.15",
28
+ "babel-loader": "^8.2.1",
29
+ "clean-webpack-plugin": "^4.0.0",
30
+ "cross-env": "^7.0.2",
31
+ "jest": "^27.0.6",
32
+ "ncp": "^2.0.0",
33
+ "webpack": "^5.3.0",
34
+ "webpack-cli": "^4.1.0"
35
+ },
36
+ "keywords": [
37
+ "html",
38
+ "dom",
39
+ "ui",
40
+ "router",
41
+ "render",
42
+ "scaffolding",
43
+ "react",
44
+ "spa"
45
+ ]
46
+ }
package/view.d.ts ADDED
@@ -0,0 +1,33 @@
1
+ export type ViewComponentRootProps = React.DetailedHTMLProps<React.HTMLAttributes<HTMLDivElement>, HTMLDivElement>;
2
+ export type ViewComponent<P> = React.FC<P>;
3
+
4
+ /**
5
+ * Registers view component with specific route paramters.
6
+ * Route parameters will be matched against current route state by {@link renderView}.
7
+ * @param factory A callback that returns a promise resolving a React component, typically using async `import`.
8
+ * @param params A dictionary containing route parameters.
9
+ */
10
+ export function registerView<P>(factory: () => Promise<{ default: React.ComponentType<P> }>, params: Zeta.Dictionary<string>): ViewComponent<P>;
11
+
12
+ /**
13
+ * Renders view by matching current route state against registered route parameters of each supplied views.
14
+ * @param args A list of view components created by {@link registerView}.
15
+ */
16
+ export function renderView(...args: ViewComponent<any>[]): JSX.Element;
17
+
18
+ /**
19
+ * Renders view by matching current route state against registered route parameters of each supplied views.
20
+ * @param props Optional parameters passed to the root element rendered by the function.
21
+ * @param args A list of view components created by {@link registerView}.
22
+ */
23
+ export function renderView(props: ViewComponentRootProps, ...args: ViewComponent<any>[]): JSX.Element;
24
+
25
+ /**
26
+ * Returns pathname that will render the specified view.
27
+ * The pathname is resolved using route parameters given to {@link registerView},
28
+ * current route parameters, as well as any supplemeneted route parameters
29
+ * against registered routes in {@link Brew.RouterOptions.routes}.
30
+ * @param view A view component created by {@link registerView}.
31
+ * @param params Extra route parameters that supplements or overrides current route parameters.
32
+ */
33
+ export function linkTo(view: ViewComponent<any>, params?: Zeta.Dictionary<string>): string;