@blockle/blocks-react-slot 1.0.1 → 1.1.0

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.
@@ -1,6 +1,6 @@
1
1
  import { HTMLElementProps } from '@blockle/blocks-core';
2
2
  import { default as React } from 'react';
3
- import { Slot } from './Slot/Slot';
3
+ import { Slot } from './Slot/Slot.js';
4
4
  type TemplateProps = {
5
5
  asChild?: boolean;
6
6
  children?: React.ReactNode;
package/dist/index.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- export { createSlottable } from './createSlottable';
2
- export { Slot } from './Slot/Slot';
1
+ export { createSlottable } from './createSlottable.js';
2
+ export { Slot } from './Slot/Slot.js';
package/package.json CHANGED
@@ -1,25 +1,18 @@
1
1
  {
2
2
  "name": "@blockle/blocks-react-slot",
3
- "version": "1.0.1",
3
+ "version": "1.1.0",
4
4
  "description": "Slot",
5
5
  "type": "module",
6
6
  "exports": {
7
7
  ".": {
8
- "types": {
9
- "import": "./dist/index.d.mts",
10
- "require": "./dist/index.d.ts"
11
- },
12
- "import": "./dist/index.js",
13
- "require": "./dist/index.cjs"
8
+ "types": "./dist/index.d.ts",
9
+ "import": "./dist/index.js"
14
10
  }
15
11
  },
16
12
  "files": [
17
13
  "dist"
18
14
  ],
19
15
  "sideEffects": false,
20
- "main": "./dist/index.cjs",
21
- "module": "./dist/index.mjs",
22
- "types": "./dist/index.d.ts",
23
16
  "scripts": {
24
17
  "build": "vite build",
25
18
  "test": "vitest ",
@@ -38,7 +31,7 @@
38
31
  },
39
32
  "homepage": "https://github.com/Blockle/blocks#readme",
40
33
  "peerDependencies": {
41
- "react": ">=19.0.0",
42
- "@blockle/blocks-core": "^0.21.0"
34
+ "react": ">= 18 || >= 19",
35
+ "@blockle/blocks-core": ">= 0.x"
43
36
  }
44
37
  }
@@ -1,6 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
- const Slot = ({ children }) => {
4
- return children;
5
- };
6
- exports.Slot = Slot;
@@ -1,58 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
- const jsxRuntime = require("react/jsx-runtime");
4
- const blocksCore = require("@blockle/blocks-core");
5
- const react = require("react");
6
- const Slot = require("./Slot/Slot.cjs");
7
- function createSlottable(defaultElement) {
8
- const Tag = defaultElement;
9
- const Template = ({
10
- asChild,
11
- children,
12
- ref,
13
- ...rootProps
14
- }) => {
15
- if (!asChild) {
16
- const tagProps = { ref, ...rootProps };
17
- return /* @__PURE__ */ jsxRuntime.jsx(Tag, { ...tagProps, children });
18
- }
19
- const childrenArray = react.Children.toArray(children);
20
- const slotIndex = childrenArray.findIndex((child) => {
21
- if (!react.isValidElement(child)) {
22
- return false;
23
- }
24
- return child.type === Slot.Slot;
25
- });
26
- const slot = childrenArray[slotIndex];
27
- if (!slot) {
28
- return null;
29
- }
30
- if (!isValidElementWithChildren(slot)) {
31
- return null;
32
- }
33
- if (!react.isValidElement(slot.props.children)) {
34
- return null;
35
- }
36
- if (!isValidElementWithChildren(slot.props.children)) {
37
- return null;
38
- }
39
- const nextChildren = [...childrenArray];
40
- if (nextChildren.length === 1 && !slot.props.children.props.children) {
41
- return react.cloneElement(
42
- slot.props.children,
43
- blocksCore.mergeProps(rootProps, slot.props.children.props)
44
- );
45
- }
46
- nextChildren[slotIndex] = slot.props.children.props.children;
47
- return react.cloneElement(
48
- slot.props.children,
49
- blocksCore.mergeProps(rootProps, slot.props.children.props),
50
- nextChildren
51
- );
52
- };
53
- return [Template, Slot.Slot];
54
- }
55
- function isValidElementWithChildren(child) {
56
- return react.isValidElement(child) && !!child.props;
57
- }
58
- exports.createSlottable = createSlottable;
package/dist/index.cjs DELETED
@@ -1,6 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
- const createSlottable = require("./createSlottable.cjs");
4
- const Slot = require("./Slot/Slot.cjs");
5
- exports.createSlottable = createSlottable.createSlottable;
6
- exports.Slot = Slot.Slot;