@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 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(vm?: import("vue").ComponentInternalInstance | null): Ui0CoreInstance;
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;
@@ -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;wBCDrC,mBAAmB,mBAAE,mCAA0B;KCJ1D,YAAY;KACZ,YAAY;KACZ;;;;;;;;wBASW,eAAe,iBAAiB,IAAI,aAAa,QAAQ,UAAU,OAAO"}
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 { newErrorForSetupCall, objectMerge } from "@ui0/util";
2
- import { getCurrentInstance, hasInjectionContext, inject, provide, useId } from "vue";
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
- function getUi0CoreInstance(vm = getCurrentInstance()) {
34
- if (!vm) throw new Error("getFrameworkInstance: called outside of a component setup");
35
- return vm.appContext.config.globalProperties.$ui0;
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 { getCurrentInstance } from 'vue'\n\n// The app-level ui0 runtime, exposed on globalProperties.$ui0 by the host app's\n// ui0 plugin. Holds the live theme instance (see the @ui0/types augmentation in\n// theme.runtime.types).\nexport function getUi0CoreInstance(vm = getCurrentInstance()): Ui0CoreInstance {\n if (!vm)\n throw new Error('getFrameworkInstance: called outside of a component setup')\n return vm.appContext.config.globalProperties.$ui0 as Ui0CoreInstance\n}\n","import { newErrorForSetupCall } from '@ui0/util'\nimport { getCurrentInstance, 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 vm = getCurrentInstance()\n if (!vm) throw newErrorForSetupCall('useComponentId')\n\n const id: ComponentId = name ? name + '-' + useId() : useId()\n\n const fn = (str: string) => str + '-' + id\n const log = (...arg: []) => console.log(...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,SAAgB,mBAAmB,KAAK,mBAAmB,GAAoB;CAC7E,IAAI,CAAC,IACH,MAAM,IAAI,MAAM,2DAA2D;CAC7E,OAAO,GAAG,WAAW,OAAO,iBAAiB;AAC/C;;;;;;;;;ACGA,SAAgB,eAAe,MAAqE;CAElG,IAAI,CADO,mBACL,GAAG,MAAM,qBAAqB,gBAAgB;CAEpD,MAAM,KAAkB,OAAO,OAAO,MAAM,MAAM,IAAI,MAAM;CAE5D,MAAM,MAAM,QAAgB,MAAM,MAAM;CACxC,MAAM,OAAO,GAAG,QAAY,QAAQ,IAAI,GAAG,GAAG;CAE9C,OAAO;EAAC;EAAI;EAAI;CAAG;AACrB"}
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.4",
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.4",
27
- "@ui0/util": "^0.0.5"
26
+ "@ui0/types": "^0.1.7",
27
+ "@ui0/util": "^0.0.8"
28
28
  },
29
29
  "peerDependencies": {
30
30
  "vue": "^3.5.45"