@fluffjs/fluff 0.1.14 → 0.1.15
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/decorators/Pipe.d.ts +5 -1
- package/decorators/Pipe.js +9 -0
- package/index.d.ts +1 -1
- package/index.js +1 -1
- package/package.json +1 -1
- package/runtime/FluffElementImpl.js +2 -1
- package/runtime/TextController.js +2 -3
- package/runtime/tests/TestForTextMarkerCollisionParentComponent.js +3 -1
- package/runtime/tests/TestInterpolationNestedPropertyComponentBase.js +4 -1
- package/runtime/tests/TestPropertyBindingPipeParentComponent.js +1 -0
- package/runtime/tests/TestPropertyUnwrapParentComponent.js +4 -1
- package/runtime/tests/TestWatchNestedPropertyParentComponent.js +4 -1
- package/runtime/tests/createTestInterpolationNestedPropertyComponent.d.ts +1 -1
- package/runtime/tests/createTestInterpolationPipeComponent.d.ts +8 -0
- package/runtime/tests/createTestInterpolationPipeComponent.js +35 -0
- package/runtime/tests/createTestInterpolationPipeWithArgsComponent.d.ts +2 -0
- package/runtime/tests/createTestInterpolationPipeWithArgsComponent.js +35 -0
- package/runtime/tests/typeguards.d.ts +20 -0
- package/runtime/tests/typeguards.js +18 -0
package/decorators/Pipe.d.ts
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
|
-
|
|
1
|
+
interface PipeInstance {
|
|
2
|
+
transform: (value: unknown, ...args: unknown[]) => unknown;
|
|
3
|
+
}
|
|
4
|
+
type PipeConstructor = (new () => PipeInstance) & {
|
|
2
5
|
__pipeName?: string;
|
|
3
6
|
};
|
|
7
|
+
export declare function getPipeTransform(name: string): ((value: unknown, ...args: unknown[]) => unknown) | undefined;
|
|
4
8
|
export declare function Pipe(name: string): <T extends PipeConstructor>(target: T) => T;
|
|
5
9
|
export interface PipeTransform<TArgs extends unknown[] = unknown[], TReturn = unknown> {
|
|
6
10
|
transform: (value: unknown, ...args: TArgs) => TReturn;
|
package/decorators/Pipe.js
CHANGED
|
@@ -1,6 +1,15 @@
|
|
|
1
|
+
const pipeRegistry = new Map();
|
|
2
|
+
export function getPipeTransform(name) {
|
|
3
|
+
const PipeClass = pipeRegistry.get(name);
|
|
4
|
+
if (!PipeClass)
|
|
5
|
+
return undefined;
|
|
6
|
+
const instance = new PipeClass();
|
|
7
|
+
return (value, ...args) => instance.transform(value, ...args);
|
|
8
|
+
}
|
|
1
9
|
export function Pipe(name) {
|
|
2
10
|
return function (target) {
|
|
3
11
|
target.__pipeName = name;
|
|
12
|
+
pipeRegistry.set(name, target);
|
|
4
13
|
return target;
|
|
5
14
|
};
|
|
6
15
|
}
|
package/index.d.ts
CHANGED
|
@@ -4,7 +4,7 @@ export { HostBinding } from './decorators/HostBinding.js';
|
|
|
4
4
|
export { HostListener } from './decorators/HostListener.js';
|
|
5
5
|
export { Input } from './decorators/Input.js';
|
|
6
6
|
export { Output } from './decorators/Output.js';
|
|
7
|
-
export { Pipe } from './decorators/Pipe.js';
|
|
7
|
+
export { getPipeTransform, Pipe } from './decorators/Pipe.js';
|
|
8
8
|
export type { PipeTransform } from './decorators/Pipe.js';
|
|
9
9
|
export { Reactive } from './decorators/Reactive.js';
|
|
10
10
|
export { ViewChild } from './decorators/ViewChild.js';
|
package/index.js
CHANGED
|
@@ -3,7 +3,7 @@ export { HostBinding } from './decorators/HostBinding.js';
|
|
|
3
3
|
export { HostListener } from './decorators/HostListener.js';
|
|
4
4
|
export { Input } from './decorators/Input.js';
|
|
5
5
|
export { Output } from './decorators/Output.js';
|
|
6
|
-
export { Pipe } from './decorators/Pipe.js';
|
|
6
|
+
export { getPipeTransform, Pipe } from './decorators/Pipe.js';
|
|
7
7
|
export { Reactive } from './decorators/Reactive.js';
|
|
8
8
|
export { ViewChild } from './decorators/ViewChild.js';
|
|
9
9
|
export { Watch } from './decorators/Watch.js';
|
package/package.json
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { getPipeTransform } from '../decorators/Pipe.js';
|
|
1
2
|
import { DomUtils } from '../utils/DomUtils.js';
|
|
2
3
|
import { Property } from '../utils/Property.js';
|
|
3
4
|
import { Publisher } from '../utils/Publisher.js';
|
|
@@ -87,7 +88,7 @@ export class FluffElement extends FluffBase {
|
|
|
87
88
|
return pipe(value, ...args);
|
|
88
89
|
}
|
|
89
90
|
__getPipeFn(name) {
|
|
90
|
-
return this.__pipes[name];
|
|
91
|
+
return this.__pipes[name] ?? getPipeTransform(name);
|
|
91
92
|
}
|
|
92
93
|
__getShadowRoot() {
|
|
93
94
|
return this._shadowRoot;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { getPipeTransform } from '../decorators/Pipe.js';
|
|
1
2
|
import { Property } from '../utils/Property.js';
|
|
2
3
|
import { MarkerController } from './MarkerController.js';
|
|
3
4
|
export class TextController extends MarkerController {
|
|
@@ -44,9 +45,7 @@ export class TextController extends MarkerController {
|
|
|
44
45
|
}
|
|
45
46
|
applyPipe(name, value, args) {
|
|
46
47
|
const pipes = this.host.__pipes;
|
|
47
|
-
|
|
48
|
-
return value;
|
|
49
|
-
const pipeFn = pipes[name];
|
|
48
|
+
const pipeFn = pipes?.[name] ?? getPipeTransform(name);
|
|
50
49
|
if (!pipeFn) {
|
|
51
50
|
console.warn(`Pipe "${name}" not found`);
|
|
52
51
|
return value;
|
|
@@ -3,6 +3,7 @@ import { FluffElement } from '../FluffElementImpl.js';
|
|
|
3
3
|
import { MarkerManager } from '../MarkerManager.js';
|
|
4
4
|
export class TestForTextMarkerCollisionParentComponent extends FluffElement {
|
|
5
5
|
__tags = new Property({ initialValue: ['docs', 'api'], propertyName: 'tags' });
|
|
6
|
+
// TEST STUB: In real apps, __pipes is generated by the CLI in CodeGenerator.ts
|
|
6
7
|
__pipes = {
|
|
7
8
|
lowercase: (v) => String(v)
|
|
8
9
|
.toLowerCase(),
|
|
@@ -29,7 +30,8 @@ export class TestForTextMarkerCollisionParentComponent extends FluffElement {
|
|
|
29
30
|
`;
|
|
30
31
|
this.__setMarkerConfigs(JSON.stringify([
|
|
31
32
|
[0, { type: 'for', iterator: 'tag', iterableExprId: 0, deps: ['tags'], trackBy: 'tag', hasEmpty: false }],
|
|
32
|
-
[
|
|
33
|
+
[
|
|
34
|
+
9,
|
|
33
35
|
{
|
|
34
36
|
type: 'text',
|
|
35
37
|
exprId: 1,
|
|
@@ -3,7 +3,10 @@ import { FluffElement } from '../FluffElement.js';
|
|
|
3
3
|
import { MarkerManager } from '../MarkerManager.js';
|
|
4
4
|
import { TestInterpolationNestedPropertyContainerClass } from './TestInterpolationNestedPropertyContainerClass.js';
|
|
5
5
|
export class TestInterpolationNestedPropertyComponentBase extends FluffElement {
|
|
6
|
-
__hostClass = new Property({
|
|
6
|
+
__hostClass = new Property({
|
|
7
|
+
initialValue: new TestInterpolationNestedPropertyContainerClass(),
|
|
8
|
+
propertyName: 'hostClass'
|
|
9
|
+
});
|
|
7
10
|
get hostClass() {
|
|
8
11
|
const val = this.__hostClass.getValue();
|
|
9
12
|
if (!val) {
|
|
@@ -8,6 +8,7 @@ export class TestPropertyBindingPipeParentComponent extends FluffElement {
|
|
|
8
8
|
set amount(val) {
|
|
9
9
|
this.__amount.setValue(val);
|
|
10
10
|
}
|
|
11
|
+
// TEST STUB: In real apps, __pipes is generated by the CLI in CodeGenerator.ts
|
|
11
12
|
__pipes = {
|
|
12
13
|
double: (v) => (typeof v === 'number' ? v * 2 : 0),
|
|
13
14
|
addSuffix: (v, suffix) => `${String(v)}${String(suffix)}`
|
|
@@ -2,7 +2,10 @@ import { Property } from '../../utils/Property.js';
|
|
|
2
2
|
import { FluffElement } from '../FluffElement.js';
|
|
3
3
|
import { TestPropertyUnwrapContainerClass } from './TestPropertyUnwrapContainerClass.js';
|
|
4
4
|
export class TestPropertyUnwrapParentComponent extends FluffElement {
|
|
5
|
-
__hostClass = new Property({
|
|
5
|
+
__hostClass = new Property({
|
|
6
|
+
initialValue: new TestPropertyUnwrapContainerClass(),
|
|
7
|
+
propertyName: 'hostClass'
|
|
8
|
+
});
|
|
6
9
|
get hostClass() {
|
|
7
10
|
const val = this.__hostClass.getValue();
|
|
8
11
|
if (!val) {
|
|
@@ -2,7 +2,10 @@ import { Property } from '../../utils/Property.js';
|
|
|
2
2
|
import { FluffElement } from '../FluffElement.js';
|
|
3
3
|
import { TestWatchNestedPropertyContainerClass } from './TestWatchNestedPropertyContainerClass.js';
|
|
4
4
|
export class TestWatchNestedPropertyParentComponent extends FluffElement {
|
|
5
|
-
__hostClass = new Property({
|
|
5
|
+
__hostClass = new Property({
|
|
6
|
+
initialValue: new TestWatchNestedPropertyContainerClass(),
|
|
7
|
+
propertyName: 'hostClass'
|
|
8
|
+
});
|
|
6
9
|
get hostClass() {
|
|
7
10
|
const val = this.__hostClass.getValue();
|
|
8
11
|
if (!val) {
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { TestInterpolationNestedPropertyComponentBase } from './TestInterpolationNestedPropertyComponentBase.js';
|
|
2
|
-
export declare function createTestInterpolationNestedPropertyComponent():
|
|
2
|
+
export declare function createTestInterpolationNestedPropertyComponent(): new () => TestInterpolationNestedPropertyComponentBase;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { Property } from '../../utils/Property.js';
|
|
2
|
+
import { FluffElement } from '../FluffElementImpl.js';
|
|
3
|
+
export interface TestInterpolationPipeComponentInstance extends FluffElement {
|
|
4
|
+
message: string;
|
|
5
|
+
__message: Property<string>;
|
|
6
|
+
}
|
|
7
|
+
export type TestInterpolationPipeComponentConstructor = new () => TestInterpolationPipeComponentInstance;
|
|
8
|
+
export declare function createTestInterpolationPipeComponent(): TestInterpolationPipeComponentConstructor;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { Property } from '../../utils/Property.js';
|
|
2
|
+
import { FluffElement } from '../FluffElementImpl.js';
|
|
3
|
+
import { MarkerManager } from '../MarkerManager.js';
|
|
4
|
+
export function createTestInterpolationPipeComponent() {
|
|
5
|
+
class TestComponent extends FluffElement {
|
|
6
|
+
__message = new Property({ initialValue: 'hello world', propertyName: 'message' });
|
|
7
|
+
get message() {
|
|
8
|
+
return this.__message.getValue() ?? '';
|
|
9
|
+
}
|
|
10
|
+
set message(val) {
|
|
11
|
+
this.__message.setValue(val);
|
|
12
|
+
}
|
|
13
|
+
// TEST STUB: In real apps, __pipes is generated by the CLI in CodeGenerator.ts
|
|
14
|
+
__pipes = {
|
|
15
|
+
uppercase: (v) => String(v)
|
|
16
|
+
.toUpperCase(),
|
|
17
|
+
truncate: (v, length) => {
|
|
18
|
+
const str = String(v);
|
|
19
|
+
const len = typeof length === 'number' ? length : 10;
|
|
20
|
+
return str.length > len ? str.slice(0, len) + '...' : str;
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
__render() {
|
|
24
|
+
this.__getShadowRoot().innerHTML = '<span><!--fluff:text:0--><!--/fluff:text:0--></span>';
|
|
25
|
+
this.__setMarkerConfigs(JSON.stringify([
|
|
26
|
+
[0, { type: 'text', exprId: 0, deps: ['message'], pipes: [{ name: 'uppercase', argExprIds: [] }] }]
|
|
27
|
+
]));
|
|
28
|
+
}
|
|
29
|
+
__setupBindings() {
|
|
30
|
+
this.__initializeMarkers(MarkerManager);
|
|
31
|
+
super.__setupBindings();
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
return TestComponent;
|
|
35
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { Property } from '../../utils/Property.js';
|
|
2
|
+
import { FluffElement } from '../FluffElementImpl.js';
|
|
3
|
+
import { MarkerManager } from '../MarkerManager.js';
|
|
4
|
+
export function createTestInterpolationPipeWithArgsComponent() {
|
|
5
|
+
class TestComponentWithArgs extends FluffElement {
|
|
6
|
+
__message = new Property({ initialValue: 'hello world', propertyName: 'message' });
|
|
7
|
+
get message() {
|
|
8
|
+
return this.__message.getValue() ?? '';
|
|
9
|
+
}
|
|
10
|
+
set message(val) {
|
|
11
|
+
this.__message.setValue(val);
|
|
12
|
+
}
|
|
13
|
+
// TEST STUB: In real apps, __pipes is generated by the CLI in CodeGenerator.ts
|
|
14
|
+
__pipes = {
|
|
15
|
+
uppercase: (v) => String(v)
|
|
16
|
+
.toUpperCase(),
|
|
17
|
+
truncate: (v, length) => {
|
|
18
|
+
const str = String(v);
|
|
19
|
+
const len = typeof length === 'number' ? length : 10;
|
|
20
|
+
return str.length > len ? str.slice(0, len) + '...' : str;
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
__render() {
|
|
24
|
+
this.__getShadowRoot().innerHTML = '<span><!--fluff:text:0--><!--/fluff:text:0--></span>';
|
|
25
|
+
this.__setMarkerConfigs(JSON.stringify([
|
|
26
|
+
[0, { type: 'text', exprId: 0, deps: ['message'], pipes: [{ name: 'truncate', argExprIds: [1] }] }]
|
|
27
|
+
]));
|
|
28
|
+
}
|
|
29
|
+
__setupBindings() {
|
|
30
|
+
this.__initializeMarkers(MarkerManager);
|
|
31
|
+
super.__setupBindings();
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
return TestComponentWithArgs;
|
|
35
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { TestLateDefineForColumn } from './TestLateDefineForComponent.js';
|
|
2
|
+
import type { TestTask } from './TestNullInputTextComponent.js';
|
|
3
|
+
export declare function hasItem(t: unknown): t is {
|
|
4
|
+
item: unknown;
|
|
5
|
+
};
|
|
6
|
+
export declare function hasItemName(t: unknown): t is {
|
|
7
|
+
itemName: string;
|
|
8
|
+
};
|
|
9
|
+
export declare function hasTask(t: unknown): t is {
|
|
10
|
+
task: TestTask;
|
|
11
|
+
};
|
|
12
|
+
export declare function isLateDefineForColumn(l: unknown): l is {
|
|
13
|
+
column: TestLateDefineForColumn;
|
|
14
|
+
};
|
|
15
|
+
export declare function hasValue(t: unknown): t is {
|
|
16
|
+
value: string;
|
|
17
|
+
};
|
|
18
|
+
export declare function hasTaskId(e: unknown): e is {
|
|
19
|
+
taskId: number;
|
|
20
|
+
};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export function hasItem(t) {
|
|
2
|
+
return t !== null && typeof t === 'object' && 'item' in t;
|
|
3
|
+
}
|
|
4
|
+
export function hasItemName(t) {
|
|
5
|
+
return t !== null && typeof t === 'object' && 'itemName' in t && typeof t.itemName === 'string';
|
|
6
|
+
}
|
|
7
|
+
export function hasTask(t) {
|
|
8
|
+
return t !== null && typeof t === 'object' && 'task' in t;
|
|
9
|
+
}
|
|
10
|
+
export function isLateDefineForColumn(l) {
|
|
11
|
+
return l !== null && typeof l === 'object' && 'column' in l;
|
|
12
|
+
}
|
|
13
|
+
export function hasValue(t) {
|
|
14
|
+
return t !== null && typeof t === 'object' && 'value' in t && typeof t.value === 'string';
|
|
15
|
+
}
|
|
16
|
+
export function hasTaskId(e) {
|
|
17
|
+
return e !== null && typeof e === 'object' && 'taskId' in e && typeof e.taskId === 'number';
|
|
18
|
+
}
|