Skip to content

Commit cc74e53

Browse files
committed
feat(async-stack): first, here be dragon
1 parent 6d5be33 commit cc74e53

10 files changed

Lines changed: 367 additions & 401 deletions

File tree

.changeset/shiny-ears-work.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@svelte-put/async-stack': major
3+
---
4+
5+
Extracted from core logic of `@svelte-put/noti` and `@svelte-put/modal`

packages/async-stack/CHANGELOG.md

Lines changed: 0 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,2 @@
11
# Changelog
22

3-
## 2.0.0-next.2
4-
5-
### Patch Changes
6-
7-
- [`26bbd81`](https://github.com/vnphanquang/svelte-put/commit/26bbd813c1e65ead04d5d6bcb29b97a34045646b) Thanks [@vnphanquang](https://github.com/vnphanquang)! - sync README.md and installation version in docs page
8-
9-
## 2.0.0-next.1
10-
11-
### Minor Changes
12-
13-
- [#302](https://github.com/vnphanquang/svelte-put/pull/302) [`eb68654`](https://github.com/vnphanquang/svelte-put/commit/eb686548fe22a54bfd3fee2c9826eeaac7b76d80) Thanks [@github-actions](https://github.com/apps/github-actions)! - update Component typing, add `pause` & `resume` proxies on `NotificationController`, and return `resolution` in `resolve`
14-
15-
## 2.0.0-next.0
16-
17-
### Major Changes
18-
19-
- [`796ff16`](https://github.com/vnphanquang/svelte-put/commit/796ff16d4ffad1f7943b6a293e435da2616db6ed) Thanks [@vnphanquang](https://github.com/vnphanquang)! - drop support for Svelte 4 and below. Now using runes for fine-grained reactivity. See [docs page](https://svelte-put.vnphanquang.com/docs/noti) for more information
20-
21-
## 1.1.1
22-
23-
### Patch Changes
24-
25-
- [`5ca7d70`](https://github.com/vnphanquang/svelte-put/commit/5ca7d701a61b6d2f90e7a6b21f644b8ad93fc33e) Thanks [@vnphanquang](https://github.com/vnphanquang)! - restrict to svelte 3 and 4 (not compatible with 5)
26-
27-
## 1.1.0
28-
29-
### Minor Changes
30-
31-
- [#225](https://github.com/vnphanquang/svelte-put/pull/225) [`e050621`](https://github.com/vnphanquang/svelte-put/commit/e0506210da96a0d13a5b899a6c16852dea922725) Thanks [@vnphanquang](https://github.com/vnphanquang)! - rename `PushedNotification` to `NotificationInstance` for better naming consistency
32-
33-
- [#225](https://github.com/vnphanquang/svelte-put/pull/225) [`dc21171`](https://github.com/vnphanquang/svelte-put/commit/dc211715f36b8fbf99b499ab9a2acefc5c7d04cf) Thanks [@vnphanquang](https://github.com/vnphanquang)! - inject `config` prop (`NotificationInstanceConfig`) is now `nofitication` (`NotificationInstance`), to enable better granular access and expose more helpful api to users
34-
35-
- [#225](https://github.com/vnphanquang/svelte-put/pull/225) [`12a321a`](https://github.com/vnphanquang/svelte-put/commit/12a321ab6e2a4c635378953a202ce565c1a64dbc) Thanks [@vnphanquang](https://github.com/vnphanquang)! - support progress store in `NotificationInstance`, allowing pause & resume noti midway
36-
37-
- [#225](https://github.com/vnphanquang/svelte-put/pull/225) [`0b8791f`](https://github.com/vnphanquang/svelte-put/commit/0b8791ff3ca2cfd6cdc7bda565259b6f94b38d92) Thanks [@vnphanquang](https://github.com/vnphanquang)! - export a `Notification` component for easer custom portal building
38-
39-
## 1.0.0
40-
41-
### Major Changes
42-
43-
- [#216](https://github.com/vnphanquang/svelte-put/pull/216) [`64c6352`](https://github.com/vnphanquang/svelte-put/commit/64c63524ac12d22af1ed57f2f988d75b8082721d) Thanks [@vnphanquang](https://github.com/vnphanquang)! - v1 here be dragons

packages/async-stack/src/errors.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ export class NotFoundVariantConfig extends Error {
1212

1313
export class MissingComponentInCustomPush extends Error {
1414
constructor() {
15-
super('Notification custom push must have component property specified');
15+
super('Stack custom push must have component property specified');
1616
}
1717
}
18+

packages/async-stack/src/index.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// Copyright (c) Quang Phan. All rights reserved. Licensed under the MIT license.
22

3-
export { controller, NotificationControllerBuilder } from './notification-controller-builder.js'
4-
export { Notification } from './notification.svelte.js';
5-
export { NotificationController } from './notification-controller.svelte.js';
3+
export { stack, StackBuilder } from './stack-builder.js'
4+
export { StackItem } from './stack-item.svelte.js';
5+
export { Stack } from './stack.svelte.js';
6+
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
import { Stack } from './stack.svelte.js';
2+
3+
/**
4+
* @template {Record<string, import('svelte').Component>} [VariantMap={}]
5+
*/
6+
export class StackBuilder {
7+
/** @type {Record<string, import('./types').StackItemVariantConfig<any, any, any>>} */
8+
#variantConfigMap = {};
9+
10+
/**
11+
* @type {import('./types').StackItemCommonConfig<any, any, any> | undefined}
12+
*/
13+
#init;
14+
15+
/**
16+
* @param {import('./types').StackItemCommonConfig<any, any, any>} [init]
17+
*/
18+
constructor(init) {
19+
this.#init = init;
20+
}
21+
22+
/**
23+
* add config for a stack item variant
24+
* @template Resolved
25+
* @template {string} Variant
26+
* @template {import('svelte').Component} UserComponent
27+
* @param {Variant} variant
28+
* @param {UserComponent | Omit<import('./types').StackItemVariantConfig<Resolved, Variant, UserComponent>, 'variant'>} config
29+
* @returns {StackBuilder<VariantMap & Record<Variant, UserComponent>> }
30+
*/
31+
addVariant(variant, config) {
32+
if ('component' in config) {
33+
this.#variantConfigMap[variant] = /** @type {any} */ ({
34+
...config,
35+
variant,
36+
});
37+
} else {
38+
this.#variantConfigMap[variant] = /** @type {any} */ ({
39+
component: config,
40+
variant,
41+
});
42+
}
43+
return this;
44+
}
45+
46+
/**
47+
* Build the actual stack
48+
* @returns {Stack<VariantMap>}
49+
*/
50+
build() {
51+
return new Stack(/** @type {any} */ (this.#variantConfigMap), this.#init);
52+
}
53+
}
54+
55+
/**
56+
* @param {import('./types').StackItemCommonConfig<any, any, any>} [init]
57+
* @returns {StackBuilder}
58+
*/
59+
export function stack(init) {
60+
return new StackBuilder(init);
61+
}
62+

packages/async-stack/src/stack-controller-builder.js

Lines changed: 0 additions & 61 deletions
This file was deleted.

0 commit comments

Comments
 (0)