@oscarpalmer/abydon 0.15.0 → 0.16.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 +799 -751
- package/dist/constants.js +20 -5
- package/dist/fragment.js +8 -10
- package/dist/fragments.js +3 -2
- package/dist/helpers/dom.js +1 -11
- package/dist/helpers/index.js +11 -4
- package/dist/index.js +2 -2
- package/dist/node/attribute/index.js +14 -14
- package/dist/node/attribute/value.js +19 -13
- package/dist/node/event.js +15 -22
- package/dist/node/index.js +2 -2
- package/dist/node/value.js +5 -5
- package/dist/parse.js +9 -1
- package/package.json +13 -15
- package/src/constants.ts +30 -10
- package/src/fragment.ts +12 -24
- package/src/fragments.ts +3 -5
- package/src/helpers/dom.ts +1 -20
- package/src/helpers/index.ts +18 -15
- package/src/index.ts +14 -10
- package/src/models.ts +10 -1
- package/src/node/attribute/index.ts +22 -21
- package/src/node/attribute/value.ts +44 -37
- package/src/node/event.ts +26 -33
- package/src/node/index.ts +6 -18
- package/src/node/value.ts +15 -46
- package/src/parse.ts +15 -17
- package/types/constants.d.ts +12 -4
- package/types/index.d.ts +12 -1
- package/types/models.d.ts +10 -1
- package/types/node/attribute/index.d.ts +1 -2
- package/types/node/attribute/value.d.ts +1 -2
- package/types/node/event.d.ts +1 -3
package/src/parse.ts
CHANGED
|
@@ -1,11 +1,8 @@
|
|
|
1
1
|
import {isNullableOrWhitespace} from '@oscarpalmer/atoms/is';
|
|
2
|
+
import {EXPRESSION_ABYDON_ATTRIBUTE_FULL} from './constants';
|
|
2
3
|
import type {FragmentData} from './models';
|
|
3
4
|
|
|
4
|
-
function handleExpression(
|
|
5
|
-
data: FragmentData,
|
|
6
|
-
prefix: string,
|
|
7
|
-
expression: unknown,
|
|
8
|
-
): string {
|
|
5
|
+
function handleExpression(data: FragmentData, prefix: string, expression: unknown): string {
|
|
9
6
|
if (Array.isArray(expression)) {
|
|
10
7
|
const {length} = expression;
|
|
11
8
|
|
|
@@ -18,13 +15,8 @@ function handleExpression(
|
|
|
18
15
|
return `${prefix}${expressions}`;
|
|
19
16
|
}
|
|
20
17
|
|
|
21
|
-
if (
|
|
22
|
-
|
|
23
|
-
(typeof expression === 'object' && expression != null)
|
|
24
|
-
) {
|
|
25
|
-
const index = data.values.push(expression) - 1;
|
|
26
|
-
|
|
27
|
-
return `${prefix}<!--abydon.${index}-->`;
|
|
18
|
+
if (typeof expression === 'function' || (typeof expression === 'object' && expression != null)) {
|
|
19
|
+
return transformExpression(prefix, data.values.push(expression) - 1);
|
|
28
20
|
}
|
|
29
21
|
|
|
30
22
|
return isNullableOrWhitespace(expression) ? prefix : `${prefix}${expression}`;
|
|
@@ -40,15 +32,21 @@ export function parse(data: FragmentData): string {
|
|
|
40
32
|
data.template = '';
|
|
41
33
|
|
|
42
34
|
for (let index = 0; index < length; index += 1) {
|
|
43
|
-
data.template += handleExpression(
|
|
44
|
-
data,
|
|
45
|
-
data.strings[index],
|
|
46
|
-
data.expressions[index],
|
|
47
|
-
);
|
|
35
|
+
data.template += handleExpression(data, data.strings[index], data.expressions[index]);
|
|
48
36
|
}
|
|
49
37
|
|
|
38
|
+
data.template = data.template.replaceAll(EXPRESSION_ABYDON_ATTRIBUTE_FULL, transformAttribute);
|
|
39
|
+
|
|
50
40
|
data.expressions = [];
|
|
51
41
|
data.strings = [] as never;
|
|
52
42
|
|
|
53
43
|
return data.template;
|
|
54
44
|
}
|
|
45
|
+
|
|
46
|
+
function transformAttribute(_: string, name: string, index: string): string {
|
|
47
|
+
return `_${name}="@abydon.${index}@"`;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
function transformExpression(prefix: string, index: number): string {
|
|
51
|
+
return `${prefix}<!--abydon.${index}-->`;
|
|
52
|
+
}
|
package/types/constants.d.ts
CHANGED
|
@@ -1,9 +1,17 @@
|
|
|
1
|
-
export declare const ABORT_CONTROLLERS: WeakMap<HTMLOrSVGElement, AbortController>;
|
|
2
1
|
export declare const ATTRIBUTE_CLASS_PREFIX_LENGTH = 6;
|
|
2
|
+
export declare const EVENT_DEFAULTS: Record<string, string>;
|
|
3
|
+
export declare const EXPRESSION_ABYDON_ATTRIBUTE_FULL: RegExp;
|
|
4
|
+
export declare const EXPRESSION_ABYDON_ATTRIBUTE_PREFIX: RegExp;
|
|
5
|
+
export declare const EXPRESSION_ABYDON_CONTENT: RegExp;
|
|
3
6
|
export declare const EXPRESSION_ATTRIBUTE_CLASS: RegExp;
|
|
4
7
|
export declare const EXPRESSION_ATTRIBUTE_STYLE_FULL: RegExp;
|
|
5
8
|
export declare const EXPRESSION_ATTRIBUTE_STYLE_PREFIX: RegExp;
|
|
6
|
-
export declare const
|
|
7
|
-
export declare const EXPRESSION_COMMENT_CONTENT: RegExp;
|
|
9
|
+
export declare const EXPRESSION_EVENT_CHANGE_TYPES: RegExp;
|
|
8
10
|
export declare const EXPRESSION_EVENT_NAME: RegExp;
|
|
9
|
-
export declare const
|
|
11
|
+
export declare const EXPRESSION_EVENT_OPTIONS_ACTIVE: RegExp;
|
|
12
|
+
export declare const EXPRESSION_EVENT_OPTIONS_CAPTURE: RegExp;
|
|
13
|
+
export declare const EXPRESSION_EVENT_OPTIONS_ONCE: RegExp;
|
|
14
|
+
export declare const EXPRESSION_EVENT_PREFIX: RegExp;
|
|
15
|
+
export declare const EXPRESSION_PERIOD: RegExp;
|
|
16
|
+
export declare const NAME_FRAGMENT = "$fragment";
|
|
17
|
+
export declare const NAME_FRAGMENTS = "$fragments";
|
package/types/index.d.ts
CHANGED
|
@@ -2,8 +2,19 @@ import '@oscarpalmer/mora';
|
|
|
2
2
|
import type { ReactiveArray } from '@oscarpalmer/mora';
|
|
3
3
|
import { Fragment } from './fragment';
|
|
4
4
|
import { Fragments } from './fragments';
|
|
5
|
+
/**
|
|
6
|
+
* Create Fragments from a reactive array
|
|
7
|
+
* @param array Reactive array
|
|
8
|
+
* @param identify Function to identify item
|
|
9
|
+
* @param fragment Function to create fragment from item
|
|
10
|
+
* @returns Fragments
|
|
11
|
+
*/
|
|
5
12
|
export declare function fragments<Item>(array: ReactiveArray<Item>, identify: (item: Item) => unknown, fragment: (item: Item) => Fragment): Fragments;
|
|
6
|
-
|
|
13
|
+
/**
|
|
14
|
+
* Create Fragment from a template
|
|
15
|
+
* @returns Fragment
|
|
16
|
+
*/
|
|
17
|
+
export declare function html(template: TemplateStringsArray, ...values: unknown[]): Fragment;
|
|
7
18
|
export * from '@oscarpalmer/mora';
|
|
8
19
|
export type { Fragment } from './fragment';
|
|
9
20
|
export type { Fragments } from './fragments';
|
package/types/models.d.ts
CHANGED
|
@@ -1,8 +1,17 @@
|
|
|
1
1
|
import type { Reactive, ReactiveArray, Unsubscribe } from '@oscarpalmer/mora';
|
|
2
2
|
import type { Fragment } from './fragment';
|
|
3
3
|
export type FragmentConfiguration = {
|
|
4
|
+
/**
|
|
5
|
+
* Should the template be cached? _(defaults to `true`)_
|
|
6
|
+
*/
|
|
7
|
+
cache?: boolean;
|
|
8
|
+
/**
|
|
9
|
+
* Identifier for the fragment
|
|
10
|
+
*
|
|
11
|
+
* _(An identifier can be used to uniquely identify a fragment,
|
|
12
|
+
* which helps prevent re-rendering in certain scenarios)_
|
|
13
|
+
*/
|
|
4
14
|
identifier?: unknown;
|
|
5
|
-
ignoreCache?: boolean;
|
|
6
15
|
};
|
|
7
16
|
export type FragmentData = {
|
|
8
17
|
expressions: unknown[];
|
|
@@ -1,3 +1,2 @@
|
|
|
1
|
-
import type { HTMLOrSVGElement } from '@oscarpalmer/toretto/models';
|
|
2
1
|
import type { FragmentData } from '../../models';
|
|
3
|
-
export declare function mapAttributes(data: FragmentData, element:
|
|
2
|
+
export declare function mapAttributes(data: FragmentData, element: HTMLElement | SVGElement): void;
|
|
@@ -1,3 +1,2 @@
|
|
|
1
|
-
import type { HTMLOrSVGElement } from '@oscarpalmer/toretto/models';
|
|
2
1
|
import type { FragmentData } from '../../models';
|
|
3
|
-
export declare function setAttribute(data: FragmentData, element:
|
|
2
|
+
export declare function setAttribute(data: FragmentData, element: HTMLElement | SVGElement, name: string, value: unknown): void;
|
package/types/node/event.d.ts
CHANGED
|
@@ -1,3 +1 @@
|
|
|
1
|
-
|
|
2
|
-
export declare function mapEvent(element: HTMLOrSVGElement, name: string, value: unknown): void;
|
|
3
|
-
export declare function removeEvents(element: HTMLOrSVGElement): void;
|
|
1
|
+
export declare function mapEvent(element: HTMLElement | SVGElement, name: string, value: unknown): void;
|