@holo-js/adapter-next 0.1.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/client.d.ts +7 -0
- package/dist/client.mjs +73 -0
- package/dist/index.d.ts +17 -0
- package/dist/index.mjs +30 -0
- package/package.json +41 -0
package/dist/client.d.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { InferSchemaData } from '@holo-js/forms';
|
|
2
|
+
import { useForm as useForm$1, UseFormOptions, UseFormResult } from '@holo-js/forms/client';
|
|
3
|
+
export { ClientSubmitContext, ClientSubmitResult, FormFieldState, FormFieldTree, UseFormOptions, UseFormResult, ValidateOnMode } from '@holo-js/forms/client';
|
|
4
|
+
|
|
5
|
+
declare function useForm<TSchema extends Parameters<typeof useForm$1>[0]>(schemaDefinition: TSchema, options?: UseFormOptions<InferSchemaData<TSchema['fields']>>): UseFormResult<InferSchemaData<TSchema['fields']>>;
|
|
6
|
+
|
|
7
|
+
export { useForm };
|
package/dist/client.mjs
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
// src/client.ts
|
|
2
|
+
import { useEffect, useRef, useState } from "react";
|
|
3
|
+
import {
|
|
4
|
+
useForm as createForm
|
|
5
|
+
} from "@holo-js/forms/client";
|
|
6
|
+
function isPlainObject(value) {
|
|
7
|
+
return !!value && typeof value === "object" && !Array.isArray(value) && !(value instanceof Date) && !(value instanceof Blob);
|
|
8
|
+
}
|
|
9
|
+
function areEqual(left, right) {
|
|
10
|
+
if (Object.is(left, right)) {
|
|
11
|
+
return true;
|
|
12
|
+
}
|
|
13
|
+
if (left instanceof Date && right instanceof Date) {
|
|
14
|
+
return left.getTime() === right.getTime();
|
|
15
|
+
}
|
|
16
|
+
if (left instanceof Blob || right instanceof Blob) {
|
|
17
|
+
return false;
|
|
18
|
+
}
|
|
19
|
+
if (Array.isArray(left) && Array.isArray(right)) {
|
|
20
|
+
return left.length === right.length && left.every((value, index) => areEqual(value, right[index]));
|
|
21
|
+
}
|
|
22
|
+
if (isPlainObject(left) && isPlainObject(right)) {
|
|
23
|
+
const leftKeys = Object.keys(left);
|
|
24
|
+
const rightKeys = Object.keys(right);
|
|
25
|
+
return leftKeys.length === rightKeys.length && leftKeys.every((key) => key in right && areEqual(left[key], right[key]));
|
|
26
|
+
}
|
|
27
|
+
return false;
|
|
28
|
+
}
|
|
29
|
+
function areOptionsEqual(left, right) {
|
|
30
|
+
return left.action === right.action && left.method === right.method && left.validateOn === right.validateOn && Boolean(left.submitter) === Boolean(right.submitter) && areEqual(left.initialValues, right.initialValues) && areEqual(left.initialState, right.initialState);
|
|
31
|
+
}
|
|
32
|
+
function createSubmitterBridge(optionsRef) {
|
|
33
|
+
return (context) => {
|
|
34
|
+
const submitter = optionsRef.current?.submitter;
|
|
35
|
+
if (!submitter) {
|
|
36
|
+
throw new TypeError("Expected submitter to be defined.");
|
|
37
|
+
}
|
|
38
|
+
return submitter(context);
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
function useForm(schemaDefinition, options = {}) {
|
|
42
|
+
const formRef = useRef();
|
|
43
|
+
const previousSchemaRef = useRef();
|
|
44
|
+
const previousOptionsRef = useRef();
|
|
45
|
+
const latestOptionsRef = useRef();
|
|
46
|
+
const submitterBridgeRef = useRef();
|
|
47
|
+
const [, setVersion] = useState(0);
|
|
48
|
+
latestOptionsRef.current = options;
|
|
49
|
+
if (options.submitter && !submitterBridgeRef.current) {
|
|
50
|
+
submitterBridgeRef.current = createSubmitterBridge(latestOptionsRef);
|
|
51
|
+
}
|
|
52
|
+
const resolvedOptions = options.submitter ? {
|
|
53
|
+
...options,
|
|
54
|
+
submitter: submitterBridgeRef.current
|
|
55
|
+
} : options;
|
|
56
|
+
if (!formRef.current || previousSchemaRef.current !== schemaDefinition) {
|
|
57
|
+
formRef.current = createForm(schemaDefinition, resolvedOptions);
|
|
58
|
+
previousSchemaRef.current = schemaDefinition;
|
|
59
|
+
previousOptionsRef.current = options;
|
|
60
|
+
} else {
|
|
61
|
+
const previousOptions = previousOptionsRef.current;
|
|
62
|
+
if (!areOptionsEqual(previousOptions, options)) {
|
|
63
|
+
formRef.current = createForm(schemaDefinition, resolvedOptions);
|
|
64
|
+
previousOptionsRef.current = options;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
const form = formRef.current;
|
|
68
|
+
useEffect(() => form.subscribe(() => setVersion((version) => version + 1)), [form]);
|
|
69
|
+
return form;
|
|
70
|
+
}
|
|
71
|
+
export {
|
|
72
|
+
useForm
|
|
73
|
+
};
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import * as _holo_js_core from '@holo-js/core';
|
|
2
|
+
import { HoloFrameworkOptions, HoloAdapterProject } from '@holo-js/core';
|
|
3
|
+
import { HoloConfigMap } from '@holo-js/config';
|
|
4
|
+
|
|
5
|
+
type NextHoloOptions = HoloFrameworkOptions;
|
|
6
|
+
type NextHoloProject<TCustom extends HoloConfigMap = HoloConfigMap> = HoloAdapterProject<TCustom>;
|
|
7
|
+
declare const nextHoloCapabilities: Readonly<_holo_js_core.HoloAdapterCapabilities>;
|
|
8
|
+
declare function createNextHoloProject<TCustom extends HoloConfigMap = HoloConfigMap>(options?: NextHoloOptions): Promise<NextHoloProject<TCustom>>;
|
|
9
|
+
declare function initializeNextHoloProject<TCustom extends HoloConfigMap = HoloConfigMap>(options?: NextHoloOptions): Promise<NextHoloProject<TCustom>>;
|
|
10
|
+
declare function createNextHoloHelpers<TCustom extends HoloConfigMap = HoloConfigMap>(options?: NextHoloOptions): _holo_js_core.HoloAdapterProjectAccessors<TCustom>;
|
|
11
|
+
declare function resetNextHoloProject(): Promise<void>;
|
|
12
|
+
declare const adapterNextInternals: {
|
|
13
|
+
getState: () => _holo_js_core.HoloFrameworkAdapterState<HoloAdapterProject<object>>;
|
|
14
|
+
resolveOptions: (projectOptions?: HoloFrameworkOptions | undefined) => _holo_js_core.ResolvedHoloFrameworkOptions;
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
export { type NextHoloOptions, type NextHoloProject, adapterNextInternals, createNextHoloHelpers, createNextHoloProject, initializeNextHoloProject, nextHoloCapabilities, resetNextHoloProject };
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
// src/index.ts
|
|
2
|
+
import {
|
|
3
|
+
createHoloFrameworkAdapter
|
|
4
|
+
} from "@holo-js/core";
|
|
5
|
+
var nextAdapter = createHoloFrameworkAdapter({
|
|
6
|
+
stateKey: "__holoNextAdapter__",
|
|
7
|
+
displayName: "Next"
|
|
8
|
+
});
|
|
9
|
+
var nextHoloCapabilities = nextAdapter.capabilities;
|
|
10
|
+
async function createNextHoloProject(options = {}) {
|
|
11
|
+
return nextAdapter.createProject(options);
|
|
12
|
+
}
|
|
13
|
+
async function initializeNextHoloProject(options = {}) {
|
|
14
|
+
return nextAdapter.initializeProject(options);
|
|
15
|
+
}
|
|
16
|
+
function createNextHoloHelpers(options = {}) {
|
|
17
|
+
return nextAdapter.createHelpers(options);
|
|
18
|
+
}
|
|
19
|
+
async function resetNextHoloProject() {
|
|
20
|
+
await nextAdapter.resetProject();
|
|
21
|
+
}
|
|
22
|
+
var adapterNextInternals = nextAdapter.internals;
|
|
23
|
+
export {
|
|
24
|
+
adapterNextInternals,
|
|
25
|
+
createNextHoloHelpers,
|
|
26
|
+
createNextHoloProject,
|
|
27
|
+
initializeNextHoloProject,
|
|
28
|
+
nextHoloCapabilities,
|
|
29
|
+
resetNextHoloProject
|
|
30
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@holo-js/adapter-next",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Holo-JS Framework - Next.js adapter",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": {
|
|
9
|
+
"types": "./dist/index.d.ts",
|
|
10
|
+
"import": "./dist/index.mjs",
|
|
11
|
+
"default": "./dist/index.mjs"
|
|
12
|
+
},
|
|
13
|
+
"./client": {
|
|
14
|
+
"types": "./dist/client.d.ts",
|
|
15
|
+
"import": "./dist/client.mjs",
|
|
16
|
+
"default": "./dist/client.mjs"
|
|
17
|
+
}
|
|
18
|
+
},
|
|
19
|
+
"main": "./dist/index.mjs",
|
|
20
|
+
"types": "./dist/index.d.ts",
|
|
21
|
+
"files": [
|
|
22
|
+
"dist"
|
|
23
|
+
],
|
|
24
|
+
"scripts": {
|
|
25
|
+
"build": "tsup",
|
|
26
|
+
"stub": "tsup",
|
|
27
|
+
"typecheck": "tsc -p tsconfig.json --noEmit",
|
|
28
|
+
"test": "vitest --run"
|
|
29
|
+
},
|
|
30
|
+
"dependencies": {
|
|
31
|
+
"@holo-js/config": "workspace:*",
|
|
32
|
+
"@holo-js/core": "workspace:*",
|
|
33
|
+
"@holo-js/forms": "workspace:*"
|
|
34
|
+
},
|
|
35
|
+
"devDependencies": {
|
|
36
|
+
"@types/node": "catalog:",
|
|
37
|
+
"tsup": "catalog:",
|
|
38
|
+
"typescript": "catalog:",
|
|
39
|
+
"vitest": "catalog:"
|
|
40
|
+
}
|
|
41
|
+
}
|