@oscarpalmer/abydon 0.14.0 → 0.15.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/abydon.full.js +229 -108
- package/dist/fragment.js +32 -11
- package/dist/fragments.js +74 -0
- package/dist/helpers/dom.js +1 -1
- package/dist/helpers/index.js +4 -1
- package/dist/index.js +5 -1
- package/dist/node/index.js +7 -2
- package/dist/node/value.js +44 -39
- package/dist/parse.js +6 -3
- package/package.json +2 -2
- package/src/fragment.ts +55 -20
- package/src/fragments.ts +134 -0
- package/src/helpers/index.ts +10 -0
- package/src/index.ts +18 -4
- package/src/models.ts +10 -1
- package/src/node/index.ts +12 -2
- package/src/node/value.ts +25 -3
- package/types/fragment.d.ts +23 -3
- package/types/fragments.d.ts +13 -0
- package/types/helpers/index.d.ts +2 -0
- package/types/index.d.ts +5 -1
- package/types/models.d.ts +16 -3
package/src/node/value.ts
CHANGED
|
@@ -105,6 +105,22 @@ function removeFragments(fragments: Fragment[] | undefined): void {
|
|
|
105
105
|
}
|
|
106
106
|
}
|
|
107
107
|
|
|
108
|
+
function replaceText(
|
|
109
|
+
item: FragmentItem,
|
|
110
|
+
comment: Comment,
|
|
111
|
+
isNullable: boolean,
|
|
112
|
+
): void {
|
|
113
|
+
let to: ChildNode[];
|
|
114
|
+
|
|
115
|
+
if (isNullable) {
|
|
116
|
+
to = [comment];
|
|
117
|
+
} else {
|
|
118
|
+
to = item.text == null ? [] : [item.text];
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
replaceNodes(item.nodes ?? [], to);
|
|
122
|
+
}
|
|
123
|
+
|
|
108
124
|
function setArray(
|
|
109
125
|
item: FragmentItem,
|
|
110
126
|
comment: Comment,
|
|
@@ -213,7 +229,11 @@ function setReactiveValueForArray(
|
|
|
213
229
|
item.fragments = typeof result === 'boolean' ? undefined : result?.fragments;
|
|
214
230
|
|
|
215
231
|
if (typeof result === 'boolean') {
|
|
216
|
-
|
|
232
|
+
if (result) {
|
|
233
|
+
item.nodes = item.text == null ? [] : [item.text];
|
|
234
|
+
} else {
|
|
235
|
+
item.nodes = undefined;
|
|
236
|
+
}
|
|
217
237
|
} else {
|
|
218
238
|
item.nodes = result?.nodes;
|
|
219
239
|
}
|
|
@@ -249,7 +269,7 @@ function setText(
|
|
|
249
269
|
let result = false;
|
|
250
270
|
|
|
251
271
|
if (item.nodes != null) {
|
|
252
|
-
|
|
272
|
+
replaceText(item, comment, isNullable);
|
|
253
273
|
|
|
254
274
|
result = !isNullable;
|
|
255
275
|
} else if (isNullable && comment.parentNode == null) {
|
|
@@ -264,5 +284,7 @@ function setText(
|
|
|
264
284
|
|
|
265
285
|
removeFragments(item.fragments);
|
|
266
286
|
|
|
267
|
-
|
|
287
|
+
if (result) {
|
|
288
|
+
return item.text == null ? [] : [item.text];
|
|
289
|
+
}
|
|
268
290
|
}
|
package/types/fragment.d.ts
CHANGED
|
@@ -1,18 +1,38 @@
|
|
|
1
|
+
import type { FragmentConfiguration } from './models';
|
|
1
2
|
export declare class Fragment {
|
|
2
3
|
#private;
|
|
4
|
+
/**
|
|
5
|
+
* Fragment identifier
|
|
6
|
+
*/
|
|
3
7
|
get identifier(): unknown;
|
|
4
8
|
constructor(strings: TemplateStringsArray, expressions: unknown[]);
|
|
5
9
|
/**
|
|
6
|
-
*
|
|
10
|
+
* Append the fragment to the given element
|
|
11
|
+
* @param element Element to append to
|
|
7
12
|
*/
|
|
8
13
|
appendTo(element: Element): void;
|
|
9
14
|
/**
|
|
10
|
-
*
|
|
15
|
+
* Configure the fragment
|
|
16
|
+
* @param configuration Configuration options
|
|
17
|
+
* @returns Fragment
|
|
18
|
+
*/
|
|
19
|
+
configure(configuration: FragmentConfiguration): Fragment;
|
|
20
|
+
/**
|
|
21
|
+
* Get a list of the fragment's nodes
|
|
22
|
+
* @returns List of nodes
|
|
11
23
|
*/
|
|
12
24
|
get(): ChildNode[];
|
|
25
|
+
/**
|
|
26
|
+
* Set an identifier for the fragment
|
|
27
|
+
*
|
|
28
|
+
* _An identifier can be used to uniquely identify a fragment,
|
|
29
|
+
* which helps prevent re-rendering in certain scenarios._
|
|
30
|
+
* @param identifier Identifier
|
|
31
|
+
* @returns Fragment
|
|
32
|
+
*/
|
|
13
33
|
identify(identifier: unknown): Fragment;
|
|
14
34
|
/**
|
|
15
|
-
*
|
|
35
|
+
* Remove the fragment from the DOM
|
|
16
36
|
*/
|
|
17
37
|
remove(): void;
|
|
18
38
|
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { type ReactiveArray } from '@oscarpalmer/mora';
|
|
2
|
+
import type { Fragment } from './fragment';
|
|
3
|
+
import type { FragmentsState } from './models';
|
|
4
|
+
export declare class Fragments {
|
|
5
|
+
#private;
|
|
6
|
+
/**
|
|
7
|
+
* Fragment items
|
|
8
|
+
*/
|
|
9
|
+
get items(): ReactiveArray<Fragment>;
|
|
10
|
+
constructor(items: ReactiveArray<unknown>, identify: (item: unknown) => unknown, fragment: (item: unknown) => Fragment);
|
|
11
|
+
}
|
|
12
|
+
export declare function handleFragments(item: Fragments | FragmentsState, remove: boolean): void;
|
|
13
|
+
export declare function initializeFragments(state: FragmentsState): void;
|
package/types/helpers/index.d.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
1
|
import type { Fragment } from '../fragment';
|
|
2
|
+
import type { Fragments } from '../fragments';
|
|
2
3
|
export declare function compareArrays(first: unknown[], second: unknown[]): 'added' | 'dissimilar' | 'removed';
|
|
3
4
|
export declare function isFragment(value: unknown): value is Fragment;
|
|
5
|
+
export declare function isFragments(value: unknown): value is Fragments;
|
package/types/index.d.ts
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
import '@oscarpalmer/mora';
|
|
2
|
+
import type { ReactiveArray } from '@oscarpalmer/mora';
|
|
2
3
|
import { Fragment } from './fragment';
|
|
3
|
-
|
|
4
|
+
import { Fragments } from './fragments';
|
|
5
|
+
export declare function fragments<Item>(array: ReactiveArray<Item>, identify: (item: Item) => unknown, fragment: (item: Item) => Fragment): Fragments;
|
|
6
|
+
export declare function html(strings: TemplateStringsArray, ...values: unknown[]): unknown;
|
|
4
7
|
export * from '@oscarpalmer/mora';
|
|
5
8
|
export type { Fragment } from './fragment';
|
|
9
|
+
export type { Fragments } from './fragments';
|
package/types/models.d.ts
CHANGED
|
@@ -1,16 +1,29 @@
|
|
|
1
|
-
import type { Reactive } from '@oscarpalmer/mora';
|
|
1
|
+
import type { Reactive, ReactiveArray, Unsubscribe } from '@oscarpalmer/mora';
|
|
2
2
|
import type { Fragment } from './fragment';
|
|
3
|
+
export type FragmentConfiguration = {
|
|
4
|
+
identifier?: unknown;
|
|
5
|
+
ignoreCache?: boolean;
|
|
6
|
+
};
|
|
3
7
|
export type FragmentData = {
|
|
4
8
|
expressions: unknown[];
|
|
5
|
-
identifier?: unknown;
|
|
6
9
|
items: FragmentItem[];
|
|
7
10
|
mora: MoraData;
|
|
8
11
|
strings: TemplateStringsArray;
|
|
12
|
+
template?: string;
|
|
9
13
|
values: unknown[];
|
|
10
14
|
};
|
|
11
15
|
export type FragmentItem = {
|
|
12
16
|
fragments?: Fragment[];
|
|
13
|
-
nodes
|
|
17
|
+
nodes?: ChildNode[];
|
|
18
|
+
text?: Text;
|
|
19
|
+
};
|
|
20
|
+
export type FragmentsState = {
|
|
21
|
+
array: ReactiveArray<unknown>;
|
|
22
|
+
fragment: (item: unknown) => Fragment;
|
|
23
|
+
identify: (item: unknown) => unknown;
|
|
24
|
+
instances: Record<string, Fragment>;
|
|
25
|
+
mapped: ReactiveArray<Fragment>;
|
|
26
|
+
subscriber: Unsubscribe | undefined;
|
|
14
27
|
};
|
|
15
28
|
type MoraData = {
|
|
16
29
|
subscribers: Set<() => void>;
|