From d3be527a0b1d9762b68694828e2a4a18691e02a5 Mon Sep 17 00:00:00 2001 From: Ramzo <115036895+ramzzo@users.noreply.github.com> Date: Wed, 2 Aug 2023 16:58:45 +0000 Subject: [PATCH 1/3] core package direction (#243) --- packages/components/direction/README.md | 7 +++ packages/components/direction/build.config.ts | 12 +++++ packages/components/direction/package.json | 45 +++++++++++++++++++ .../components/direction/src/Direction.ts | 35 +++++++++++++++ packages/components/direction/src/index.ts | 7 +++ packages/components/direction/tsconfig.json | 11 +++++ packages/components/direction/tsup.config.ts | 21 +++++++++ pnpm-lock.yaml | 17 ++++--- 8 files changed, 149 insertions(+), 6 deletions(-) create mode 100644 packages/components/direction/README.md create mode 100644 packages/components/direction/build.config.ts create mode 100644 packages/components/direction/package.json create mode 100644 packages/components/direction/src/Direction.ts create mode 100644 packages/components/direction/src/index.ts create mode 100644 packages/components/direction/tsconfig.json create mode 100644 packages/components/direction/tsup.config.ts diff --git a/packages/components/direction/README.md b/packages/components/direction/README.md new file mode 100644 index 000000000..f3777c8e0 --- /dev/null +++ b/packages/components/direction/README.md @@ -0,0 +1,7 @@ +# `@oku-ui/direction` + +## Installation + +```sh +$ pnpm add @oku-ui/direction +``` \ No newline at end of file diff --git a/packages/components/direction/build.config.ts b/packages/components/direction/build.config.ts new file mode 100644 index 000000000..b972b9a78 --- /dev/null +++ b/packages/components/direction/build.config.ts @@ -0,0 +1,12 @@ +import { defineBuildConfig } from 'unbuild' + +export default defineBuildConfig({ + entries: [ + { + builder: 'mkdist', + input: './src/', + pattern: ['**/!(*.test|*.stories).ts'], + }, + ], + declaration: true, +}) diff --git a/packages/components/direction/package.json b/packages/components/direction/package.json new file mode 100644 index 000000000..e92fd5c63 --- /dev/null +++ b/packages/components/direction/package.json @@ -0,0 +1,45 @@ +{ + "name": "@oku-ui/direction", + "type": "module", + "version": "0.2.3", + "license": "MIT", + "source": "src/index.ts", + "funding": "https://github.com/sponsors/productdevbook", + "homepage": "https://oku-ui.com/primitives", + "repository": { + "type": "git", + "url": "git+https://github.com/oku-ui/primitives.git", + "directory": "packages/components/direction" + }, + "bugs": { + "url": "https://github.com/oku-ui/primitives/issues" + }, + "exports": { + ".": { + "types": "./dist/index.d.ts", + "import": "./dist/index.mjs" + } + }, + "module": "./dist/index.mjs", + "types": "./dist/index.d.ts", + "files": [ + "dist" + ], + "engines": { + "node": ">=18" + }, + "scripts": { + "build": "tsup", + "dev": "tsup --watch" + }, + "peerDependencies": { + "vue": "^3.3.0" + }, + "devDependencies": { + "tsconfig": "workspace:^" + }, + "publishConfig": { + "access": "public" + } + } + \ No newline at end of file diff --git a/packages/components/direction/src/Direction.ts b/packages/components/direction/src/Direction.ts new file mode 100644 index 000000000..0cc5c267e --- /dev/null +++ b/packages/components/direction/src/Direction.ts @@ -0,0 +1,35 @@ +import { defineComponent, inject, provide } from 'vue' + +type Direction = 'ltr' | 'rtl' +const DirectionContextSymbol = Symbol('DirectionContext') + +/* ------------------------------------------------------------------------------------------------- + * Direction + * ----------------------------------------------------------------------------------------------- */ + +const DirectionProvider = defineComponent({ + name: 'DirectionProvider', + props: { + dir: { type: String as () => Direction, required: true }, + }, + setup(props, { slots }) { + // Direction context + provide(DirectionContextSymbol, props.dir) + return () => slots.default?.() + }, +}) + +/* ----------------------------------------------------------------------------------------------- */ + +function useDirection(localDir?: Direction) { + const globalDir = inject(DirectionContextSymbol, null) + return localDir || globalDir || 'ltr' +} + +const Provider = DirectionProvider + +export { + useDirection, + Provider, + DirectionProvider, +} diff --git a/packages/components/direction/src/index.ts b/packages/components/direction/src/index.ts new file mode 100644 index 000000000..bc747495f --- /dev/null +++ b/packages/components/direction/src/index.ts @@ -0,0 +1,7 @@ +export { + useDirection, + // + Provider, + // + DirectionProvider, +} from './Direction' diff --git a/packages/components/direction/tsconfig.json b/packages/components/direction/tsconfig.json new file mode 100644 index 000000000..8a4646923 --- /dev/null +++ b/packages/components/direction/tsconfig.json @@ -0,0 +1,11 @@ +{ + "extends": "tsconfig/node16.json", + "compilerOptions": { + "rootDir": "src", + "outDir": "dist" + }, + "include": [ + "src" + ] + } + \ No newline at end of file diff --git a/packages/components/direction/tsup.config.ts b/packages/components/direction/tsup.config.ts new file mode 100644 index 000000000..61f14f532 --- /dev/null +++ b/packages/components/direction/tsup.config.ts @@ -0,0 +1,21 @@ +import { defineConfig } from 'tsup' +import pkg from './package.json' + +const external = [ + ...Object.keys(pkg.peerDependencies || {}), +] + +export default defineConfig((options) => { + return [ + { + ...options, + entryPoints: ['src/index.ts'], + external, + dts: true, + clean: true, + target: 'node16', + format: ['esm'], + outExtension: () => ({ js: '.mjs' }), + }, + ] +}) diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index f4a80cf0d..6248111a1 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -292,6 +292,16 @@ importers: specifier: workspace:^ version: link:../../tsconfig + packages/components/direction: + dependencies: + vue: + specifier: ^3.3.0 + version: 3.3.4 + devDependencies: + tsconfig: + specifier: workspace:^ + version: link:../../tsconfig + packages/components/label: dependencies: '@oku-ui/primitive': @@ -9247,11 +9257,6 @@ packages: resolution: {integrity: sha512-1BC0BVFhS/p0qtw6enp8e+8OD0UrK0oFLztSjNzhcKA3WDuJxxAPXzPuPtKkjEY9UUoEWlX/8fgKeu2S8i9JTA==} engines: {node: '>= 0.4'} - /is-core-module@2.12.0: - resolution: {integrity: sha512-RECHCBCd/viahWmwj6enj19sKbHfJrddi/6cBDsNTKbNq0f7VeaUkBo60BqzvPqo/W54ChS62Z5qyun7cfOMqQ==} - dependencies: - has: 1.0.3 - /is-core-module@2.12.1: resolution: {integrity: sha512-Q4ZuBAe2FUsKtyQJoQHlvP8OvBERxO3jEmy1I7hcRXcJBGGHFh/aJBswbXuS9sgrDH2QUO8ilkwNPHvHMd8clg==} dependencies: @@ -12319,7 +12324,7 @@ packages: resolution: {integrity: sha512-Sb+mjNHOULsBv818T40qSPeRiuWLyaGMa5ewydRLFimneixmVy2zdivRl+AF6jaYPC8ERxGDmFSiqui6SfPd+g==} hasBin: true dependencies: - is-core-module: 2.12.0 + is-core-module: 2.12.1 path-parse: 1.0.7 supports-preserve-symlinks-flag: 1.0.0 From 681ba7c618aad2ddd67f382462ec663275d27ba4 Mon Sep 17 00:00:00 2001 From: "autofix-ci[bot]" <114827586+autofix-ci[bot]@users.noreply.github.com> Date: Wed, 2 Aug 2023 17:17:07 +0000 Subject: [PATCH 2/3] fix: lint issues --- packages/components/direction/package.json | 83 ++++++++++----------- packages/components/direction/tsconfig.json | 19 +++-- 2 files changed, 50 insertions(+), 52 deletions(-) diff --git a/packages/components/direction/package.json b/packages/components/direction/package.json index e92fd5c63..06ebed608 100644 --- a/packages/components/direction/package.json +++ b/packages/components/direction/package.json @@ -1,45 +1,44 @@ { - "name": "@oku-ui/direction", - "type": "module", - "version": "0.2.3", - "license": "MIT", - "source": "src/index.ts", - "funding": "https://github.com/sponsors/productdevbook", - "homepage": "https://oku-ui.com/primitives", - "repository": { - "type": "git", - "url": "git+https://github.com/oku-ui/primitives.git", - "directory": "packages/components/direction" - }, - "bugs": { - "url": "https://github.com/oku-ui/primitives/issues" - }, - "exports": { - ".": { - "types": "./dist/index.d.ts", - "import": "./dist/index.mjs" - } - }, - "module": "./dist/index.mjs", - "types": "./dist/index.d.ts", - "files": [ - "dist" - ], - "engines": { - "node": ">=18" - }, - "scripts": { - "build": "tsup", - "dev": "tsup --watch" - }, - "peerDependencies": { - "vue": "^3.3.0" - }, - "devDependencies": { - "tsconfig": "workspace:^" - }, - "publishConfig": { - "access": "public" + "name": "@oku-ui/direction", + "type": "module", + "version": "0.2.3", + "license": "MIT", + "source": "src/index.ts", + "funding": "https://github.com/sponsors/productdevbook", + "homepage": "https://oku-ui.com/primitives", + "repository": { + "type": "git", + "url": "git+https://github.com/oku-ui/primitives.git", + "directory": "packages/components/direction" + }, + "bugs": { + "url": "https://github.com/oku-ui/primitives/issues" + }, + "exports": { + ".": { + "types": "./dist/index.d.ts", + "import": "./dist/index.mjs" } + }, + "module": "./dist/index.mjs", + "types": "./dist/index.d.ts", + "files": [ + "dist" + ], + "engines": { + "node": ">=18" + }, + "scripts": { + "build": "tsup", + "dev": "tsup --watch" + }, + "peerDependencies": { + "vue": "^3.3.0" + }, + "devDependencies": { + "tsconfig": "workspace:^" + }, + "publishConfig": { + "access": "public" } - \ No newline at end of file +} diff --git a/packages/components/direction/tsconfig.json b/packages/components/direction/tsconfig.json index 8a4646923..b8dfa9041 100644 --- a/packages/components/direction/tsconfig.json +++ b/packages/components/direction/tsconfig.json @@ -1,11 +1,10 @@ { - "extends": "tsconfig/node16.json", - "compilerOptions": { - "rootDir": "src", - "outDir": "dist" - }, - "include": [ - "src" - ] - } - \ No newline at end of file + "extends": "tsconfig/node16.json", + "compilerOptions": { + "rootDir": "src", + "outDir": "dist" + }, + "include": [ + "src" + ] +} From 38410dab522d6450ce95843880f251628bcea954 Mon Sep 17 00:00:00 2001 From: Ramzo <115036895+ramzzo@users.noreply.github.com> Date: Thu, 3 Aug 2023 10:54:28 +0000 Subject: [PATCH 3/3] fix --- packages/components/direction/src/Direction.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/components/direction/src/Direction.ts b/packages/components/direction/src/Direction.ts index 0cc5c267e..55094db59 100644 --- a/packages/components/direction/src/Direction.ts +++ b/packages/components/direction/src/Direction.ts @@ -1,4 +1,4 @@ -import { defineComponent, inject, provide } from 'vue' +import { type PropType, defineComponent, inject, provide } from 'vue' type Direction = 'ltr' | 'rtl' const DirectionContextSymbol = Symbol('DirectionContext') @@ -10,7 +10,7 @@ const DirectionContextSymbol = Symbol('DirectionContext') const DirectionProvider = defineComponent({ name: 'DirectionProvider', props: { - dir: { type: String as () => Direction, required: true }, + dir: { type: String as PropType, required: true }, }, setup(props, { slots }) { // Direction context