@piying/view-svelte 1.4.0 → 1.4.1
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/builder.js +2 -23
- package/component/field-template.svelte +5 -5
- package/component/group.svelte +2 -2
- package/component/wrapper.svelte +2 -2
- package/package.json +5 -6
- package/svelte-schema.js +3 -23
- package/token.js +2 -2
- package/util/signal-convert.svelte.d.ts +1 -1
- package/util/signal-convert.svelte.js +9 -9
- package/util/use-control-value-accessor.svelte.d.ts +1 -0
- package/util/use-control-value-accessor.svelte.js +12 -12
package/builder.js
CHANGED
|
@@ -1,24 +1,3 @@
|
|
|
1
|
-
var __extends = (this && this.__extends) || (function () {
|
|
2
|
-
var extendStatics = function (d, b) {
|
|
3
|
-
extendStatics = Object.setPrototypeOf ||
|
|
4
|
-
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
5
|
-
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
6
|
-
return extendStatics(d, b);
|
|
7
|
-
};
|
|
8
|
-
return function (d, b) {
|
|
9
|
-
if (typeof b !== "function" && b !== null)
|
|
10
|
-
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
11
|
-
extendStatics(d, b);
|
|
12
|
-
function __() { this.constructor = d; }
|
|
13
|
-
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
14
|
-
};
|
|
15
|
-
})();
|
|
16
1
|
import { FormBuilder } from '@piying/view-core';
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
function SvelteFormBuilder() {
|
|
20
|
-
return _super !== null && _super.apply(this, arguments) || this;
|
|
21
|
-
}
|
|
22
|
-
return SvelteFormBuilder;
|
|
23
|
-
}(FormBuilder));
|
|
24
|
-
export { SvelteFormBuilder };
|
|
2
|
+
export class SvelteFormBuilder extends FormBuilder {
|
|
3
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
2
|
import type { PiResolvedViewFieldConfig } from '../type/group';
|
|
3
|
-
import {
|
|
3
|
+
import { signalToState } from '../util/signal-convert.svelte';
|
|
4
4
|
import { PI_VIEW_FIELD_TOKEN, InjectorToken } from '../token';
|
|
5
5
|
import { createViewControlLink, getLazyImport, isLazyMark } from '@piying/view-core';
|
|
6
6
|
import { getContext, setContext } from 'svelte';
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
field: PiResolvedViewFieldConfig;
|
|
11
11
|
} = $props();
|
|
12
12
|
const injector = getContext<Injector>(InjectorToken)!;
|
|
13
|
-
const fieldInputs =
|
|
13
|
+
const fieldInputs = signalToState(() => {
|
|
14
14
|
return {
|
|
15
15
|
...props.field.attributes(),
|
|
16
16
|
...props.field.inputs(),
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
};
|
|
20
20
|
});
|
|
21
21
|
let controlRef = $state<any>();
|
|
22
|
-
const renderConfig =
|
|
22
|
+
const renderConfig = signalToState(() => props.field.renderConfig());
|
|
23
23
|
const control = $derived.by(() => props.field.form.control);
|
|
24
24
|
$effect.pre(() => {
|
|
25
25
|
let dispose: (() => any) | undefined;
|
|
@@ -31,9 +31,9 @@
|
|
|
31
31
|
dispose = undefined;
|
|
32
32
|
};
|
|
33
33
|
});
|
|
34
|
-
const fieldChildren =
|
|
34
|
+
const fieldChildren = signalToState(() => props.field.children?.());
|
|
35
35
|
|
|
36
|
-
const wrappers =
|
|
36
|
+
const wrappers = signalToState(() => props.field.wrappers());
|
|
37
37
|
const ComponentType = $derived.by(() => {
|
|
38
38
|
return props.field.define?.type;
|
|
39
39
|
});
|
package/component/group.svelte
CHANGED
|
@@ -2,10 +2,10 @@
|
|
|
2
2
|
import FieldTemplate from './field-template.svelte';
|
|
3
3
|
import { getContext } from 'svelte';
|
|
4
4
|
import { PI_VIEW_FIELD_TOKEN } from '../token';
|
|
5
|
-
import {
|
|
5
|
+
import { signalToState } from '../util/signal-convert.svelte';
|
|
6
6
|
|
|
7
7
|
const field = getContext<PI_VIEW_FIELD_TOKEN>(PI_VIEW_FIELD_TOKEN);
|
|
8
|
-
const children =
|
|
8
|
+
const children = signalToState(() => field().children!())!;
|
|
9
9
|
</script>
|
|
10
10
|
|
|
11
11
|
{#each children()! as field, i (i)}
|
package/component/wrapper.svelte
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
2
|
import type { CoreResolvedWrapperConfig } from '@piying/view-core';
|
|
3
|
-
import {
|
|
3
|
+
import { signalToState } from '../util/signal-convert.svelte';
|
|
4
4
|
import PiWrapper from './wrapper.svelte';
|
|
5
5
|
const dProps: {
|
|
6
6
|
wrappers: CoreResolvedWrapperConfig[];
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
} = $props();
|
|
9
9
|
const restWrappers = $derived.by(() => dProps.wrappers!.slice(1));
|
|
10
10
|
const wrapper = $derived.by(() => dProps.wrappers?.[0]);
|
|
11
|
-
const inputs =
|
|
11
|
+
const inputs = signalToState(() => ({
|
|
12
12
|
...wrapper?.inputs(),
|
|
13
13
|
...wrapper?.attributes(),
|
|
14
14
|
...wrapper?.outputs
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@piying/view-svelte",
|
|
3
|
-
"version": "1.4.
|
|
3
|
+
"version": "1.4.1",
|
|
4
4
|
"description": "Piying view For Svelte;Valibot to Component",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"homepage": "https://piying-org.github.io/website/docs/client/intro",
|
|
@@ -34,14 +34,13 @@
|
|
|
34
34
|
],
|
|
35
35
|
"license": "MIT",
|
|
36
36
|
"dependencies": {
|
|
37
|
-
"@piying/view-core": "^1.4.
|
|
38
|
-
"
|
|
39
|
-
"static-injector": "^6.1.2",
|
|
40
|
-
"valibot": "^1.1.0"
|
|
37
|
+
"@piying/view-core": "^1.4.1",
|
|
38
|
+
"static-injector": "^6.1.2"
|
|
41
39
|
},
|
|
42
40
|
"sideEffects": false,
|
|
43
41
|
"peerDependencies": {
|
|
44
|
-
"svelte": "^5.0.0"
|
|
42
|
+
"svelte": "^5.0.0",
|
|
43
|
+
"valibot": "^1.1.0"
|
|
45
44
|
},
|
|
46
45
|
"module": "index.js",
|
|
47
46
|
"typings": "index.d.ts",
|
package/svelte-schema.js
CHANGED
|
@@ -1,24 +1,4 @@
|
|
|
1
|
-
var __extends = (this && this.__extends) || (function () {
|
|
2
|
-
var extendStatics = function (d, b) {
|
|
3
|
-
extendStatics = Object.setPrototypeOf ||
|
|
4
|
-
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
5
|
-
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
6
|
-
return extendStatics(d, b);
|
|
7
|
-
};
|
|
8
|
-
return function (d, b) {
|
|
9
|
-
if (typeof b !== "function" && b !== null)
|
|
10
|
-
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
11
|
-
extendStatics(d, b);
|
|
12
|
-
function __() { this.constructor = d; }
|
|
13
|
-
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
14
|
-
};
|
|
15
|
-
})();
|
|
16
1
|
import { CoreSchemaHandle } from '@piying/view-core';
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
return _super !== null && _super.apply(this, arguments) || this;
|
|
21
|
-
}
|
|
22
|
-
return SvelteSchemaHandle;
|
|
23
|
-
}(CoreSchemaHandle));
|
|
24
|
-
export { SvelteSchemaHandle };
|
|
2
|
+
export class SvelteSchemaHandle extends CoreSchemaHandle {
|
|
3
|
+
contents;
|
|
4
|
+
}
|
package/token.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export
|
|
2
|
-
export
|
|
1
|
+
export const InjectorToken = Symbol();
|
|
2
|
+
export const PI_VIEW_FIELD_TOKEN = Symbol();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare function
|
|
1
|
+
export declare function signalToState<T>(value: () => T | undefined): () => T | undefined;
|
|
@@ -1,20 +1,20 @@
|
|
|
1
|
-
import { effect } from 'static-injector';
|
|
1
|
+
import { effect, Injector } from 'static-injector';
|
|
2
2
|
import { InjectorToken } from '../token';
|
|
3
3
|
import { getContext } from 'svelte';
|
|
4
|
-
export function
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
$effect.pre(
|
|
4
|
+
export function signalToState(value) {
|
|
5
|
+
const injector = getContext(InjectorToken);
|
|
6
|
+
let dataRef = $state.raw(undefined);
|
|
7
|
+
$effect.pre(() => {
|
|
8
8
|
dataRef = value();
|
|
9
|
-
|
|
10
|
-
|
|
9
|
+
const ref = effect(() => {
|
|
10
|
+
const currentValue = value();
|
|
11
11
|
if (!Object.is(dataRef, currentValue)) {
|
|
12
12
|
dataRef = currentValue;
|
|
13
13
|
}
|
|
14
14
|
}, { injector: injector });
|
|
15
|
-
return
|
|
15
|
+
return () => {
|
|
16
16
|
ref.destroy();
|
|
17
17
|
};
|
|
18
18
|
});
|
|
19
|
-
return
|
|
19
|
+
return () => dataRef;
|
|
20
20
|
}
|
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
export function useControlValueAccessor() {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
writeValue
|
|
2
|
+
let value = $state();
|
|
3
|
+
let disabled = $state(false);
|
|
4
|
+
let onChange;
|
|
5
|
+
let touched;
|
|
6
|
+
const instance = {
|
|
7
|
+
writeValue(obj) {
|
|
8
8
|
value = obj;
|
|
9
9
|
},
|
|
10
|
-
registerOnChange
|
|
10
|
+
registerOnChange(fn) {
|
|
11
11
|
onChange = fn;
|
|
12
12
|
},
|
|
13
|
-
registerOnTouched
|
|
13
|
+
registerOnTouched(fn) {
|
|
14
14
|
touched = fn;
|
|
15
15
|
},
|
|
16
|
-
setDisabledState
|
|
16
|
+
setDisabledState(value) {
|
|
17
17
|
disabled = value;
|
|
18
18
|
}
|
|
19
19
|
};
|
|
@@ -26,11 +26,11 @@ export function useControlValueAccessor() {
|
|
|
26
26
|
get disabled() {
|
|
27
27
|
return disabled;
|
|
28
28
|
},
|
|
29
|
-
valueChange:
|
|
30
|
-
onChange
|
|
29
|
+
valueChange: (input) => {
|
|
30
|
+
onChange?.(input);
|
|
31
31
|
value = input;
|
|
32
32
|
},
|
|
33
|
-
touchedChange:
|
|
33
|
+
touchedChange: () => {
|
|
34
34
|
touched();
|
|
35
35
|
}
|
|
36
36
|
}
|