ripple 0.4.0 → 0.4.2
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/CHANGELOG.md +82 -0
- package/package.json +3 -2
- package/src/constants.js +4 -0
- package/src/jsx-runtime.d.ts +12 -2
- package/src/runtime/internal/client/constants.js +6 -0
- package/src/runtime/internal/client/for.js +224 -50
- package/src/runtime/internal/client/hydration.js +0 -16
- package/src/runtime/internal/client/index.js +2 -2
- package/src/runtime/internal/client/operations.js +1 -2
- package/src/runtime/internal/client/render.js +42 -4
- package/src/runtime/internal/client/runtime.js +45 -2
- package/src/runtime/internal/server/index.js +11 -6
- package/tests/client/basic/basic.attributes.test.tsrx +37 -0
- package/tests/client/compiler/compiler.basic.test.tsrx +2 -2
- package/tests/client/for-item.test.tsrx +404 -0
- package/tests/hydration/compiled/client/basic.js +29 -55
- package/tests/hydration/compiled/client/events.js +80 -67
- package/tests/hydration/compiled/client/for.js +95 -80
- package/tests/hydration/compiled/client/fragment-cursor.js +412 -344
- package/tests/hydration/compiled/client/head.js +4 -7
- package/tests/hydration/compiled/client/html.js +40 -64
- package/tests/hydration/compiled/client/if-children.js +30 -34
- package/tests/hydration/compiled/client/if-fragment-controlflow.js +7 -7
- package/tests/hydration/compiled/client/if.js +4 -4
- package/tests/hydration/compiled/client/mixed-control-flow.js +20 -50
- package/tests/hydration/compiled/client/nested-control-flow.js +97 -185
- package/tests/hydration/compiled/client/portal.js +2 -2
- package/tests/hydration/compiled/client/reactivity.js +17 -31
- package/tests/hydration/compiled/client/streaming.js +4 -8
- package/tests/hydration/compiled/client/typed-text.js +4 -15
- package/tests/hydration/compiled/server/events.js +5 -53
- package/tests/hydration/compiled/server/for.js +1 -9
- package/tests/hydration/compiled/server/fragment-cursor.js +36 -324
- package/tests/server/basic.attributes.test.tsrx +28 -0
- package/tests/server/basic.test.tsrx +23 -0
- package/tests/utils/jsx-runtime-types.test.js +67 -2
- package/tests/utils/tracked-types.test.js +117 -0
- package/types/index.d.ts +7 -8
- package/tests/client/compiler/__snapshots__/compiler.assignments.test.rsrx.snap +0 -12
- package/tests/client/compiler/__snapshots__/compiler.typescript.test.rsrx.snap +0 -46
|
@@ -43,6 +43,68 @@ function create_service(source, automatic) {
|
|
|
43
43
|
}
|
|
44
44
|
|
|
45
45
|
describe('Ripple JSX types', () => {
|
|
46
|
+
it.each([true, false])('checks CSS property values (automatic runtime: %s)', (automatic) => {
|
|
47
|
+
const source = `
|
|
48
|
+
import type { CSSProperties, Ripple } from 'ripple';
|
|
49
|
+
import type { CSSProperties as RuntimeCSSProperties } from 'ripple/jsx-runtime';
|
|
50
|
+
|
|
51
|
+
const styles = {
|
|
52
|
+
width: '24rem', height: '50%', margin: 0, padding: '1em',
|
|
53
|
+
maxWidth: 'calc(100% - 2rem)', minWidth: 'var(--min-width)',
|
|
54
|
+
opacity: 0.5, lineHeight: 1.5, zIndex: 2, flexGrow: 1,
|
|
55
|
+
fontSizeAdjust: 0.5, shapeImageThreshold: 0.5, mathDepth: 2, scale: 1.5,
|
|
56
|
+
'font-size': '1rem', 'line-height': 1.5, 'border-width': 0,
|
|
57
|
+
WebkitLineClamp: 2, '-webkit-line-clamp': 2,
|
|
58
|
+
transitionDuration: '200ms',
|
|
59
|
+
'--space': '1rem', '--scale': 2,
|
|
60
|
+
} satisfies CSSProperties;
|
|
61
|
+
const namespaced: Ripple.CSSProperties = styles;
|
|
62
|
+
const runtime_styles: RuntimeCSSProperties = styles;
|
|
63
|
+
const html = <div style={namespaced} />;
|
|
64
|
+
const svg = <svg style={styles}><circle style={{ strokeWidth: 2, 'fill-opacity': 0.5 }} /></svg>;
|
|
65
|
+
const zero = <div style={{ width: 0 }} />;
|
|
66
|
+
const css_text = <div style="width: 400px; opacity: 0.5" />;
|
|
67
|
+
const absent = <div style={null} />;
|
|
68
|
+
const omitted = <svg style={undefined} />;
|
|
69
|
+
const conditional = <div style={{ width: Math.random() ? '400px' : undefined, '--scale': undefined }} />;
|
|
70
|
+
const nullable = {
|
|
71
|
+
width: null, 'font-size': null, opacity: null, WebkitLineClamp: null,
|
|
72
|
+
'-webkit-line-clamp': null, '--scale': null,
|
|
73
|
+
} satisfies CSSProperties;
|
|
74
|
+
const nullable_html = <div style={nullable} />;
|
|
75
|
+
const nullable_svg = <svg style={nullable} />;
|
|
76
|
+
|
|
77
|
+
// @ts-expect-error Lengths require explicit units unless the value is zero.
|
|
78
|
+
const bad_styles = { width: 400 } satisfies CSSProperties;
|
|
79
|
+
// @ts-expect-error Lengths require explicit units unless the value is zero.
|
|
80
|
+
const bad_width = <div style={{ width: 400 }} />;
|
|
81
|
+
// @ts-expect-error Kebab-case lengths use the same rules.
|
|
82
|
+
const bad_font_size = <div style={{ 'font-size': 16 }} />;
|
|
83
|
+
// @ts-expect-error SVG style objects also require units for these lengths.
|
|
84
|
+
const bad_svg = <svg style={{ width: 400 }} />;
|
|
85
|
+
// @ts-expect-error Vendor-prefixed lengths require units too.
|
|
86
|
+
const bad_vendor_length = <div style={{ WebkitBorderRadius: 4 }} />;
|
|
87
|
+
// @ts-expect-error Durations require time units, even for zero.
|
|
88
|
+
const bad_duration = <div style={{ transitionDuration: 0 }} />;
|
|
89
|
+
// @ts-expect-error Unknown property names do not bypass CSS checking.
|
|
90
|
+
const bad_property = <div style={{ widht: '400px' }} />;
|
|
91
|
+
// @ts-expect-error Custom properties accept strings and numbers, not objects.
|
|
92
|
+
const bad_custom = <div style={{ '--theme': {} }} />;
|
|
93
|
+
// @ts-expect-error CSS fallback arrays are not supported by the runtime.
|
|
94
|
+
const bad_array = <div style={{ display: ['flex', 'block'] }} />;
|
|
95
|
+
`;
|
|
96
|
+
const { service, file_name } = create_service(source, automatic);
|
|
97
|
+
try {
|
|
98
|
+
expect(
|
|
99
|
+
service
|
|
100
|
+
.getSemanticDiagnostics(file_name)
|
|
101
|
+
.map((diagnostic) => ts.flattenDiagnosticMessageText(diagnostic.messageText, '\n')),
|
|
102
|
+
).toEqual([]);
|
|
103
|
+
} finally {
|
|
104
|
+
service.dispose();
|
|
105
|
+
}
|
|
106
|
+
});
|
|
107
|
+
|
|
46
108
|
it.each([true, false])('qualifies HTML tag hovers (automatic runtime: %s)', (automatic) => {
|
|
47
109
|
const source = `
|
|
48
110
|
import 'ripple/jsx-runtime';
|
|
@@ -68,7 +130,8 @@ describe('Ripple JSX types', () => {
|
|
|
68
130
|
|
|
69
131
|
it('preserves JSX imports, global types, native events, and DOM refs', () => {
|
|
70
132
|
const source = `
|
|
71
|
-
import type { ClassValue, JSX as RuntimeJSX, Ripple } from 'ripple/jsx-runtime';
|
|
133
|
+
import type { ClassValue, JSX as RuntimeJSX, Ripple as RuntimeRipple } from 'ripple/jsx-runtime';
|
|
134
|
+
import type { JSX as PublicJSX, Ripple } from 'ripple';
|
|
72
135
|
import { createRefKey, type RefKey } from 'ripple';
|
|
73
136
|
|
|
74
137
|
const ref_key: RefKey = createRefKey();
|
|
@@ -81,8 +144,10 @@ describe('Ripple JSX types', () => {
|
|
|
81
144
|
};
|
|
82
145
|
const global_props: JSX.IntrinsicElements['input'] = props;
|
|
83
146
|
const runtime_props: RuntimeJSX.IntrinsicElements['input'] = global_props;
|
|
147
|
+
const public_props: PublicJSX.IntrinsicElements['input'] = runtime_props;
|
|
148
|
+
const runtime_namespace_props: RuntimeRipple.InputHTMLAttributes<HTMLInputElement> = public_props;
|
|
84
149
|
const classes: ClassValue = ['one', { two: true }];
|
|
85
|
-
const input = <input {...
|
|
150
|
+
const input = <input {...public_props} class={classes} />;
|
|
86
151
|
const svg = <svg><circle cx={10} ref={(node) => { const circle: SVGCircleElement = node; }} /></svg>;
|
|
87
152
|
// @ts-expect-error Input values do not accept objects.
|
|
88
153
|
const bad_value = <input value={{}} />;
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import ts from 'typescript';
|
|
2
|
+
import { describe, expect, it } from 'vitest';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* @param {string} source
|
|
6
|
+
*/
|
|
7
|
+
function create_service(source) {
|
|
8
|
+
const root = process.cwd();
|
|
9
|
+
const file_name = `${root}/packages/ripple/tracked-types-test.tsx`;
|
|
10
|
+
const options = {
|
|
11
|
+
strict: true,
|
|
12
|
+
target: ts.ScriptTarget.ESNext,
|
|
13
|
+
module: ts.ModuleKind.ESNext,
|
|
14
|
+
moduleResolution: ts.ModuleResolutionKind.Bundler,
|
|
15
|
+
jsx: ts.JsxEmit.Preserve,
|
|
16
|
+
jsxImportSource: 'ripple',
|
|
17
|
+
skipLibCheck: true,
|
|
18
|
+
types: [],
|
|
19
|
+
paths: {
|
|
20
|
+
'#public': [`${root}/packages/ripple/types/index.d.ts`],
|
|
21
|
+
ripple: [`${root}/packages/ripple/types/index.d.ts`],
|
|
22
|
+
'ripple/jsx-runtime': [`${root}/packages/ripple/src/jsx-runtime.d.ts`],
|
|
23
|
+
},
|
|
24
|
+
};
|
|
25
|
+
const service = ts.createLanguageService({
|
|
26
|
+
getCompilationSettings: () => options,
|
|
27
|
+
getScriptFileNames: () => [file_name],
|
|
28
|
+
getScriptVersion: () => '0',
|
|
29
|
+
getScriptSnapshot: (name) => {
|
|
30
|
+
const text = name === file_name ? source : ts.sys.readFile(name);
|
|
31
|
+
return text === undefined ? undefined : ts.ScriptSnapshot.fromString(text);
|
|
32
|
+
},
|
|
33
|
+
getCurrentDirectory: () => root,
|
|
34
|
+
getDefaultLibFileName: ts.getDefaultLibFilePath,
|
|
35
|
+
realpath: ts.sys.realpath,
|
|
36
|
+
directoryExists: ts.sys.directoryExists,
|
|
37
|
+
getDirectories: ts.sys.getDirectories,
|
|
38
|
+
fileExists: (name) => name === file_name || ts.sys.fileExists(name),
|
|
39
|
+
readFile: (name) => (name === file_name ? source : ts.sys.readFile(name)),
|
|
40
|
+
});
|
|
41
|
+
return { service, file_name };
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
describe('Ripple tracked types', () => {
|
|
45
|
+
it('shows public names in value property hovers', () => {
|
|
46
|
+
const source = `
|
|
47
|
+
import { track } from 'ripple';
|
|
48
|
+
const count = track(0);
|
|
49
|
+
const derived = track(() => count.value * 2);
|
|
50
|
+
const writable = track(() => count.value, undefined, true);
|
|
51
|
+
count.value;
|
|
52
|
+
derived.value;
|
|
53
|
+
writable.value;
|
|
54
|
+
`;
|
|
55
|
+
const { service, file_name } = create_service(source);
|
|
56
|
+
try {
|
|
57
|
+
expect(service.getSemanticDiagnostics(file_name)).toEqual([]);
|
|
58
|
+
for (const [name, type] of [
|
|
59
|
+
['count', 'Tracked'],
|
|
60
|
+
['derived', 'Derived'],
|
|
61
|
+
['writable', 'WritableDerived'],
|
|
62
|
+
]) {
|
|
63
|
+
const info = service.getQuickInfoAtPosition(
|
|
64
|
+
file_name,
|
|
65
|
+
source.lastIndexOf(`${name}.value`) + name.length + 1,
|
|
66
|
+
);
|
|
67
|
+
expect(ts.displayPartsToString(info?.displayParts)).toBe(
|
|
68
|
+
`(property) ${type}<number>.value: number`,
|
|
69
|
+
);
|
|
70
|
+
}
|
|
71
|
+
} finally {
|
|
72
|
+
service.dispose();
|
|
73
|
+
}
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
it('preserves writes, read-only views, and tracked component props', () => {
|
|
77
|
+
const source = `
|
|
78
|
+
import { track, type Component, type Derived, type Tracked } from 'ripple';
|
|
79
|
+
const count = track(0);
|
|
80
|
+
count.value = 1;
|
|
81
|
+
const tracked: Tracked<number> = track(count);
|
|
82
|
+
const derived: Derived<number> = tracked;
|
|
83
|
+
const view = count.readOnly();
|
|
84
|
+
// @ts-expect-error Read-only views reject writes.
|
|
85
|
+
view.value = 2;
|
|
86
|
+
const computed = track(() => count.value * 2);
|
|
87
|
+
// @ts-expect-error Computed values reject writes.
|
|
88
|
+
computed.value = 2;
|
|
89
|
+
const writable = track(() => count.value, undefined, true);
|
|
90
|
+
writable.value = 2;
|
|
91
|
+
const with_setter = track(() => count.value, undefined, (next) => next);
|
|
92
|
+
with_setter.value = 3;
|
|
93
|
+
// @ts-expect-error Tracked values preserve their value type.
|
|
94
|
+
count.value = 'wrong';
|
|
95
|
+
// @ts-expect-error Non-component tracked values are not callable.
|
|
96
|
+
count({});
|
|
97
|
+
declare const TrackedComponent: Tracked<Component<{ name: string }>>;
|
|
98
|
+
declare const DerivedComponent: Derived<Component<{ name: string }>>;
|
|
99
|
+
const valid = <TrackedComponent name="Ripple" />;
|
|
100
|
+
const valid_derived = <DerivedComponent name="Ripple" />;
|
|
101
|
+
// @ts-expect-error Tracked components preserve required props.
|
|
102
|
+
const missing = <TrackedComponent />;
|
|
103
|
+
// @ts-expect-error Derived components preserve prop types.
|
|
104
|
+
const invalid = <DerivedComponent name={123} />;
|
|
105
|
+
`;
|
|
106
|
+
const { service, file_name } = create_service(source);
|
|
107
|
+
try {
|
|
108
|
+
expect(
|
|
109
|
+
service
|
|
110
|
+
.getSemanticDiagnostics(file_name)
|
|
111
|
+
.map((diagnostic) => ts.flattenDiagnosticMessageText(diagnostic.messageText, '\n')),
|
|
112
|
+
).toEqual([]);
|
|
113
|
+
} finally {
|
|
114
|
+
service.dispose();
|
|
115
|
+
}
|
|
116
|
+
});
|
|
117
|
+
});
|
package/types/index.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { ExtendedEventOptions } from '@tsrx/core/types';
|
|
2
|
+
export type { CSSProperties, JSX, Ripple } from '../src/jsx-runtime.js';
|
|
2
3
|
export { setTransport } from './transport.js';
|
|
3
4
|
export type { Transport, Transporter } from './transport.js';
|
|
4
5
|
export type { RefValue } from '@tsrx/core/runtime/ref';
|
|
@@ -220,8 +221,8 @@ export const TRACKED_UPDATED: unique symbol;
|
|
|
220
221
|
export const SUSPENSE_PENDING: unique symbol;
|
|
221
222
|
export const SUSPENSE_REJECTED: unique symbol;
|
|
222
223
|
|
|
223
|
-
//
|
|
224
|
-
interface
|
|
224
|
+
// A tracked value: `track(0)`. Read and write it through `.value`.
|
|
225
|
+
export interface Tracked<V> extends TrackedCallable<V> {
|
|
225
226
|
'#v': V;
|
|
226
227
|
value: V;
|
|
227
228
|
/**
|
|
@@ -236,22 +237,20 @@ interface TrackedBase<V> {
|
|
|
236
237
|
interface TrackedCallable<V> {
|
|
237
238
|
(props: V extends Component<infer P> ? P : never): V extends Component ? void : never;
|
|
238
239
|
}
|
|
239
|
-
// A tracked value: `track(0)`. Read and write it through `.value`.
|
|
240
|
-
export type Tracked<V> = TrackedBase<V> & TrackedCallable<V>;
|
|
241
|
-
|
|
242
240
|
// A computed value: `track(() => ...)`. Its `value` is read-only unless the
|
|
243
241
|
// call opted into writes (see `WritableDerived`). A `Tracked` satisfies it.
|
|
244
|
-
interface
|
|
242
|
+
export interface Derived<V> extends TrackedCallable<V> {
|
|
245
243
|
'#v': V;
|
|
246
244
|
readonly value: V;
|
|
247
245
|
/** A derived is already read-only: returns itself. */
|
|
248
246
|
readOnly(): Derived<V>;
|
|
249
247
|
}
|
|
250
|
-
export type Derived<V> = DerivedBase<V> & TrackedCallable<V>;
|
|
251
248
|
// A computed value created with a setter (`track(fn, get, set)`) or with
|
|
252
249
|
// `true` in the setter position: writes land as a temporary value until the
|
|
253
250
|
// next recompute.
|
|
254
|
-
export
|
|
251
|
+
export interface WritableDerived<V> extends Tracked<V> {
|
|
252
|
+
value: V;
|
|
253
|
+
}
|
|
255
254
|
|
|
256
255
|
// Helper type to infer component type from a function that returns a component
|
|
257
256
|
// If T is a function returning a Component, extract the Component type itself, not the return type (void)
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
|
|
2
|
-
|
|
3
|
-
exports[`compiler > assignments > compiles tracked values in effect with assignment expression 1`] = `"state.count = lazy.value;"`;
|
|
4
|
-
|
|
5
|
-
exports[`compiler > assignments > compiles tracked values in effect with update expressions 1`] = `
|
|
6
|
-
"_$_.untrack(() => {
|
|
7
|
-
state.preIncrement = _$_.update_pre(lazy);
|
|
8
|
-
state.postIncrement = _$_.update(lazy);
|
|
9
|
-
state.preDecrement = _$_.update_pre(lazy, -1);
|
|
10
|
-
state.postDecrement = _$_.update(lazy, -1);
|
|
11
|
-
});"
|
|
12
|
-
`;
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
|
|
2
|
-
|
|
3
|
-
exports[`compiler > typescript > compiles TSInstantiationExpression 1`] = `
|
|
4
|
-
"import * as _$_ from 'ripple/internal/client';
|
|
5
|
-
|
|
6
|
-
function makeBox(value) {
|
|
7
|
-
return { value };
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
const makeStringBox = (makeBox);
|
|
11
|
-
const stringBox = makeStringBox('abc');
|
|
12
|
-
const ErrorMap = (Map);
|
|
13
|
-
const errorMap = new ErrorMap();"
|
|
14
|
-
`;
|
|
15
|
-
|
|
16
|
-
exports[`compiler > typescript > removes class TypeScript syntax from JS output 1`] = `
|
|
17
|
-
"import * as _$_ from 'ripple/internal/client';
|
|
18
|
-
|
|
19
|
-
class PrintEvent {
|
|
20
|
-
text;
|
|
21
|
-
|
|
22
|
-
constructor(text) {
|
|
23
|
-
this.text = text;
|
|
24
|
-
}
|
|
25
|
-
}"
|
|
26
|
-
`;
|
|
27
|
-
|
|
28
|
-
exports[`compiler > typescript > removes class extends type arguments from JS output 1`] = `
|
|
29
|
-
"import * as _$_ from 'ripple/internal/client';
|
|
30
|
-
|
|
31
|
-
class StringMap extends Map {
|
|
32
|
-
constructor() {
|
|
33
|
-
var __block = _$_.scope();
|
|
34
|
-
|
|
35
|
-
super();
|
|
36
|
-
}
|
|
37
|
-
}"
|
|
38
|
-
`;
|
|
39
|
-
|
|
40
|
-
exports[`compiler > typescript > removes type assertions from function parameters and leaves default values 1`] = `
|
|
41
|
-
"import * as _$_ from 'ripple/internal/client';
|
|
42
|
-
|
|
43
|
-
function getString(e = 'test') {
|
|
44
|
-
return e;
|
|
45
|
-
}"
|
|
46
|
-
`;
|