@ui0/composable 0.1.3 → 0.1.4

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
@@ -18,6 +18,13 @@ export declare function getUi0CoreInstance(vm?: import("vue").ComponentInternalI
18
18
  type WithIdFn = (str: string) => string;
19
19
  type LoggerFn = (str: string) => void;
20
20
  type ComponentId = string;
21
+ /**
22
+ * A component-scoped id, stable across SSR and hydration. Built on vue's
23
+ * useId: a per-component counter, so the same call order inside the
24
+ * component yields the same ids on the server and the client (the raw
25
+ * instance uid is a PROCESS-global counter and mismatches between the two
26
+ * environments).
27
+ */
21
28
  export declare function useComponentId(name?: string): [id: ComponentId, withId: WithIdFn, logId: LoggerFn];
22
29
  export {};
23
30
  //# sourceMappingURL=index.d.ts.map
@@ -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;wBAEW,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;wBCDrC,mBAAmB,mBAAE,mCAA0B;KCJ1D,YAAY;KACZ,YAAY;KACZ;;;;;;;;wBASW,eAAe,iBAAiB,IAAI,aAAa,QAAQ,UAAU,OAAO"}
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { newErrorForSetupCall, objectMerge } from "@ui0/util";
2
- import { getCurrentInstance, hasInjectionContext, inject, provide } from "vue";
2
+ import { getCurrentInstance, hasInjectionContext, inject, provide, useId } from "vue";
3
3
  // src/injectHost.ts
4
4
  /**
5
5
  * Inject hosted data previously provided under `key`.
@@ -35,10 +35,16 @@ function getUi0CoreInstance(vm = getCurrentInstance()) {
35
35
  return vm.appContext.config.globalProperties.$ui0;
36
36
  }
37
37
  // src/useComponentId.ts
38
+ /**
39
+ * A component-scoped id, stable across SSR and hydration. Built on vue's
40
+ * useId: a per-component counter, so the same call order inside the
41
+ * component yields the same ids on the server and the client (the raw
42
+ * instance uid is a PROCESS-global counter and mismatches between the two
43
+ * environments).
44
+ */
38
45
  function useComponentId(name) {
39
- const vm = getCurrentInstance();
40
- if (!vm) throw newErrorForSetupCall("useComponentId");
41
- const id = name ? name + "-" + vm.uid.toString() : vm.uid.toString();
46
+ if (!getCurrentInstance()) throw newErrorForSetupCall("useComponentId");
47
+ const id = name ? name + "-" + useId() : useId();
42
48
  const fn = (str) => str + "-" + id;
43
49
  const log = (...arg) => console.log(...arg);
44
50
  return [
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 } from 'vue'\ntype WithIdFn = (str: string) => string\ntype LoggerFn = (str: string) => void\ntype ComponentId = string\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 + '-' + vm.uid.toString() : vm.uid.toString()\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;;ACJA,SAAgB,eAAe,MAAqE;CAClG,MAAM,KAAK,mBAAmB;CAC9B,IAAI,CAAC,IAAI,MAAM,qBAAqB,gBAAgB;CAEpD,MAAM,KAAkB,OAAO,OAAO,MAAM,GAAG,IAAI,SAAS,IAAI,GAAG,IAAI,SAAS;CAEhF,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 { 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"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ui0/composable",
3
- "version": "0.1.3",
3
+ "version": "0.1.4",
4
4
  "description": "ui0 composables",
5
5
  "files": [
6
6
  "dist"
@@ -19,11 +19,12 @@
19
19
  "build": "tsdown",
20
20
  "dev": "tsdown --watch",
21
21
  "typecheck": "tsc -p tsconfig.json --noEmit",
22
- "test": "vitest run --passWithNoTests"
22
+ "test": "vitest run --passWithNoTests",
23
+ "composable:publish": "node ../../scripts/publish-packages.ts"
23
24
  },
24
25
  "dependencies": {
25
- "@ui0/types": "^0.1.3",
26
- "@ui0/util": "^0.0.4"
26
+ "@ui0/types": "^0.1.4",
27
+ "@ui0/util": "^0.0.5"
27
28
  },
28
29
  "peerDependencies": {
29
30
  "vue": "^3.5.45"