@ui0/composable 0.1.4 → 0.1.6
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/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +6 -7
- package/dist/index.js.map +1 -1
- package/package.json +4 -4
package/dist/index.d.ts
CHANGED
|
@@ -14,7 +14,7 @@ export declare function provideHost<T>(key: InjectionKey<T>, data: T, inherit?:
|
|
|
14
14
|
* @returns the injected value, or `undefined` when nothing was provided
|
|
15
15
|
*/
|
|
16
16
|
export declare function injectHost<T>(key: InjectionKey<T>): T | undefined;
|
|
17
|
-
export declare function getUi0CoreInstance(
|
|
17
|
+
export declare function getUi0CoreInstance(): Ui0CoreInstance | undefined;
|
|
18
18
|
type WithIdFn = (str: string) => string;
|
|
19
19
|
type LoggerFn = (str: string) => void;
|
|
20
20
|
type ComponentId = string;
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","names":[],"sources":["../src/provideHost.ts","../src/injectHost.ts","../src/getUi0CoreInstance.ts","../src/useComponentId.ts"],"mappings":";;;;;;;;;wBAYgB,YAAY,GAC1B,KAAK,aAAa,IAClB,MAAM,GACN,oBAAwB;;;;;;wBCRV,WAAW,GAAG,KAAK,aAAa,KAAK;
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":[],"sources":["../src/provideHost.ts","../src/injectHost.ts","../src/getUi0CoreInstance.ts","../src/useComponentId.ts"],"mappings":";;;;;;;;;wBAYgB,YAAY,GAC1B,KAAK,aAAa,IAClB,MAAM,GACN,oBAAwB;;;;;;wBCRV,WAAW,GAAG,KAAK,aAAa,KAAK;wBCArC,sBAAsB;KCNjC,YAAY;KACZ,YAAY;KACZ;;;;;;;;wBASW,eAAe,iBAAiB,IAAI,aAAa,QAAQ,UAAU,OAAO"}
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { objectMerge } from "@ui0/util";
|
|
2
|
+
import { hasInjectionContext, inject, provide, useId } from "vue";
|
|
3
3
|
// src/injectHost.ts
|
|
4
4
|
/**
|
|
5
5
|
* Inject hosted data previously provided under `key`.
|
|
@@ -30,9 +30,9 @@ function provideHost(key, data, inherit = false) {
|
|
|
30
30
|
return data;
|
|
31
31
|
}
|
|
32
32
|
// src/getUi0CoreInstance.ts
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
return
|
|
33
|
+
const Ui0CoreKey = Symbol.for("ui0-core");
|
|
34
|
+
function getUi0CoreInstance() {
|
|
35
|
+
if (hasInjectionContext()) return inject(Ui0CoreKey);
|
|
36
36
|
}
|
|
37
37
|
// src/useComponentId.ts
|
|
38
38
|
/**
|
|
@@ -43,10 +43,9 @@ function getUi0CoreInstance(vm = getCurrentInstance()) {
|
|
|
43
43
|
* environments).
|
|
44
44
|
*/
|
|
45
45
|
function useComponentId(name) {
|
|
46
|
-
if (!getCurrentInstance()) throw newErrorForSetupCall("useComponentId");
|
|
47
46
|
const id = name ? name + "-" + useId() : useId();
|
|
48
47
|
const fn = (str) => str + "-" + id;
|
|
49
|
-
const log = (...arg) => console.log(...arg);
|
|
48
|
+
const log = (...arg) => console.log(id, ...arg);
|
|
50
49
|
return [
|
|
51
50
|
id,
|
|
52
51
|
fn,
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":[],"sources":["../src/injectHost.ts","../src/provideHost.ts","../src/getUi0CoreInstance.ts","../src/useComponentId.ts"],"sourcesContent":["import { inject, type InjectionKey } from 'vue'\n\n/**\n * Inject hosted data previously provided under `key`.\n * @param key injection key\n * @returns the injected value, or `undefined` when nothing was provided\n */\nexport function injectHost<T>(key: InjectionKey<T>): T | undefined {\n return inject(key, undefined)\n}\n","import { objectMerge } from '@ui0/util'\nimport { hasInjectionContext, type InjectionKey, provide } from 'vue'\n\nimport { injectHost } from './injectHost'\n\n/**\n * Provide hosted data.\n * set `inherit` to `t\n * @param key\n * @param data\n * @param inherit\n */\nexport function provideHost<T>(\n key: InjectionKey<T>,\n data: T,\n inherit: boolean = false\n) {\n if (inherit && hasInjectionContext()) {\n const injection = injectHost(key)\n if (injection) {\n // merging with previous keyed-instance\n const merged = objectMerge(injection, data, { mergeFunctions: true })\n\n provide(key, merged)\n return merged\n }\n }\n\n provide(key, data)\n return data\n}\n","import type { Ui0CoreInstance } from '@ui0/types'\nimport {
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../src/injectHost.ts","../src/provideHost.ts","../src/getUi0CoreInstance.ts","../src/useComponentId.ts"],"sourcesContent":["import { inject, type InjectionKey } from 'vue'\n\n/**\n * Inject hosted data previously provided under `key`.\n * @param key injection key\n * @returns the injected value, or `undefined` when nothing was provided\n */\nexport function injectHost<T>(key: InjectionKey<T>): T | undefined {\n return inject(key, undefined)\n}\n","import { objectMerge } from '@ui0/util'\nimport { hasInjectionContext, type InjectionKey, provide } from 'vue'\n\nimport { injectHost } from './injectHost'\n\n/**\n * Provide hosted data.\n * set `inherit` to `t\n * @param key\n * @param data\n * @param inherit\n */\nexport function provideHost<T>(\n key: InjectionKey<T>,\n data: T,\n inherit: boolean = false\n) {\n if (inherit && hasInjectionContext()) {\n const injection = injectHost(key)\n if (injection) {\n // merging with previous keyed-instance\n const merged = objectMerge(injection, data, { mergeFunctions: true })\n\n provide(key, merged)\n return merged\n }\n }\n\n provide(key, data)\n return data\n}\n","import type { Ui0CoreInstance } from '@ui0/types'\nimport { hasInjectionContext, inject, type InjectionKey } from 'vue'\n\n// The app-level ui0 runtime, provided under Ui0CoreKey by the host app's\n// ui0 plugin. Holds the live theme instance (see the @ui0/types augmentation\n// in theme.runtime.types).\nexport const Ui0CoreKey = Symbol.for('ui0-core') as InjectionKey<Ui0CoreInstance>\nexport function getUi0CoreInstance(): Ui0CoreInstance | undefined {\n if (hasInjectionContext()) {\n return inject(Ui0CoreKey)\n }\n return undefined\n}\n","import { useId } from 'vue'\ntype WithIdFn = (str: string) => string\ntype LoggerFn = (str: string) => void\ntype ComponentId = string\n\n/**\n * A component-scoped id, stable across SSR and hydration. Built on vue's\n * useId: a per-component counter, so the same call order inside the\n * component yields the same ids on the server and the client (the raw\n * instance uid is a PROCESS-global counter and mismatches between the two\n * environments).\n */\nexport function useComponentId(name?: string): [id: ComponentId, withId: WithIdFn, logId: LoggerFn] {\n const id: ComponentId = name ? name + '-' + useId() : useId()\n\n const fn = (str: string) => str + '-' + id\n\n const log = (...arg: []) => console.log(id, ...arg)\n\n return [id, fn, log]\n}\n"],"mappings":";;;;;;;;AAOA,SAAgB,WAAc,KAAqC;CACjE,OAAO,OAAO,KAAK,KAAA,CAAS;AAC9B;;;;;;;;;ACGA,SAAgB,YACd,KACA,MACA,UAAmB,OACnB;CACA,IAAI,WAAW,oBAAoB,GAAG;EACpC,MAAM,YAAY,WAAW,GAAG;EAChC,IAAI,WAAW;GAEb,MAAM,SAAS,YAAY,WAAW,MAAM,EAAE,gBAAgB,KAAK,CAAC;GAEpE,QAAQ,KAAK,MAAM;GACnB,OAAO;EACT;CACF;CAEA,QAAQ,KAAK,IAAI;CACjB,OAAO;AACT;;ACxBA,MAAa,aAAa,OAAO,IAAI,UAAU;AAC/C,SAAgB,qBAAkD;CAChE,IAAI,oBAAoB,GACtB,OAAO,OAAO,UAAU;AAG5B;;;;;;;;;ACAA,SAAgB,eAAe,MAAqE;CAClG,MAAM,KAAkB,OAAO,OAAO,MAAM,MAAM,IAAI,MAAM;CAE5D,MAAM,MAAM,QAAgB,MAAM,MAAM;CAExC,MAAM,OAAO,GAAG,QAAY,QAAQ,IAAI,IAAI,GAAG,GAAG;CAElD,OAAO;EAAC;EAAI;EAAI;CAAG;AACrB"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ui0/composable",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.6",
|
|
4
4
|
"description": "ui0 composables",
|
|
5
5
|
"files": [
|
|
6
6
|
"dist"
|
|
@@ -16,15 +16,15 @@
|
|
|
16
16
|
}
|
|
17
17
|
},
|
|
18
18
|
"scripts": {
|
|
19
|
-
"build": "tsdown",
|
|
19
|
+
"composable:build": "tsdown",
|
|
20
20
|
"dev": "tsdown --watch",
|
|
21
21
|
"typecheck": "tsc -p tsconfig.json --noEmit",
|
|
22
22
|
"test": "vitest run --passWithNoTests",
|
|
23
23
|
"composable:publish": "node ../../scripts/publish-packages.ts"
|
|
24
24
|
},
|
|
25
25
|
"dependencies": {
|
|
26
|
-
"@ui0/types": "^0.1.
|
|
27
|
-
"@ui0/util": "^0.0.
|
|
26
|
+
"@ui0/types": "^0.1.7",
|
|
27
|
+
"@ui0/util": "^0.0.8"
|
|
28
28
|
},
|
|
29
29
|
"peerDependencies": {
|
|
30
30
|
"vue": "^3.5.45"
|