@ui0/composable 0.0.0-stage → 0.1.1

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.
@@ -0,0 +1,23 @@
1
+ import { InjectionKey } from "vue";
2
+ import { Ui0CoreInstance } from "@ui0/types";
3
+ /**
4
+ * Provide hosted data.
5
+ * set `inherit` to `t
6
+ * @param key
7
+ * @param data
8
+ * @param inherit
9
+ */
10
+ export declare function provideHost<T>(key: InjectionKey<T>, data: T, inherit?: boolean): T;
11
+ /**
12
+ * Inject hosted data previously provided under `key`.
13
+ * @param key injection key
14
+ * @returns the injected value, or `undefined` when nothing was provided
15
+ */
16
+ export declare function injectHost<T>(key: InjectionKey<T>): T | undefined;
17
+ export declare function getUi0CoreInstance(vm?: import("vue").ComponentInternalInstance | null): Ui0CoreInstance;
18
+ type WithIdFn = (str: string) => string;
19
+ type LoggerFn = (str: string) => void;
20
+ type ComponentId = string;
21
+ export declare function useComponentId(name?: string): [id: ComponentId, withId: WithIdFn, logId: LoggerFn];
22
+ export {};
23
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +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"}
package/dist/index.js ADDED
@@ -0,0 +1,52 @@
1
+ import { newErrorForSetupCall, objectMerge } from "@ui0/util";
2
+ import { getCurrentInstance, hasInjectionContext, inject, provide } from "vue";
3
+ // src/injectHost.ts
4
+ /**
5
+ * Inject hosted data previously provided under `key`.
6
+ * @param key injection key
7
+ * @returns the injected value, or `undefined` when nothing was provided
8
+ */
9
+ function injectHost(key) {
10
+ return inject(key, void 0);
11
+ }
12
+ // src/provideHost.ts
13
+ /**
14
+ * Provide hosted data.
15
+ * set `inherit` to `t
16
+ * @param key
17
+ * @param data
18
+ * @param inherit
19
+ */
20
+ function provideHost(key, data, inherit = false) {
21
+ if (inherit && hasInjectionContext()) {
22
+ const injection = injectHost(key);
23
+ if (injection) {
24
+ const merged = objectMerge(injection, data, { mergeFunctions: true });
25
+ provide(key, merged);
26
+ return merged;
27
+ }
28
+ }
29
+ provide(key, data);
30
+ return data;
31
+ }
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;
36
+ }
37
+ // src/useComponentId.ts
38
+ function useComponentId(name) {
39
+ const vm = getCurrentInstance();
40
+ if (!vm) throw newErrorForSetupCall("useComponentId");
41
+ const id = name ? name + "-" + vm.uid.toString() : vm.uid.toString();
42
+ const fn = (str) => str + "-" + id;
43
+ const log = (...arg) => console.log(...arg);
44
+ return [
45
+ id,
46
+ fn,
47
+ log
48
+ ];
49
+ }
50
+ export { getUi0CoreInstance, injectHost, provideHost, useComponentId };
51
+
52
+ //# sourceMappingURL=index.js.map
@@ -0,0 +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"}
package/package.json CHANGED
@@ -1,6 +1,31 @@
1
1
  {
2
2
  "name": "@ui0/composable",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.1.1",
4
+ "description": "ui0 composables",
5
+ "files": [
6
+ "dist"
7
+ ],
8
+ "type": "module",
9
+ "sideEffects": false,
10
+ "module": "./dist/index.js",
11
+ "types": "./dist/index.d.ts",
12
+ "exports": {
13
+ ".": {
14
+ "types": "./dist/index.d.ts",
15
+ "import": "./dist/index.js"
16
+ }
17
+ },
18
+ "scripts": {
19
+ "build": "tsdown",
20
+ "dev": "tsdown --watch",
21
+ "typecheck": "tsc -p tsconfig.json --noEmit",
22
+ "test": "vitest run --passWithNoTests"
23
+ },
24
+ "dependencies": {
25
+ "@ui0/types": "0.1.1",
26
+ "@ui0/util": "0.0.2"
27
+ },
28
+ "peerDependencies": {
29
+ "vue": "^3.5.45"
30
+ }
31
+ }
package/README.md DELETED
@@ -1,3 +0,0 @@
1
- # Temporary Holding Version
2
-
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.