@crabs-dev/dtwo 0.4.9

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/README.md ADDED
@@ -0,0 +1,28 @@
1
+ # `@crabs-dev/dtwo`
2
+
3
+ > Dtwo 2 & 3 module
4
+
5
+ ## Installation
6
+
7
+ ```shell
8
+ npm i @crabs-dev/dtwo
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ Add to `modules` (Dtwo 3) or `buildModules` (Dtwo 2) in `dtwo.config.js`:
14
+
15
+ ```js
16
+ // Dtwo 2
17
+ export default {
18
+ buildModules: [['@crabs-dev/dtwo', { disableKdux: true }]],
19
+ }
20
+ // Dtwo 3
21
+ export default defineDtwoConfig({
22
+ modules: ['@crabs-dev/dtwo'],
23
+ })
24
+ ```
25
+
26
+ ## License
27
+
28
+ [MIT](http://opensource.org/licenses/MIT)
@@ -0,0 +1,5 @@
1
+ module.exports = function(...args) {
2
+ return import('./module.mjs').then(m => m.default.call(this, ...args))
3
+ }
4
+ const _meta = module.exports.meta = require('./module.json')
5
+ module.exports.getMeta = () => Promise.resolve(_meta)
@@ -0,0 +1,29 @@
1
+ import { DtwoModule } from '@dtwo/schema';
2
+
3
+ interface ModuleOptions {
4
+ /**
5
+ * Crabs disables Kdux by default, set this option to `false` to avoid it and
6
+ * use Crabs alongside Kdux (Dtwo 2 only)
7
+ *
8
+ * @default `true`
9
+ */
10
+ disableKdux?: boolean;
11
+ /**
12
+ * Array of auto imports to be added to the dtwo.config.js file.
13
+ *
14
+ * @example
15
+ * ```js
16
+ * autoImports: [
17
+ * // automatically import `defineStore`
18
+ * 'defineStore',
19
+ * // automatically import `defineStore` as `defineCrabsStore`
20
+ * ['defineStore', 'defineCrabsStore',
21
+ * ]
22
+ * ```
23
+ *
24
+ */
25
+ autoImports?: Array<string | [string, string]>;
26
+ }
27
+ declare const module: DtwoModule<ModuleOptions>;
28
+
29
+ export { ModuleOptions, module as default };
@@ -0,0 +1,9 @@
1
+ {
2
+ "name": "crabs",
3
+ "configKey": "crabs",
4
+ "compatibility": {
5
+ "dtwo": "^2.0.0 || ^3.0.0-rc.5",
6
+ "bridge": true
7
+ },
8
+ "version": "0.4.9"
9
+ }
@@ -0,0 +1,49 @@
1
+ import { defineDtwoModule, createResolver, isDtwo2, resolveModule, addPlugin, addImports } from '@dtwo/kit';
2
+
3
+ const module = defineDtwoModule({
4
+ meta: {
5
+ name: "crabs",
6
+ configKey: "crabs",
7
+ compatibility: {
8
+ dtwo: "^2.0.0 || ^3.0.0-rc.5",
9
+ bridge: true
10
+ }
11
+ },
12
+ defaults: {
13
+ disableKdux: true,
14
+ autoImports: []
15
+ },
16
+ setup(options, dtwo) {
17
+ const resolver = createResolver(import.meta.url);
18
+ if (
19
+ // @ts-expect-error: no feature flag anymore or private?
20
+ dtwo.options.features && // ts
21
+ options.disableKdux && isDtwo2()
22
+ ) {
23
+ dtwo.options.features.store = false;
24
+ }
25
+ dtwo.options.build.transpile.push(resolver.resolve("./runtime"));
26
+ dtwo.options.alias.crabs = dtwo.options.alias.crabs || resolveModule("crabs/dist/crabs.mjs", {
27
+ paths: [dtwo.options.rootDir, import.meta.url]
28
+ });
29
+ dtwo.hook("prepare:types", ({ references }) => {
30
+ references.push({ types: "@crabs-dev/dtwo" });
31
+ });
32
+ dtwo.hook("modules:done", () => {
33
+ if (isDtwo2()) {
34
+ addPlugin(resolver.resolve("./runtime/plugin.kdu2"));
35
+ } else {
36
+ addPlugin(resolver.resolve("./runtime/plugin.kdu3"));
37
+ }
38
+ });
39
+ const composables = resolver.resolve("./runtime/composables");
40
+ addImports([
41
+ { from: composables, name: "useDtwo" },
42
+ ...options.autoImports.map(
43
+ (imports) => typeof imports === "string" ? { from: composables, name: imports } : { from: composables, name: imports[0], as: imports[1] }
44
+ )
45
+ ]);
46
+ }
47
+ });
48
+
49
+ export { module as default };
@@ -0,0 +1,2 @@
1
+ export * from 'crabs-dev';
2
+ export declare const useCrabs: () => any;
@@ -0,0 +1,3 @@
1
+ import { useDtwoApp } from "#app";
2
+ export * from "crabs-dev";
3
+ export const useCrabs = () => useDtwoApp().$crabs;
@@ -0,0 +1,13 @@
1
+ declare const _default: (context: any, inject: any) => void;
2
+ export default _default;
3
+ declare module 'crabs' {
4
+ interface CrabsCustomProperties {
5
+ /**
6
+ * Dtwo context. Requires you to install `@dtwo/types` to have types.
7
+ *
8
+ * @deprecated use `useDtwoApp()` and global `$fetch()` instead. See
9
+ * https://dtwojs-v3.web.app/bridge/bridge-composition-api/
10
+ */
11
+ $dtwo: import('@dtwo/types').Context;
12
+ }
13
+ }
@@ -0,0 +1,20 @@
1
+ import _Kdu2 from "kdu";
2
+ import { createCrabs, setActiveCrabs, CrabsKduPlugin } from "crabs-dev";
3
+ const Kdu = "default" in _Kdu2 ? _Kdu2.default : _Kdu2;
4
+ Kdu.use(CrabsKduPlugin);
5
+ export default (context, inject) => {
6
+ const crabs = createCrabs();
7
+ context.app.crabs = crabs;
8
+ setActiveCrabs(crabs);
9
+ crabs._p.push(({ store }) => {
10
+ Object.defineProperty(store, "$dtwo", { value: context });
11
+ });
12
+ if (process.server) {
13
+ context.beforeDtwoRender((ctx) => {
14
+ ctx.dtwoState.crabs = crabs.state.value;
15
+ });
16
+ } else if (context.dtwoState && context.dtwoState.crabs) {
17
+ crabs.state.value = context.dtwoState.crabs;
18
+ }
19
+ inject("crabs", crabs);
20
+ };
@@ -0,0 +1,6 @@
1
+ import type { Crabs } from 'crabs-dev';
2
+ import { Plugin } from '#app';
3
+ declare const plugin: Plugin<{
4
+ crabs: Crabs;
5
+ }>;
6
+ export default plugin;
@@ -0,0 +1,18 @@
1
+ import { createCrabs, setActiveCrabs } from "crabs-dev";
2
+ import { defineDtwoPlugin } from "#app";
3
+ const plugin = defineDtwoPlugin((dtwoApp) => {
4
+ const crabs = createCrabs();
5
+ dtwoApp.kduApp.use(crabs);
6
+ setActiveCrabs(crabs);
7
+ if (process.server) {
8
+ dtwoApp.payload.crabs = crabs.state.value;
9
+ } else if (dtwoApp.payload && dtwoApp.payload.crabs) {
10
+ crabs.state.value = dtwoApp.payload.crabs;
11
+ }
12
+ return {
13
+ provide: {
14
+ crabs
15
+ }
16
+ };
17
+ });
18
+ export default plugin;
@@ -0,0 +1,10 @@
1
+
2
+ import { ModuleOptions } from './module'
3
+
4
+ declare module '@dtwo/schema' {
5
+ interface DtwoConfig { ['crabs']?: Partial<ModuleOptions> }
6
+ interface DtwoOptions { ['crabs']?: ModuleOptions }
7
+ }
8
+
9
+
10
+ export { ModuleOptions, default } from './module'
package/package.json ADDED
@@ -0,0 +1,57 @@
1
+ {
2
+ "name": "@crabs-dev/dtwo",
3
+ "version": "0.4.9",
4
+ "description": "Dtwo Module for crabs",
5
+ "keywords": [
6
+ "crabs",
7
+ "dtwo",
8
+ "kdu",
9
+ "kdux",
10
+ "store"
11
+ ],
12
+ "homepage": "https://github.com/kdujs/crabs/tree/v2/packages/dtwo#readme",
13
+ "bugs": {
14
+ "url": "https://github.com/kdujs/crabs/issues"
15
+ },
16
+ "repository": {
17
+ "type": "git",
18
+ "url": "git+https://github.com/kdujs/crabs.git"
19
+ },
20
+ "license": "MIT",
21
+ "author": "NKDuy",
22
+ "sideEffects": false,
23
+ "type": "module",
24
+ "exports": {
25
+ ".": {
26
+ "types": "./dist/types.d.ts",
27
+ "import": "./dist/module.mjs",
28
+ "require": "./dist/module.cjs"
29
+ }
30
+ },
31
+ "main": "./dist/module.cjs",
32
+ "types": "./dist/types.d.ts",
33
+ "files": [
34
+ "dist"
35
+ ],
36
+ "dependencies": {
37
+ "@dtwo/kit": "3.1.0",
38
+ "crabs-dev": "2.0.35"
39
+ },
40
+ "devDependencies": {
41
+ "@dtwo/module-builder": "0.2.1",
42
+ "@dtwo/schema": "3.1.0",
43
+ "@types/node": "18.15.11",
44
+ "dtwo": "3.1.0",
45
+ "kdu-tsc": "1.2.0",
46
+ "typescript": "5.0.4"
47
+ },
48
+ "publishConfig": {
49
+ "access": "public"
50
+ },
51
+ "scripts": {
52
+ "build": "pnpm dev:prepare && dtwo-module-build",
53
+ "dev": "dtwc dev playground",
54
+ "dev:build": "dtwc build playground",
55
+ "dev:prepare": "dtwo-module-build --stub && dtwc prepare playground"
56
+ }
57
+ }