@brytdesigns/web-component-core 1.1.7 → 3.0.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/main/animation/awaitAllAnimations.js +28 -32
- package/dist/main/animation/awaitAllAnimations.js.map +1 -1
- package/dist/main/animation/content.js +156 -0
- package/dist/main/animation/content.js.map +1 -0
- package/dist/main/animation/controlsToPromise.js +6 -5
- package/dist/main/animation/controlsToPromise.js.map +1 -1
- package/dist/main/animation/getTransitionConfig.js +52 -51
- package/dist/main/animation/getTransitionConfig.js.map +1 -1
- package/dist/main/animation/index.d.ts +61 -1
- package/dist/main/animation/index.js +5 -5
- package/dist/main/focusTrap/index.d.ts +1 -1
- package/dist/main/focusTrap/index.js +10 -14
- package/dist/main/focusTrap/index.js.map +1 -1
- package/dist/main/hooks/index.d.ts +14 -9
- package/dist/main/hooks/index.js +5 -6
- package/dist/main/hooks/internal/getValueFromPath.js +9 -10
- package/dist/main/hooks/internal/getValueFromPath.js.map +1 -1
- package/dist/main/hooks/makePathContextHooks.js +58 -68
- package/dist/main/hooks/makePathContextHooks.js.map +1 -1
- package/dist/main/hooks/makePathDataArrayComponent.js +61 -67
- package/dist/main/hooks/makePathDataArrayComponent.js.map +1 -1
- package/dist/main/hooks/makePathDataArrayItemComponent.js +17 -21
- package/dist/main/hooks/makePathDataArrayItemComponent.js.map +1 -1
- package/dist/main/hooks/makePathDataComponent.js +31 -33
- package/dist/main/hooks/makePathDataComponent.js.map +1 -1
- package/dist/main/index.d.ts +304 -27
- package/dist/main/index.js +28 -7
- package/dist/main/promise/abortablePromise.js +10 -15
- package/dist/main/promise/abortablePromise.js.map +1 -1
- package/dist/main/promise/index.js +2 -3
- package/dist/main/utils/a11y.js +133 -0
- package/dist/main/utils/a11y.js.map +1 -0
- package/dist/main/utils/body-scroll-lock.js +40 -18
- package/dist/main/utils/body-scroll-lock.js.map +1 -1
- package/dist/main/utils/checkLoaded.js +4 -4
- package/dist/main/utils/checkLoaded.js.map +1 -1
- package/dist/main/utils/createRemoteContext.js +85 -0
- package/dist/main/utils/createRemoteContext.js.map +1 -0
- package/dist/main/utils/disclosure.js +52 -0
- package/dist/main/utils/disclosure.js.map +1 -0
- package/dist/main/utils/formatValue.js +14 -18
- package/dist/main/utils/formatValue.js.map +1 -1
- package/dist/main/utils/getContextFromProvider.js +15 -10
- package/dist/main/utils/getContextFromProvider.js.map +1 -1
- package/dist/main/utils/getTemplateContent.js +6 -7
- package/dist/main/utils/getTemplateContent.js.map +1 -1
- package/dist/main/utils/guarded-effect.js +72 -0
- package/dist/main/utils/guarded-effect.js.map +1 -0
- package/dist/main/utils/index.d.ts +237 -20
- package/dist/main/utils/index.js +15 -12
- package/dist/main/utils/invokeOnLoaded.js +13 -13
- package/dist/main/utils/invokeOnLoaded.js.map +1 -1
- package/dist/main/utils/isCustomElement.js +4 -3
- package/dist/main/utils/isCustomElement.js.map +1 -1
- package/dist/main/utils/nested-overlays.js +36 -0
- package/dist/main/utils/nested-overlays.js.map +1 -0
- package/dist/main/utils/solid-element.js +48 -88
- package/dist/main/utils/solid-element.js.map +1 -1
- package/dist/main/utils/toHyphenated.js +4 -3
- package/dist/main/utils/toHyphenated.js.map +1 -1
- package/package.json +16 -15
- package/dist/esm/animation/index.js +0 -97
- package/dist/esm/animation/index.js.map +0 -1
- package/dist/esm/focusTrap/index.js +0 -18
- package/dist/esm/focusTrap/index.js.map +0 -1
- package/dist/esm/hooks/index.js +0 -235
- package/dist/esm/hooks/index.js.map +0 -1
- package/dist/esm/index.js +0 -547
- package/dist/esm/index.js.map +0 -1
- package/dist/esm/promise/index.js +0 -20
- package/dist/esm/promise/index.js.map +0 -1
- package/dist/esm/utils/index.js +0 -236
- package/dist/esm/utils/index.js.map +0 -1
- package/dist/main/animation/index.js.map +0 -1
- package/dist/main/hooks/index.js.map +0 -1
- package/dist/main/hooks/internal/index.js +0 -3
- package/dist/main/hooks/internal/index.js.map +0 -1
- package/dist/main/hooks/internal/types.js +0 -3
- package/dist/main/hooks/internal/types.js.map +0 -1
- package/dist/main/index.js.map +0 -1
- package/dist/main/promise/index.js.map +0 -1
- package/dist/main/utils/createWithElementContext.js +0 -64
- package/dist/main/utils/createWithElementContext.js.map +0 -1
- package/dist/main/utils/index.js.map +0 -1
|
@@ -1,14 +1,13 @@
|
|
|
1
|
+
//#region src/hooks/internal/getValueFromPath.ts
|
|
1
2
|
function getValueFromPath(obj, path) {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
return acc[key];
|
|
9
|
-
}, obj);
|
|
3
|
+
return path.split(".").reduce((acc, key) => {
|
|
4
|
+
if (acc === null || acc === void 0) return void 0;
|
|
5
|
+
const isArrayIndex = !isNaN(Number(key)) && key.trim() !== "";
|
|
6
|
+
if (Array.isArray(acc) && isArrayIndex) return acc[Number(key)];
|
|
7
|
+
return acc[key];
|
|
8
|
+
}, obj);
|
|
10
9
|
}
|
|
11
|
-
|
|
10
|
+
//#endregion
|
|
12
11
|
export { getValueFromPath };
|
|
13
|
-
|
|
12
|
+
|
|
14
13
|
//# sourceMappingURL=getValueFromPath.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"getValueFromPath.js","names":[],"sources":["../../../../src/hooks/internal/getValueFromPath.ts"],"sourcesContent":["export type Path<T> = T extends readonly (infer U)[]\n\t? `${number}` | `${number}.${Path<U>}` // Allows indexing into readonly arrays\n\t: T extends object\n\t\t? {\n\t\t\t\t[K in keyof T & (string | number)]: T[K] extends object | any[]\n\t\t\t\t\t? `${K}` | `${K}.${Path<T[K]>}`\n\t\t\t\t\t: `${K}`;\n\t\t\t}[keyof T & (string | number)]\n\t\t: never;\n\nexport type PathValue<\n\tT,\n\tP extends string,\n> = P extends `${infer Key}.${infer Rest}`\n\t? Key extends keyof T\n\t\t? PathValue<T[Key], Rest>\n\t\t: Key extends `${number}`\n\t\t\t? T extends readonly (infer U)[]\n\t\t\t\t? PathValue<U, Rest>\n\t\t\t\t: undefined\n\t\t\t: undefined\n\t: P extends keyof T\n\t\t? T[P]\n\t\t: P extends `${number}`\n\t\t\t? T extends readonly (infer U)[]\n\t\t\t\t? U\n\t\t\t\t: undefined\n\t\t\t: undefined;\n\nexport function getValueFromPath<T, P extends Path<T>>(\n\tobj: T,\n\tpath: P,\n): PathValue<T, P> {\n\treturn path.split(\".\").reduce<any>((acc, key) => {\n\t\tif (acc === null || acc === undefined) return undefined;\n\n\t\tconst isArrayIndex = !isNaN(Number(key)) && key.trim() !== \"\";\n\t\tif (Array.isArray(acc) && isArrayIndex) {\n\t\t\treturn acc[Number(key)];\n\t\t}\n\n\t\treturn acc[key];\n\t}, obj) as PathValue<T, P>;\n}\n"],"mappings":";AA6BA,SAAgB,iBACf,KACA,MACkB;CAClB,OAAO,KAAK,MAAM,GAAG,CAAC,CAAC,QAAa,KAAK,QAAQ;EAChD,IAAI,QAAQ,QAAQ,QAAQ,KAAA,GAAW,OAAO,KAAA;EAE9C,MAAM,eAAe,CAAC,MAAM,OAAO,GAAG,CAAC,KAAK,IAAI,KAAK,MAAM;EAC3D,IAAI,MAAM,QAAQ,GAAG,KAAK,cACzB,OAAO,IAAI,OAAO,GAAG;EAGtB,OAAO,IAAI;CACZ,GAAG,GAAG;AACP"}
|
|
@@ -1,71 +1,61 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import
|
|
3
|
-
import { getValueFromPath } from
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
return null;
|
|
58
|
-
});
|
|
59
|
-
return formattedValue;
|
|
60
|
-
}
|
|
61
|
-
return {
|
|
62
|
-
provide: provide$1,
|
|
63
|
-
usePath,
|
|
64
|
-
usePathValue,
|
|
65
|
-
useFormattedValue
|
|
66
|
-
};
|
|
1
|
+
import { formatValue } from "../utils/formatValue.js";
|
|
2
|
+
import "../utils/index.js";
|
|
3
|
+
import { getValueFromPath } from "./internal/getValueFromPath.js";
|
|
4
|
+
import { createMemo } from "solid-js";
|
|
5
|
+
import { consume, createContext, provide } from "component-register";
|
|
6
|
+
//#region src/hooks/makePathContextHooks.ts
|
|
7
|
+
var makeFullPropertyPathContext = () => {
|
|
8
|
+
function createFullPathPropertyContext(options) {
|
|
9
|
+
return options.path;
|
|
10
|
+
}
|
|
11
|
+
const Context = createContext(createFullPathPropertyContext);
|
|
12
|
+
function provide$1({ element, path }) {
|
|
13
|
+
return provide(Context, { path }, element);
|
|
14
|
+
}
|
|
15
|
+
function useFullPropertyPathContext(context) {
|
|
16
|
+
return context;
|
|
17
|
+
}
|
|
18
|
+
function usePath(props) {
|
|
19
|
+
const basePath = useFullPropertyPathContext(consume(Context, props.element));
|
|
20
|
+
return createMemo(() => {
|
|
21
|
+
if (typeof basePath !== "function" && typeof props.path === "function") return props.path();
|
|
22
|
+
else if (typeof basePath === "function" && typeof props.path !== "function") return basePath();
|
|
23
|
+
else if (typeof basePath === "function" && typeof props.path === "function") return `${basePath()}.${props.path()}`;
|
|
24
|
+
return "";
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
function usePathValue(options) {
|
|
28
|
+
return createMemo(() => {
|
|
29
|
+
const data = options.data();
|
|
30
|
+
if (typeof options.path !== "function") return data;
|
|
31
|
+
const path = options.path();
|
|
32
|
+
if (!path) return data;
|
|
33
|
+
const v = getValueFromPath(data, path);
|
|
34
|
+
if (v === void 0 || v === null) return null;
|
|
35
|
+
return v;
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
function useFormattedValue(options) {
|
|
39
|
+
const value = usePathValue({
|
|
40
|
+
path: options.path,
|
|
41
|
+
data: options.data
|
|
42
|
+
});
|
|
43
|
+
return createMemo(() => {
|
|
44
|
+
const v = value();
|
|
45
|
+
if (v === null) return null;
|
|
46
|
+
if (typeof v === "string" || typeof v === "number" || typeof v === "boolean") return formatValue(options.format || "", v);
|
|
47
|
+
console.warn(`useFormattedValue: Unsupported value type. Expected string, number, or boolean. Received: ${typeof v}.`, v);
|
|
48
|
+
return null;
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
return {
|
|
52
|
+
provide: provide$1,
|
|
53
|
+
usePath,
|
|
54
|
+
usePathValue,
|
|
55
|
+
useFormattedValue
|
|
56
|
+
};
|
|
67
57
|
};
|
|
68
|
-
|
|
58
|
+
//#endregion
|
|
69
59
|
export { makeFullPropertyPathContext };
|
|
70
|
-
|
|
60
|
+
|
|
71
61
|
//# sourceMappingURL=makePathContextHooks.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"makePathContextHooks.js","names":[],"sources":["../../../src/hooks/makePathContextHooks.ts"],"sourcesContent":["import {\n\tconsume as _consume,\n\tprovide as _provide,\n\tcreateContext,\n\ttype ICustomElement,\n} from \"component-register\";\nimport { type Accessor, createMemo } from \"solid-js\";\nimport { type Format, formatValue } from \"../utils/index.js\";\nimport type { Path, PathValue } from \"./internal\";\nimport { getValueFromPath } from \"./internal/index.js\";\n\ntype WalkableNode = Parameters<typeof _provide>[2];\n\nexport type { Path, PathValue };\n\nexport const makeFullPropertyPathContext = <RootData = any>() => {\n\ttype FullPropertyPathContextType = ReturnType<\n\t\ttypeof createFullPathPropertyContext\n\t>;\n\n\ttype Options = {\n\t\tpath: Accessor<Path<RootData>>;\n\t\telement: HTMLElement & ICustomElement;\n\t};\n\tfunction createFullPathPropertyContext(\n\t\toptions: Options,\n\t): Accessor<Path<RootData>> {\n\t\treturn options.path;\n\t}\n\n\tconst Context = createContext(createFullPathPropertyContext);\n\n\tfunction provide({\n\t\telement,\n\t\tpath,\n\t}: {\n\t\telement: WalkableNode;\n\t\tpath: Accessor<Path<RootData>>;\n\t}): FullPropertyPathContextType {\n\t\treturn _provide(Context, { path }, element);\n\t}\n\n\tfunction useFullPropertyPathContext(context: FullPropertyPathContextType) {\n\t\treturn context;\n\t}\n\n\tfunction usePath(props: {\n\t\telement: HTMLElement & ICustomElement;\n\t\tpath?: Accessor<Path<RootData>>;\n\t}): Accessor<Path<RootData>> {\n\t\tconst context = _consume(Context, props.element);\n\t\tconst basePath = useFullPropertyPathContext(context);\n\t\treturn createMemo(() => {\n\t\t\tif (typeof basePath !== \"function\" && typeof props.path === \"function\") {\n\t\t\t\treturn props.path();\n\t\t\t} else if (\n\t\t\t\ttypeof basePath === \"function\" &&\n\t\t\t\ttypeof props.path !== \"function\"\n\t\t\t) {\n\t\t\t\treturn basePath();\n\t\t\t} else if (\n\t\t\t\ttypeof basePath === \"function\" &&\n\t\t\t\ttypeof props.path === \"function\"\n\t\t\t) {\n\t\t\t\treturn `${basePath()}.${props.path()}`;\n\t\t\t}\n\t\t\treturn \"\";\n\t\t\t// The memo can yield \"\" for a missing path, which is not a\n\t\t\t// `Path<RootData>`; this cast predates v2 and is preserved as-is. v2\n\t\t\t// needs the `unknown` hop because `createMemo` now returns\n\t\t\t// `SourceAccessor`, so the two types no longer overlap directly.\n\t\t}) as unknown as Accessor<Path<RootData>>;\n\t}\n\n\ttype PathValueOptions<P extends Path<RootData>> = {\n\t\tpath: Accessor<P>;\n\t\tdata: Accessor<PathValue<RootData, P>>;\n\t};\n\n\tfunction usePathValue<P extends Path<RootData>>(\n\t\toptions: PathValueOptions<P>,\n\t): Accessor<PathValue<RootData, P>> {\n\t\treturn createMemo(() => {\n\t\t\tconst data = options.data();\n\t\t\tif (typeof options.path !== \"function\") return data;\n\t\t\tconst path = options.path();\n\t\t\tif (!path) return data;\n\t\t\tconst v = getValueFromPath(data, path as any);\n\t\t\tif (v === undefined || v === null) return null;\n\t\t\treturn v;\n\t\t}) as Accessor<PathValue<RootData, P>>;\n\t}\n\n\ttype FormmatedValueOptions<P extends Path<RootData>> = {\n\t\tpath: Accessor<P>;\n\t\tformat?: Format;\n\t\tdata: Accessor<PathValue<RootData, P>>;\n\t};\n\n\tfunction useFormattedValue<P extends Path<RootData>>(\n\t\toptions: FormmatedValueOptions<P>,\n\t): Accessor<PathValue<RootData, P>> {\n\t\tconst value = usePathValue({ path: options.path, data: options.data });\n\n\t\tconst formattedValue = createMemo(() => {\n\t\t\tconst v = value();\n\t\t\tif (v === null) return null;\n\t\t\tif (\n\t\t\t\ttypeof v === \"string\" ||\n\t\t\t\ttypeof v === \"number\" ||\n\t\t\t\ttypeof v === \"boolean\"\n\t\t\t) {\n\t\t\t\treturn formatValue(options.format || \"\", v);\n\t\t\t}\n\t\t\tconsole.warn(\n\t\t\t\t`useFormattedValue: Unsupported value type. Expected string, number, or boolean. Received: ${typeof v}.`,\n\t\t\t\tv,\n\t\t\t);\n\t\t\treturn null;\n\t\t});\n\n\t\treturn formattedValue as Accessor<PathValue<RootData, P>>;\n\t}\n\n\treturn {\n\t\tprovide,\n\t\tusePath,\n\t\tusePathValue,\n\t\tuseFormattedValue,\n\t};\n};\n"],"mappings":";;;;;;AAeA,IAAa,oCAAoD;CAShE,SAAS,8BACR,SAC2B;EAC3B,OAAO,QAAQ;CAChB;CAEA,MAAM,UAAU,cAAc,6BAA6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@@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import { createMemo,
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
</${arrayItemName}>
|
|
61
|
-
`}
|
|
62
|
-
<//>
|
|
63
|
-
<//>
|
|
64
|
-
`;
|
|
65
|
-
};
|
|
1
|
+
import { getTemplateContent } from "../utils/getTemplateContent.js";
|
|
2
|
+
import "../utils/index.js";
|
|
3
|
+
import { createMemo, untrack } from "solid-js";
|
|
4
|
+
import { Dynamic, For, Show, createComponent } from "@solidjs/web";
|
|
5
|
+
//#region src/hooks/makePathDataArrayComponent.tsx
|
|
6
|
+
var makePathDataArrayComponent = ({ useRootData, hooks, name, arrayItemName }) => {
|
|
7
|
+
const { usePath, provide, usePathValue } = hooks;
|
|
8
|
+
return (props, { element }) => {
|
|
9
|
+
const itemTemplate = getTemplateContent(element, "item");
|
|
10
|
+
if (!itemTemplate) return console.warn(`${name}: No template found with a property of 'item'.`, element);
|
|
11
|
+
if (untrack(() => !props.arrayPath)) return console.warn(`${name}: No array path provided.`, element);
|
|
12
|
+
const data = useRootData(element);
|
|
13
|
+
const fullPath = usePath({
|
|
14
|
+
element,
|
|
15
|
+
path: () => props.arrayPath
|
|
16
|
+
});
|
|
17
|
+
provide({
|
|
18
|
+
element,
|
|
19
|
+
path: fullPath
|
|
20
|
+
});
|
|
21
|
+
const value = usePathValue({
|
|
22
|
+
path: fullPath,
|
|
23
|
+
data
|
|
24
|
+
});
|
|
25
|
+
const arrayValue = createMemo(() => {
|
|
26
|
+
const v = value();
|
|
27
|
+
if (!v) {
|
|
28
|
+
console.warn(`${name}: value is null or undefined at path ${fullPath()}`, element);
|
|
29
|
+
return null;
|
|
30
|
+
}
|
|
31
|
+
if (!Array.isArray(v)) {
|
|
32
|
+
console.warn(`${name}: value is not an array at path ${fullPath()}`, element);
|
|
33
|
+
return null;
|
|
34
|
+
}
|
|
35
|
+
return v;
|
|
36
|
+
});
|
|
37
|
+
element.replaceChildren(...[]);
|
|
38
|
+
return createComponent(Show, {
|
|
39
|
+
get when() {
|
|
40
|
+
return (arrayValue()?.length ?? 0) > 0;
|
|
41
|
+
},
|
|
42
|
+
get children() {
|
|
43
|
+
return createComponent(For, {
|
|
44
|
+
get each() {
|
|
45
|
+
return arrayValue() ?? [];
|
|
46
|
+
},
|
|
47
|
+
children: (_, idx) => createComponent(Dynamic, {
|
|
48
|
+
component: arrayItemName,
|
|
49
|
+
get "item-index"() {
|
|
50
|
+
return `${idx()}`;
|
|
51
|
+
},
|
|
52
|
+
get children() {
|
|
53
|
+
return Array.from(itemTemplate.cloneNode(true).childNodes);
|
|
54
|
+
}
|
|
55
|
+
})
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
};
|
|
66
60
|
};
|
|
67
|
-
|
|
61
|
+
//#endregion
|
|
68
62
|
export { makePathDataArrayComponent };
|
|
69
|
-
|
|
63
|
+
|
|
70
64
|
//# sourceMappingURL=makePathDataArrayComponent.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"makePathDataArrayComponent.js","names":["<Show when={(arrayValue()?.length ?? 0) > 0}>\n\t\t\t\t<For each={arrayValue() ?? []}>\n\t\t\t\t\t{(_, idx) => (\n\t\t\t\t\t\t<Dynamic component={arrayItemName} item-index={`${idx()}`}>\n\t\t\t\t\t\t\t{Array.from(itemTemplate.cloneNode(true).childNodes)}\n\t\t\t\t\t\t</Dynamic>\n\t\t\t\t\t)}\n\t\t\t\t</For>\n\t\t\t</Show>","<For each={arrayValue() ?? []}>\n\t\t\t\t\t{(_, idx) => (\n\t\t\t\t\t\t<Dynamic component={arrayItemName} item-index={`${idx()}`}>\n\t\t\t\t\t\t\t{Array.from(itemTemplate.cloneNode(true).childNodes)}\n\t\t\t\t\t\t</Dynamic>\n\t\t\t\t\t)}\n\t\t\t\t</For>","<Dynamic component={arrayItemName} item-index={`${idx()}`}>\n\t\t\t\t\t\t\t{Array.from(itemTemplate.cloneNode(true).childNodes)}\n\t\t\t\t\t\t</Dynamic>","component={arrayItemName}"],"sources":["../../../src/hooks/makePathDataArrayComponent.tsx"],"sourcesContent":["import { Dynamic, For, Show } from \"@solidjs/web\";\nimport { createMemo, untrack } from \"solid-js\";\nimport type { CorrectComponentType, Format } from \"../utils/index\";\nimport { getTemplateContent } from \"../utils/index.js\";\nimport type { BaseOptions } from \"./internal/types\";\nimport type { Path } from \"./makePathContextHooks\";\n\nexport const makePathDataArrayComponent = <RootData = any, Props = any>({\n\tuseRootData,\n\thooks,\n\tname,\n\tarrayItemName,\n}: BaseOptions<RootData> & { arrayItemName: string }): CorrectComponentType<\n\t{\n\t\tarrayPath: Path<RootData>;\n\t\tformat?: Format;\n\t} & Props\n> => {\n\tconst { usePath, provide, usePathValue } = hooks;\n\treturn (props, { element }) => {\n\t\tconst itemTemplate = getTemplateContent(element, \"item\");\n\t\tif (!itemTemplate)\n\t\t\treturn console.warn(\n\t\t\t\t`${name}: No template found with a property of 'item'.`,\n\t\t\t\telement,\n\t\t\t);\n\t\tif (untrack(() => !props.arrayPath))\n\t\t\treturn console.warn(`${name}: No array path provided.`, element);\n\n\t\tconst data = useRootData(element);\n\n\t\tconst fullPath = usePath({\n\t\t\telement,\n\t\t\tpath: () => props.arrayPath,\n\t\t});\n\n\t\tprovide({\n\t\t\telement,\n\t\t\tpath: fullPath,\n\t\t});\n\n\t\tconst value = usePathValue({\n\t\t\tpath: fullPath,\n\t\t\tdata: data as any,\n\t\t});\n\n\t\tconst arrayValue = createMemo(() => {\n\t\t\tconst v = value();\n\n\t\t\tif (!v) {\n\t\t\t\tconsole.warn(\n\t\t\t\t\t`${name}: value is null or undefined at path ${fullPath()}`,\n\t\t\t\t\telement,\n\t\t\t\t);\n\t\t\t\treturn null;\n\t\t\t}\n\n\t\t\tif (!Array.isArray(v)) {\n\t\t\t\tconsole.warn(\n\t\t\t\t\t`${name}: value is not an array at path ${fullPath()}`,\n\t\t\t\t\telement,\n\t\t\t\t);\n\t\t\t\treturn null;\n\t\t\t}\n\n\t\t\treturn v;\n\t\t});\n\t\telement.replaceChildren(...[]);\n\n\t\t// The item tag is data, not a literal, so it goes through `Dynamic`.\n\t\treturn (\n\t\t\t<Show when={(arrayValue()?.length ?? 0) > 0}>\n\t\t\t\t<For each={arrayValue() ?? []}>\n\t\t\t\t\t{(_, idx) => (\n\t\t\t\t\t\t<Dynamic component={arrayItemName} item-index={`${idx()}`}>\n\t\t\t\t\t\t\t{Array.from(itemTemplate.cloneNode(true).childNodes)}\n\t\t\t\t\t\t</Dynamic>\n\t\t\t\t\t)}\n\t\t\t\t</For>\n\t\t\t</Show>\n\t\t);\n\t};\n};\n"],"mappings":";;;;;AAOA,IAAa,8BAA2D,EACvE,aACA,OACA,MACA,oBAMI;CACJ,MAAM,EAAE,SAAS,SAAS,iBAAiB;CAC3C,QAAQ,OAAO,EAAE,cAAc;EAC9B,MAAM,eAAe,mB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
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
element,
|
|
17
|
-
path: fullPath
|
|
18
|
-
});
|
|
19
|
-
};
|
|
1
|
+
import { untrack } from "solid-js";
|
|
2
|
+
//#region src/hooks/makePathDataArrayItemComponent.ts
|
|
3
|
+
var makePathDataArrayItemComponent = ({ hooks, name }) => {
|
|
4
|
+
const { usePath, provide } = hooks;
|
|
5
|
+
return (props, { element }) => {
|
|
6
|
+
if (untrack(() => !props.itemIndex)) return console.warn(`${name}: No path attribute provided.`);
|
|
7
|
+
const fullPath = usePath({
|
|
8
|
+
path: () => props.itemIndex,
|
|
9
|
+
element
|
|
10
|
+
});
|
|
11
|
+
provide({
|
|
12
|
+
element,
|
|
13
|
+
path: fullPath
|
|
14
|
+
});
|
|
15
|
+
};
|
|
20
16
|
};
|
|
21
|
-
|
|
17
|
+
//#endregion
|
|
22
18
|
export { makePathDataArrayItemComponent };
|
|
23
|
-
|
|
19
|
+
|
|
24
20
|
//# sourceMappingURL=makePathDataArrayItemComponent.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"makePathDataArrayItemComponent.js","names":[],"sources":["../../../src/hooks/makePathDataArrayItemComponent.ts"],"sourcesContent":["import { untrack } from \"solid-js\";\nimport type { CorrectComponentType } from \"../utils/index\";\nimport type { BaseOptions } from \"./internal/types\";\nimport type { Path } from \"./makePathContextHooks\";\n\nexport const makePathDataArrayItemComponent = <\n\tRootData = any,\n\tProps extends { itemIndex: Path<RootData> } = any,\n>({\n\thooks,\n\tname,\n}: BaseOptions<RootData, Props>): CorrectComponentType<Props> => {\n\tconst { usePath, provide } = hooks;\n\treturn (props, { element }) => {\n\t\tif (untrack(() => !props.itemIndex))\n\t\t\treturn console.warn(`${name}: No path attribute provided.`);\n\n\t\tconst fullPath = usePath({\n\t\t\tpath: () => props.itemIndex,\n\t\t\telement,\n\t\t});\n\n\t\tprovide({\n\t\t\telement,\n\t\t\tpath: fullPath,\n\t\t});\n\t};\n};\n"],"mappings":";;AAKA,IAAa,kCAGX,EACD,OACA,WACgE;CAChE,MAAM,EAAE,SAAS,YAAY;CAC7B,QAAQ,OAAO,EAAE,cAAc;EAC9B,IAAI,cAAc,CAAC,MAAM,SAAS,GACjC,OAAO,QAAQ,KAAK,GAAG,KAAK,8BAA8B;EAE3D,MAAM,WAAW,QAAQ;GACxB,YAAY,MAAM;GAClB;EACD,CAAC;EAED,QAAQ;GACP;GACA,MAAM;EACP,CAAC;CACF;AACD"}
|
|
@@ -1,36 +1,34 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { Show } from
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
`;
|
|
31
|
-
};
|
|
1
|
+
import { untrack } from "solid-js";
|
|
2
|
+
import { Show, createComponent } from "@solidjs/web";
|
|
3
|
+
//#region src/hooks/makePathDataComponent.tsx
|
|
4
|
+
var makePathDataComponent = ({ useRootData, hooks, name }) => {
|
|
5
|
+
const { usePath, useFormattedValue } = hooks;
|
|
6
|
+
return (props, { element }) => {
|
|
7
|
+
if (untrack(() => !props.propertyName)) return console.warn(`${name}: No property-name attribute provided.`, element);
|
|
8
|
+
const data = useRootData(element);
|
|
9
|
+
const fullPath = usePath({
|
|
10
|
+
element,
|
|
11
|
+
path: () => props.propertyName
|
|
12
|
+
});
|
|
13
|
+
const formattedValue = useFormattedValue({
|
|
14
|
+
get format() {
|
|
15
|
+
return props.format;
|
|
16
|
+
},
|
|
17
|
+
path: fullPath,
|
|
18
|
+
data
|
|
19
|
+
});
|
|
20
|
+
const text = () => formattedValue();
|
|
21
|
+
return createComponent(Show, {
|
|
22
|
+
get when() {
|
|
23
|
+
return text() !== null;
|
|
24
|
+
},
|
|
25
|
+
get children() {
|
|
26
|
+
return text();
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
};
|
|
32
30
|
};
|
|
33
|
-
|
|
31
|
+
//#endregion
|
|
34
32
|
export { makePathDataComponent };
|
|
35
|
-
|
|
33
|
+
|
|
36
34
|
//# sourceMappingURL=makePathDataComponent.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"makePathDataComponent.js","names":["<Show when={text() !== null}>{text()}</Show>"],"sources":["../../../src/hooks/makePathDataComponent.tsx"],"sourcesContent":["import { Show } from \"@solidjs/web\";\nimport { untrack } from \"solid-js\";\nimport type { CorrectComponentType, Format } from \"../utils/index\";\nimport type { Path } from \"./internal\";\nimport type { BaseOptions } from \"./internal/types\";\n\nexport const makePathDataComponent = <RootData = any, Props = any>({\n\tuseRootData,\n\thooks,\n\tname,\n}: BaseOptions<RootData>): CorrectComponentType<\n\t{ propertyName: Path<RootData>; format?: Format } & Props\n> => {\n\tconst { usePath, useFormattedValue } = hooks;\n\treturn (props, { element }) => {\n\t\tif (untrack(() => !props.propertyName))\n\t\t\treturn console.warn(\n\t\t\t\t`${name}: No property-name attribute provided.`,\n\t\t\t\telement,\n\t\t\t);\n\t\tconst data = useRootData(element);\n\t\tconst fullPath = usePath({\n\t\t\telement,\n\t\t\tpath: () => props.propertyName,\n\t\t});\n\t\tconst formattedValue = useFormattedValue({\n\t\t\tget format() {\n\t\t\t\treturn props.format;\n\t\t\t},\n\t\t\tpath: fullPath,\n\t\t\tdata: data as any,\n\t\t});\n\t\t// `useFormattedValue` is declared as `Accessor<PathValue<...>>`, but it\n\t\t// only ever returns `formatValue`'s string or null. The declared generic\n\t\t// may be callable, which makes `<Show>`'s overloads ambiguous and would\n\t\t// let Solid *invoke* the child rather than render it.\n\t\tconst text = () => formattedValue() as string | null;\n\n\t\t// Control flow moved to `@solidjs/web` in v2, and this is JSX rather than\n\t\t// `solid-js/html` now that the build compiles it.\n\t\treturn <Show when={text() !== null}>{text()}</Show>;\n\t};\n};\n"],"mappings":";;;AAMA,IAAa,yBAAsD,EAClE,aACA,OACA,WAGI;CACJ,MAAM,EAAE,SAAS,sBAAsB;CACvC,QAAQ,OAAO,EAAE,cAAc;EAC9B,IAAI,cAAc,CAAC,MAAM,YAAY,GACpC,OAAO,QAAQ,KACd,GAAG,KAAK,yCACR,OACD;EACD,MAAM,OAAO,YAAY,OAAO;EAChC,MAAM,WAAW,QAAQ;GACxB;GACA,YAAY,MAAM;EACnB,CAAC;EACD,MAAM,iBAAiB,kBAAkB;GACxC,IAAI,SAAS;IACZ,OAAO,MAAM;GACd;GACA,MAAM;GACA;EACP,CAAC;EAKD,MAAM,aAAa,eAAe;EAIlC,OAAOA,gBAAAA,MAAAA;GAAM,IAAA,OAAA;IAAM,OAAA,KAAK,MAAM;GAAI;GAA3B,IAAA,WAAA;IAA8B,OAAA,KAAK;GAAQ;;CACnD;AACD"}
|