@tamagui/text 1.0.1-beta.92 → 1.0.1-beta.95

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.
Files changed (57) hide show
  1. package/dist/cjs/Headings.js +0 -0
  2. package/dist/cjs/Headings.js.map +0 -0
  3. package/dist/cjs/Paragraph.js +0 -0
  4. package/dist/cjs/Paragraph.js.map +0 -0
  5. package/dist/cjs/SizableText.js +1 -1
  6. package/dist/cjs/SizableText.js.map +2 -2
  7. package/dist/cjs/Texts.js +0 -0
  8. package/dist/cjs/Texts.js.map +0 -0
  9. package/dist/cjs/index.js +1 -0
  10. package/dist/cjs/index.js.map +2 -2
  11. package/dist/cjs/wrapChildrenInText.js +108 -0
  12. package/dist/cjs/wrapChildrenInText.js.map +7 -0
  13. package/dist/cjs/wrapChildrenInText.test.js +31 -0
  14. package/dist/cjs/wrapChildrenInText.test.js.map +7 -0
  15. package/dist/esm/Headings.js +0 -0
  16. package/dist/esm/Headings.js.map +0 -0
  17. package/dist/esm/Paragraph.js +0 -0
  18. package/dist/esm/Paragraph.js.map +0 -0
  19. package/dist/esm/SizableText.js +2 -2
  20. package/dist/esm/SizableText.js.map +1 -1
  21. package/dist/esm/Texts.js +0 -0
  22. package/dist/esm/Texts.js.map +0 -0
  23. package/dist/esm/index.js +1 -0
  24. package/dist/esm/index.js.map +2 -2
  25. package/dist/esm/wrapChildrenInText.js +84 -0
  26. package/dist/esm/wrapChildrenInText.js.map +7 -0
  27. package/dist/esm/wrapChildrenInText.test.js +31 -0
  28. package/dist/esm/wrapChildrenInText.test.js.map +7 -0
  29. package/dist/jsx/Headings.js +0 -0
  30. package/dist/jsx/Headings.js.map +0 -0
  31. package/dist/jsx/Paragraph.js +0 -0
  32. package/dist/jsx/Paragraph.js.map +0 -0
  33. package/dist/jsx/SizableText.js +2 -2
  34. package/dist/jsx/SizableText.js.map +1 -1
  35. package/dist/jsx/Texts.js +0 -0
  36. package/dist/jsx/Texts.js.map +0 -0
  37. package/dist/jsx/index.js +1 -0
  38. package/dist/jsx/index.js.map +2 -2
  39. package/dist/jsx/wrapChildrenInText.js +61 -0
  40. package/dist/jsx/wrapChildrenInText.js.map +7 -0
  41. package/dist/jsx/wrapChildrenInText.test.js +29 -0
  42. package/dist/jsx/wrapChildrenInText.test.js.map +7 -0
  43. package/package.json +10 -5
  44. package/src/SizableText.tsx +2 -2
  45. package/src/index.tsx +1 -0
  46. package/src/wrapChildrenInText.test.tsx +39 -0
  47. package/src/wrapChildrenInText.tsx +88 -0
  48. package/types/Headings.d.ts.map +0 -0
  49. package/types/Paragraph.d.ts.map +0 -0
  50. package/types/SizableText.d.ts.map +1 -1
  51. package/types/index.d.ts +1 -0
  52. package/types/index.d.ts.map +1 -1
  53. package/types/wrapChildrenInText.d.ts +20 -0
  54. package/types/wrapChildrenInText.d.ts.map +1 -0
  55. package/types/wrapChildrenInText.test.d.ts +2 -0
  56. package/types/wrapChildrenInText.test.d.ts.map +1 -0
  57. package/types/Texts.d.ts.map +0 -1
File without changes
File without changes
File without changes
File without changes
@@ -25,7 +25,7 @@ const SizableText = (0, import_core.styled)(import_core.Text, {
25
25
  name: "SizableText",
26
26
  fontFamily: "$body",
27
27
  variants: {
28
- size: import_core.getTextSize
28
+ size: import_core.getFont
29
29
  },
30
30
  defaultVariants: {
31
31
  size: "$4"
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/SizableText.tsx"],
4
- "sourcesContent": ["import { GetProps, Text, getTextSize, styled } from '@tamagui/core'\n\nexport const SizableText = styled(\n Text,\n {\n name: 'SizableText',\n fontFamily: '$body',\n\n variants: {\n size: getTextSize,\n },\n\n defaultVariants: {\n size: '$4',\n },\n },\n {\n inlineWhenUnflattened: new Set(['fontFamily']),\n }\n)\n\nexport type SizableTextProps = GetProps<typeof SizableText>\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,kBAAoD;AAE7C,MAAM,cAAc,wBACzB,kBACA;AAAA,EACE,MAAM;AAAA,EACN,YAAY;AAAA,EAEZ,UAAU;AAAA,IACR,MAAM;AAAA,EACR;AAAA,EAEA,iBAAiB;AAAA,IACf,MAAM;AAAA,EACR;AACF,GACA;AAAA,EACE,uBAAuB,oBAAI,IAAI,CAAC,YAAY,CAAC;AAC/C,CACF;",
4
+ "sourcesContent": ["import { GetProps, Text, getFont, styled } from '@tamagui/core'\n\nexport const SizableText = styled(\n Text,\n {\n name: 'SizableText',\n fontFamily: '$body',\n\n variants: {\n size: getFont,\n },\n\n defaultVariants: {\n size: '$4',\n },\n },\n {\n inlineWhenUnflattened: new Set(['fontFamily']),\n }\n)\n\nexport type SizableTextProps = GetProps<typeof SizableText>\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,kBAAgD;AAEzC,MAAM,cAAc,wBACzB,kBACA;AAAA,EACE,MAAM;AAAA,EACN,YAAY;AAAA,EAEZ,UAAU;AAAA,IACR,MAAM;AAAA,EACR;AAAA,EAEA,iBAAiB;AAAA,IACf,MAAM;AAAA,EACR;AACF,GACA;AAAA,EACE,uBAAuB,oBAAI,IAAI,CAAC,YAAY,CAAC;AAC/C,CACF;",
6
6
  "names": []
7
7
  }
package/dist/cjs/Texts.js CHANGED
File without changes
File without changes
package/dist/cjs/index.js CHANGED
@@ -17,4 +17,5 @@ module.exports = __toCommonJS(src_exports);
17
17
  __reExport(src_exports, require("./SizableText"), module.exports);
18
18
  __reExport(src_exports, require("./Paragraph"), module.exports);
19
19
  __reExport(src_exports, require("./Headings"), module.exports);
20
+ __reExport(src_exports, require("./wrapChildrenInText"), module.exports);
20
21
  //# sourceMappingURL=index.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/index.tsx"],
4
- "sourcesContent": ["export * from './SizableText'\nexport * from './Paragraph'\nexport * from './Headings'\n"],
5
- "mappings": ";;;;;;;;;;;;;;AAAA;AAAA;AAAA,wBAAc,0BAAd;AACA,wBAAc,wBADd;AAEA,wBAAc,uBAFd;",
4
+ "sourcesContent": ["export * from './SizableText'\nexport * from './Paragraph'\nexport * from './Headings'\nexport * from './wrapChildrenInText'\n"],
5
+ "mappings": ";;;;;;;;;;;;;;AAAA;AAAA;AAAA,wBAAc,0BAAd;AACA,wBAAc,wBADd;AAEA,wBAAc,uBAFd;AAGA,wBAAc,iCAHd;",
6
6
  "names": []
7
7
  }
@@ -0,0 +1,108 @@
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __defProps = Object.defineProperties;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
6
+ var __getOwnPropNames = Object.getOwnPropertyNames;
7
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
8
+ var __getProtoOf = Object.getPrototypeOf;
9
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
10
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
11
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
12
+ var __spreadValues = (a, b) => {
13
+ for (var prop in b || (b = {}))
14
+ if (__hasOwnProp.call(b, prop))
15
+ __defNormalProp(a, prop, b[prop]);
16
+ if (__getOwnPropSymbols)
17
+ for (var prop of __getOwnPropSymbols(b)) {
18
+ if (__propIsEnum.call(b, prop))
19
+ __defNormalProp(a, prop, b[prop]);
20
+ }
21
+ return a;
22
+ };
23
+ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
24
+ var __export = (target, all) => {
25
+ for (var name in all)
26
+ __defProp(target, name, { get: all[name], enumerable: true });
27
+ };
28
+ var __copyProps = (to, from, except, desc) => {
29
+ if (from && typeof from === "object" || typeof from === "function") {
30
+ for (let key of __getOwnPropNames(from))
31
+ if (!__hasOwnProp.call(to, key) && key !== except)
32
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
33
+ }
34
+ return to;
35
+ };
36
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, mod));
37
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
38
+ var wrapChildrenInText_exports = {};
39
+ __export(wrapChildrenInText_exports, {
40
+ wrapChildrenInText: () => wrapChildrenInText
41
+ });
42
+ module.exports = __toCommonJS(wrapChildrenInText_exports);
43
+ var import_react = __toESM(require("react"));
44
+ function wrapChildrenInText(TextComponent, {
45
+ children,
46
+ textProps,
47
+ size,
48
+ noTextWrap,
49
+ color,
50
+ fontFamily,
51
+ fontSize,
52
+ fontWeight,
53
+ letterSpacing,
54
+ textAlign
55
+ }) {
56
+ if (noTextWrap || !children) {
57
+ return children;
58
+ }
59
+ let allChildren = import_react.default.Children.toArray(children);
60
+ let nextChildren = [];
61
+ let lastIsString = false;
62
+ const directTextProps = {};
63
+ if (color)
64
+ directTextProps.color = color;
65
+ if (fontFamily)
66
+ directTextProps.fontFamily = fontFamily;
67
+ if (fontSize)
68
+ directTextProps.fontSize = fontSize;
69
+ if (fontWeight)
70
+ directTextProps.fontWeight = fontWeight;
71
+ if (letterSpacing)
72
+ directTextProps.letterSpacing = letterSpacing;
73
+ if (textAlign)
74
+ directTextProps.textAlign = textAlign;
75
+ function concatStringChildren() {
76
+ if (!lastIsString)
77
+ return;
78
+ const index = nextChildren.length - 1;
79
+ const childrenStrings = nextChildren[index];
80
+ nextChildren[index] = /* @__PURE__ */ import_react.default.createElement(TextComponent, __spreadValues(__spreadProps(__spreadValues({
81
+ key: index
82
+ }, directTextProps), {
83
+ size
84
+ }), textProps), childrenStrings);
85
+ }
86
+ for (const child of allChildren) {
87
+ const last = nextChildren[nextChildren.length - 1];
88
+ const isString = typeof child === "string";
89
+ if (isString) {
90
+ if (lastIsString) {
91
+ last.push(child);
92
+ } else {
93
+ nextChildren.push([child]);
94
+ }
95
+ } else {
96
+ concatStringChildren();
97
+ nextChildren.push(child);
98
+ }
99
+ lastIsString = isString;
100
+ }
101
+ concatStringChildren();
102
+ return nextChildren;
103
+ }
104
+ // Annotate the CommonJS export names for ESM import in node:
105
+ 0 && (module.exports = {
106
+ wrapChildrenInText
107
+ });
108
+ //# sourceMappingURL=wrapChildrenInText.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/wrapChildrenInText.tsx"],
4
+ "sourcesContent": ["import type { SizeTokens } from '@tamagui/core'\nimport React from 'react'\n\nimport { SizableTextProps } from './SizableText'\n\nexport type TextParentStyles = {\n color?: SizableTextProps['color']\n fontWeight?: SizableTextProps['fontWeight']\n fontSize?: SizableTextProps['fontSize']\n fontFamily?: SizableTextProps['fontFamily']\n letterSpacing?: SizableTextProps['letterSpacing']\n textAlign?: SizableTextProps['textAlign']\n // all the other text controls\n textProps?: Partial<SizableTextProps>\n noTextWrap?: boolean\n}\n\ntype Props = TextParentStyles & {\n children?: React.ReactNode\n size?: SizeTokens\n}\n\nexport function wrapChildrenInText(\n TextComponent: any,\n {\n children,\n textProps,\n size,\n noTextWrap,\n color,\n fontFamily,\n fontSize,\n fontWeight,\n letterSpacing,\n textAlign,\n }: Props\n) {\n if (noTextWrap || !children) {\n return children\n }\n\n // in the case of using variables, like so:\n // <ListItem>Hello, {name}</ListItem>\n // it gives us props.children as ['Hello, ', 'name']\n // but we don't want to wrap multiple SizableText around each part\n // so we group them\n let allChildren = React.Children.toArray(children)\n let nextChildren: any[] = []\n let lastIsString = false\n const directTextProps: any = {}\n // to avoid setting undefined\n if (color) directTextProps.color = color\n if (fontFamily) directTextProps.fontFamily = fontFamily\n if (fontSize) directTextProps.fontSize = fontSize\n if (fontWeight) directTextProps.fontWeight = fontWeight\n if (letterSpacing) directTextProps.letterSpacing = letterSpacing\n if (textAlign) directTextProps.textAlign = textAlign\n\n function concatStringChildren() {\n if (!lastIsString) return\n const index = nextChildren.length - 1\n const childrenStrings = nextChildren[index]\n nextChildren[index] = (\n <TextComponent key={index} {...directTextProps} size={size} {...textProps}>\n {childrenStrings}\n </TextComponent>\n )\n }\n\n for (const child of allChildren) {\n const last = nextChildren[nextChildren.length - 1]\n const isString = typeof child === 'string'\n if (isString) {\n if (lastIsString) {\n last.push(child)\n } else {\n nextChildren.push([child])\n }\n } else {\n concatStringChildren()\n nextChildren.push(child)\n }\n lastIsString = isString\n }\n concatStringChildren()\n\n return nextChildren\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,mBAAkB;AAqBX,4BACL,eACA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,GAEF;AACA,MAAI,cAAc,CAAC,UAAU;AAC3B,WAAO;AAAA,EACT;AAOA,MAAI,cAAc,qBAAM,SAAS,QAAQ,QAAQ;AACjD,MAAI,eAAsB,CAAC;AAC3B,MAAI,eAAe;AACnB,QAAM,kBAAuB,CAAC;AAE9B,MAAI;AAAO,oBAAgB,QAAQ;AACnC,MAAI;AAAY,oBAAgB,aAAa;AAC7C,MAAI;AAAU,oBAAgB,WAAW;AACzC,MAAI;AAAY,oBAAgB,aAAa;AAC7C,MAAI;AAAe,oBAAgB,gBAAgB;AACnD,MAAI;AAAW,oBAAgB,YAAY;AAE3C,kCAAgC;AAC9B,QAAI,CAAC;AAAc;AACnB,UAAM,QAAQ,aAAa,SAAS;AACpC,UAAM,kBAAkB,aAAa;AACrC,iBAAa,SACX,mDAAC;AAAA,MAAc,KAAK;AAAA,OAAW,kBAA9B;AAAA,MAA+C;AAAA,QAAgB,YAC7D,eACH;AAAA,EAEJ;AAEA,aAAW,SAAS,aAAa;AAC/B,UAAM,OAAO,aAAa,aAAa,SAAS;AAChD,UAAM,WAAW,OAAO,UAAU;AAClC,QAAI,UAAU;AACZ,UAAI,cAAc;AAChB,aAAK,KAAK,KAAK;AAAA,MACjB,OAAO;AACL,qBAAa,KAAK,CAAC,KAAK,CAAC;AAAA,MAC3B;AAAA,IACF,OAAO;AACL,2BAAqB;AACrB,mBAAa,KAAK,KAAK;AAAA,IACzB;AACA,mBAAe;AAAA,EACjB;AACA,uBAAqB;AAErB,SAAO;AACT;",
6
+ "names": []
7
+ }
@@ -0,0 +1,31 @@
1
+ var import_vitest = require("vitest");
2
+ var import_wrapChildrenInText = require("./wrapChildrenInText");
3
+ const Comp = () => {
4
+ };
5
+ const re = /* @__PURE__ */ React.createElement("div", {
6
+ "data-id": Math.random()
7
+ });
8
+ const reID = re.props["data-id"];
9
+ (0, import_vitest.test)("should wrap all string children, not wrap others", () => {
10
+ const out = (0, import_wrapChildrenInText.wrapChildrenInText)(Comp, {
11
+ children: [re, "a", "b", re, "c", re, "d"]
12
+ });
13
+ (0, import_vitest.expect)(out[0].props["data-id"]).toBe(reID);
14
+ (0, import_vitest.expect)(out[1].type).toBe(Comp);
15
+ (0, import_vitest.expect)(out[1].props.children).toStrictEqual(["a", "b"]);
16
+ (0, import_vitest.expect)(out[2].props["data-id"]).toBe(reID);
17
+ (0, import_vitest.expect)(out[3].type).toBe(Comp);
18
+ (0, import_vitest.expect)(out[3].props.children).toStrictEqual(["c"]);
19
+ (0, import_vitest.expect)(out[4].props["data-id"]).toBe(reID);
20
+ (0, import_vitest.expect)(out[5].type).toBe(Comp);
21
+ (0, import_vitest.expect)(out[5].props.children).toStrictEqual(["d"]);
22
+ });
23
+ (0, import_vitest.test)("should first child string", () => {
24
+ const out = (0, import_wrapChildrenInText.wrapChildrenInText)(Comp, {
25
+ children: ["a", re]
26
+ });
27
+ (0, import_vitest.expect)(out[0].type).toBe(Comp);
28
+ (0, import_vitest.expect)(out[0].props.children).toStrictEqual(["a"]);
29
+ (0, import_vitest.expect)(out[1].props["data-id"]).toBe(reID);
30
+ });
31
+ //# sourceMappingURL=wrapChildrenInText.test.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/wrapChildrenInText.test.tsx"],
4
+ "sourcesContent": ["import { expect, test } from 'vitest'\n\nimport { wrapChildrenInText } from './wrapChildrenInText'\n\nconst Comp = () => {}\nconst re = <div data-id={Math.random()} />\nconst reID = re.props['data-id']\n\ntest('should wrap all string children, not wrap others', () => {\n const out = wrapChildrenInText(Comp, {\n children: [re, 'a', 'b', re, 'c', re, 'd'],\n }) as any\n\n expect(out[0].props['data-id']).toBe(reID)\n\n expect(out[1].type).toBe(Comp)\n expect(out[1].props.children).toStrictEqual(['a', 'b'])\n\n expect(out[2].props['data-id']).toBe(reID)\n\n expect(out[3].type).toBe(Comp)\n expect(out[3].props.children).toStrictEqual(['c'])\n\n expect(out[4].props['data-id']).toBe(reID)\n\n expect(out[5].type).toBe(Comp)\n expect(out[5].props.children).toStrictEqual(['d'])\n})\n\ntest('should first child string', () => {\n const out = wrapChildrenInText(Comp, {\n children: ['a', re],\n }) as any\n\n expect(out[0].type).toBe(Comp)\n expect(out[0].props.children).toStrictEqual(['a'])\n\n expect(out[1].props['data-id']).toBe(reID)\n})\n"],
5
+ "mappings": "AAAA,oBAA6B;AAE7B,gCAAmC;AAEnC,MAAM,OAAO,MAAM;AAAC;AACpB,MAAM,KAAK,oCAAC;AAAA,EAAI,WAAS,KAAK,OAAO;AAAA,CAAG;AACxC,MAAM,OAAO,GAAG,MAAM;AAEtB,wBAAK,oDAAoD,MAAM;AAC7D,QAAM,MAAM,kDAAmB,MAAM;AAAA,IACnC,UAAU,CAAC,IAAI,KAAK,KAAK,IAAI,KAAK,IAAI,GAAG;AAAA,EAC3C,CAAC;AAED,4BAAO,IAAI,GAAG,MAAM,UAAU,EAAE,KAAK,IAAI;AAEzC,4BAAO,IAAI,GAAG,IAAI,EAAE,KAAK,IAAI;AAC7B,4BAAO,IAAI,GAAG,MAAM,QAAQ,EAAE,cAAc,CAAC,KAAK,GAAG,CAAC;AAEtD,4BAAO,IAAI,GAAG,MAAM,UAAU,EAAE,KAAK,IAAI;AAEzC,4BAAO,IAAI,GAAG,IAAI,EAAE,KAAK,IAAI;AAC7B,4BAAO,IAAI,GAAG,MAAM,QAAQ,EAAE,cAAc,CAAC,GAAG,CAAC;AAEjD,4BAAO,IAAI,GAAG,MAAM,UAAU,EAAE,KAAK,IAAI;AAEzC,4BAAO,IAAI,GAAG,IAAI,EAAE,KAAK,IAAI;AAC7B,4BAAO,IAAI,GAAG,MAAM,QAAQ,EAAE,cAAc,CAAC,GAAG,CAAC;AACnD,CAAC;AAED,wBAAK,6BAA6B,MAAM;AACtC,QAAM,MAAM,kDAAmB,MAAM;AAAA,IACnC,UAAU,CAAC,KAAK,EAAE;AAAA,EACpB,CAAC;AAED,4BAAO,IAAI,GAAG,IAAI,EAAE,KAAK,IAAI;AAC7B,4BAAO,IAAI,GAAG,MAAM,QAAQ,EAAE,cAAc,CAAC,GAAG,CAAC;AAEjD,4BAAO,IAAI,GAAG,MAAM,UAAU,EAAE,KAAK,IAAI;AAC3C,CAAC;",
6
+ "names": []
7
+ }
File without changes
File without changes
File without changes
File without changes
@@ -1,9 +1,9 @@
1
- import { Text, getTextSize, styled } from "@tamagui/core";
1
+ import { Text, getFont, styled } from "@tamagui/core";
2
2
  const SizableText = styled(Text, {
3
3
  name: "SizableText",
4
4
  fontFamily: "$body",
5
5
  variants: {
6
- size: getTextSize
6
+ size: getFont
7
7
  },
8
8
  defaultVariants: {
9
9
  size: "$4"
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/SizableText.tsx"],
4
- "sourcesContent": ["import { GetProps, Text, getTextSize, styled } from '@tamagui/core'\n\nexport const SizableText = styled(\n Text,\n {\n name: 'SizableText',\n fontFamily: '$body',\n\n variants: {\n size: getTextSize,\n },\n\n defaultVariants: {\n size: '$4',\n },\n },\n {\n inlineWhenUnflattened: new Set(['fontFamily']),\n }\n)\n\nexport type SizableTextProps = GetProps<typeof SizableText>\n"],
4
+ "sourcesContent": ["import { GetProps, Text, getFont, styled } from '@tamagui/core'\n\nexport const SizableText = styled(\n Text,\n {\n name: 'SizableText',\n fontFamily: '$body',\n\n variants: {\n size: getFont,\n },\n\n defaultVariants: {\n size: '$4',\n },\n },\n {\n inlineWhenUnflattened: new Set(['fontFamily']),\n }\n)\n\nexport type SizableTextProps = GetProps<typeof SizableText>\n"],
5
5
  "mappings": "AAAA;AAEO,MAAM,cAAc,OACzB,MACA;AAAA,EACE,MAAM;AAAA,EACN,YAAY;AAAA,EAEZ,UAAU;AAAA,IACR,MAAM;AAAA,EACR;AAAA,EAEA,iBAAiB;AAAA,IACf,MAAM;AAAA,EACR;AACF,GACA;AAAA,EACE,uBAAuB,oBAAI,IAAI,CAAC,YAAY,CAAC;AAC/C,CACF;",
6
6
  "names": []
7
7
  }
package/dist/esm/Texts.js CHANGED
File without changes
File without changes
package/dist/esm/index.js CHANGED
@@ -1,4 +1,5 @@
1
1
  export * from "./SizableText";
2
2
  export * from "./Paragraph";
3
3
  export * from "./Headings";
4
+ export * from "./wrapChildrenInText";
4
5
  //# sourceMappingURL=index.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/index.tsx"],
4
- "sourcesContent": ["export * from './SizableText'\nexport * from './Paragraph'\nexport * from './Headings'\n"],
5
- "mappings": "AAAA;AACA;AACA;",
4
+ "sourcesContent": ["export * from './SizableText'\nexport * from './Paragraph'\nexport * from './Headings'\nexport * from './wrapChildrenInText'\n"],
5
+ "mappings": "AAAA;AACA;AACA;AACA;",
6
6
  "names": []
7
7
  }
@@ -0,0 +1,84 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __defProps = Object.defineProperties;
3
+ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
4
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
7
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
8
+ var __spreadValues = (a, b) => {
9
+ for (var prop in b || (b = {}))
10
+ if (__hasOwnProp.call(b, prop))
11
+ __defNormalProp(a, prop, b[prop]);
12
+ if (__getOwnPropSymbols)
13
+ for (var prop of __getOwnPropSymbols(b)) {
14
+ if (__propIsEnum.call(b, prop))
15
+ __defNormalProp(a, prop, b[prop]);
16
+ }
17
+ return a;
18
+ };
19
+ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
20
+ import React from "react";
21
+ function wrapChildrenInText(TextComponent, {
22
+ children,
23
+ textProps,
24
+ size,
25
+ noTextWrap,
26
+ color,
27
+ fontFamily,
28
+ fontSize,
29
+ fontWeight,
30
+ letterSpacing,
31
+ textAlign
32
+ }) {
33
+ if (noTextWrap || !children) {
34
+ return children;
35
+ }
36
+ let allChildren = React.Children.toArray(children);
37
+ let nextChildren = [];
38
+ let lastIsString = false;
39
+ const directTextProps = {};
40
+ if (color)
41
+ directTextProps.color = color;
42
+ if (fontFamily)
43
+ directTextProps.fontFamily = fontFamily;
44
+ if (fontSize)
45
+ directTextProps.fontSize = fontSize;
46
+ if (fontWeight)
47
+ directTextProps.fontWeight = fontWeight;
48
+ if (letterSpacing)
49
+ directTextProps.letterSpacing = letterSpacing;
50
+ if (textAlign)
51
+ directTextProps.textAlign = textAlign;
52
+ function concatStringChildren() {
53
+ if (!lastIsString)
54
+ return;
55
+ const index = nextChildren.length - 1;
56
+ const childrenStrings = nextChildren[index];
57
+ nextChildren[index] = /* @__PURE__ */ React.createElement(TextComponent, __spreadValues(__spreadProps(__spreadValues({
58
+ key: index
59
+ }, directTextProps), {
60
+ size
61
+ }), textProps), childrenStrings);
62
+ }
63
+ for (const child of allChildren) {
64
+ const last = nextChildren[nextChildren.length - 1];
65
+ const isString = typeof child === "string";
66
+ if (isString) {
67
+ if (lastIsString) {
68
+ last.push(child);
69
+ } else {
70
+ nextChildren.push([child]);
71
+ }
72
+ } else {
73
+ concatStringChildren();
74
+ nextChildren.push(child);
75
+ }
76
+ lastIsString = isString;
77
+ }
78
+ concatStringChildren();
79
+ return nextChildren;
80
+ }
81
+ export {
82
+ wrapChildrenInText
83
+ };
84
+ //# sourceMappingURL=wrapChildrenInText.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/wrapChildrenInText.tsx"],
4
+ "sourcesContent": ["import type { SizeTokens } from '@tamagui/core'\nimport React from 'react'\n\nimport { SizableTextProps } from './SizableText'\n\nexport type TextParentStyles = {\n color?: SizableTextProps['color']\n fontWeight?: SizableTextProps['fontWeight']\n fontSize?: SizableTextProps['fontSize']\n fontFamily?: SizableTextProps['fontFamily']\n letterSpacing?: SizableTextProps['letterSpacing']\n textAlign?: SizableTextProps['textAlign']\n // all the other text controls\n textProps?: Partial<SizableTextProps>\n noTextWrap?: boolean\n}\n\ntype Props = TextParentStyles & {\n children?: React.ReactNode\n size?: SizeTokens\n}\n\nexport function wrapChildrenInText(\n TextComponent: any,\n {\n children,\n textProps,\n size,\n noTextWrap,\n color,\n fontFamily,\n fontSize,\n fontWeight,\n letterSpacing,\n textAlign,\n }: Props\n) {\n if (noTextWrap || !children) {\n return children\n }\n\n // in the case of using variables, like so:\n // <ListItem>Hello, {name}</ListItem>\n // it gives us props.children as ['Hello, ', 'name']\n // but we don't want to wrap multiple SizableText around each part\n // so we group them\n let allChildren = React.Children.toArray(children)\n let nextChildren: any[] = []\n let lastIsString = false\n const directTextProps: any = {}\n // to avoid setting undefined\n if (color) directTextProps.color = color\n if (fontFamily) directTextProps.fontFamily = fontFamily\n if (fontSize) directTextProps.fontSize = fontSize\n if (fontWeight) directTextProps.fontWeight = fontWeight\n if (letterSpacing) directTextProps.letterSpacing = letterSpacing\n if (textAlign) directTextProps.textAlign = textAlign\n\n function concatStringChildren() {\n if (!lastIsString) return\n const index = nextChildren.length - 1\n const childrenStrings = nextChildren[index]\n nextChildren[index] = (\n <TextComponent key={index} {...directTextProps} size={size} {...textProps}>\n {childrenStrings}\n </TextComponent>\n )\n }\n\n for (const child of allChildren) {\n const last = nextChildren[nextChildren.length - 1]\n const isString = typeof child === 'string'\n if (isString) {\n if (lastIsString) {\n last.push(child)\n } else {\n nextChildren.push([child])\n }\n } else {\n concatStringChildren()\n nextChildren.push(child)\n }\n lastIsString = isString\n }\n concatStringChildren()\n\n return nextChildren\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;AACA;AAqBO,4BACL,eACA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,GAEF;AACA,MAAI,cAAc,CAAC,UAAU;AAC3B,WAAO;AAAA,EACT;AAOA,MAAI,cAAc,MAAM,SAAS,QAAQ,QAAQ;AACjD,MAAI,eAAsB,CAAC;AAC3B,MAAI,eAAe;AACnB,QAAM,kBAAuB,CAAC;AAE9B,MAAI;AAAO,oBAAgB,QAAQ;AACnC,MAAI;AAAY,oBAAgB,aAAa;AAC7C,MAAI;AAAU,oBAAgB,WAAW;AACzC,MAAI;AAAY,oBAAgB,aAAa;AAC7C,MAAI;AAAe,oBAAgB,gBAAgB;AACnD,MAAI;AAAW,oBAAgB,YAAY;AAE3C,kCAAgC;AAC9B,QAAI,CAAC;AAAc;AACnB,UAAM,QAAQ,aAAa,SAAS;AACpC,UAAM,kBAAkB,aAAa;AACrC,iBAAa,SACX,oCAAC;AAAA,MAAc,KAAK;AAAA,OAAW,kBAA9B;AAAA,MAA+C;AAAA,QAAgB,YAC7D,eACH;AAAA,EAEJ;AAEA,aAAW,SAAS,aAAa;AAC/B,UAAM,OAAO,aAAa,aAAa,SAAS;AAChD,UAAM,WAAW,OAAO,UAAU;AAClC,QAAI,UAAU;AACZ,UAAI,cAAc;AAChB,aAAK,KAAK,KAAK;AAAA,MACjB,OAAO;AACL,qBAAa,KAAK,CAAC,KAAK,CAAC;AAAA,MAC3B;AAAA,IACF,OAAO;AACL,2BAAqB;AACrB,mBAAa,KAAK,KAAK;AAAA,IACzB;AACA,mBAAe;AAAA,EACjB;AACA,uBAAqB;AAErB,SAAO;AACT;",
6
+ "names": []
7
+ }
@@ -0,0 +1,31 @@
1
+ import { expect, test } from "vitest";
2
+ import { wrapChildrenInText } from "./wrapChildrenInText";
3
+ const Comp = () => {
4
+ };
5
+ const re = /* @__PURE__ */ React.createElement("div", {
6
+ "data-id": Math.random()
7
+ });
8
+ const reID = re.props["data-id"];
9
+ test("should wrap all string children, not wrap others", () => {
10
+ const out = wrapChildrenInText(Comp, {
11
+ children: [re, "a", "b", re, "c", re, "d"]
12
+ });
13
+ expect(out[0].props["data-id"]).toBe(reID);
14
+ expect(out[1].type).toBe(Comp);
15
+ expect(out[1].props.children).toStrictEqual(["a", "b"]);
16
+ expect(out[2].props["data-id"]).toBe(reID);
17
+ expect(out[3].type).toBe(Comp);
18
+ expect(out[3].props.children).toStrictEqual(["c"]);
19
+ expect(out[4].props["data-id"]).toBe(reID);
20
+ expect(out[5].type).toBe(Comp);
21
+ expect(out[5].props.children).toStrictEqual(["d"]);
22
+ });
23
+ test("should first child string", () => {
24
+ const out = wrapChildrenInText(Comp, {
25
+ children: ["a", re]
26
+ });
27
+ expect(out[0].type).toBe(Comp);
28
+ expect(out[0].props.children).toStrictEqual(["a"]);
29
+ expect(out[1].props["data-id"]).toBe(reID);
30
+ });
31
+ //# sourceMappingURL=wrapChildrenInText.test.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/wrapChildrenInText.test.tsx"],
4
+ "sourcesContent": ["import { expect, test } from 'vitest'\n\nimport { wrapChildrenInText } from './wrapChildrenInText'\n\nconst Comp = () => {}\nconst re = <div data-id={Math.random()} />\nconst reID = re.props['data-id']\n\ntest('should wrap all string children, not wrap others', () => {\n const out = wrapChildrenInText(Comp, {\n children: [re, 'a', 'b', re, 'c', re, 'd'],\n }) as any\n\n expect(out[0].props['data-id']).toBe(reID)\n\n expect(out[1].type).toBe(Comp)\n expect(out[1].props.children).toStrictEqual(['a', 'b'])\n\n expect(out[2].props['data-id']).toBe(reID)\n\n expect(out[3].type).toBe(Comp)\n expect(out[3].props.children).toStrictEqual(['c'])\n\n expect(out[4].props['data-id']).toBe(reID)\n\n expect(out[5].type).toBe(Comp)\n expect(out[5].props.children).toStrictEqual(['d'])\n})\n\ntest('should first child string', () => {\n const out = wrapChildrenInText(Comp, {\n children: ['a', re],\n }) as any\n\n expect(out[0].type).toBe(Comp)\n expect(out[0].props.children).toStrictEqual(['a'])\n\n expect(out[1].props['data-id']).toBe(reID)\n})\n"],
5
+ "mappings": "AAAA;AAEA;AAEA,MAAM,OAAO,MAAM;AAAC;AACpB,MAAM,KAAK,oCAAC;AAAA,EAAI,WAAS,KAAK,OAAO;AAAA,CAAG;AACxC,MAAM,OAAO,GAAG,MAAM;AAEtB,KAAK,oDAAoD,MAAM;AAC7D,QAAM,MAAM,mBAAmB,MAAM;AAAA,IACnC,UAAU,CAAC,IAAI,KAAK,KAAK,IAAI,KAAK,IAAI,GAAG;AAAA,EAC3C,CAAC;AAED,SAAO,IAAI,GAAG,MAAM,UAAU,EAAE,KAAK,IAAI;AAEzC,SAAO,IAAI,GAAG,IAAI,EAAE,KAAK,IAAI;AAC7B,SAAO,IAAI,GAAG,MAAM,QAAQ,EAAE,cAAc,CAAC,KAAK,GAAG,CAAC;AAEtD,SAAO,IAAI,GAAG,MAAM,UAAU,EAAE,KAAK,IAAI;AAEzC,SAAO,IAAI,GAAG,IAAI,EAAE,KAAK,IAAI;AAC7B,SAAO,IAAI,GAAG,MAAM,QAAQ,EAAE,cAAc,CAAC,GAAG,CAAC;AAEjD,SAAO,IAAI,GAAG,MAAM,UAAU,EAAE,KAAK,IAAI;AAEzC,SAAO,IAAI,GAAG,IAAI,EAAE,KAAK,IAAI;AAC7B,SAAO,IAAI,GAAG,MAAM,QAAQ,EAAE,cAAc,CAAC,GAAG,CAAC;AACnD,CAAC;AAED,KAAK,6BAA6B,MAAM;AACtC,QAAM,MAAM,mBAAmB,MAAM;AAAA,IACnC,UAAU,CAAC,KAAK,EAAE;AAAA,EACpB,CAAC;AAED,SAAO,IAAI,GAAG,IAAI,EAAE,KAAK,IAAI;AAC7B,SAAO,IAAI,GAAG,MAAM,QAAQ,EAAE,cAAc,CAAC,GAAG,CAAC;AAEjD,SAAO,IAAI,GAAG,MAAM,UAAU,EAAE,KAAK,IAAI;AAC3C,CAAC;",
6
+ "names": []
7
+ }
File without changes
File without changes
File without changes
File without changes
@@ -1,9 +1,9 @@
1
- import { Text, getTextSize, styled } from "@tamagui/core";
1
+ import { Text, getFont, styled } from "@tamagui/core";
2
2
  const SizableText = styled(Text, {
3
3
  name: "SizableText",
4
4
  fontFamily: "$body",
5
5
  variants: {
6
- size: getTextSize
6
+ size: getFont
7
7
  },
8
8
  defaultVariants: {
9
9
  size: "$4"
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/SizableText.tsx"],
4
- "sourcesContent": ["import { GetProps, Text, getTextSize, styled } from '@tamagui/core'\n\nexport const SizableText = styled(\n Text,\n {\n name: 'SizableText',\n fontFamily: '$body',\n\n variants: {\n size: getTextSize,\n },\n\n defaultVariants: {\n size: '$4',\n },\n },\n {\n inlineWhenUnflattened: new Set(['fontFamily']),\n }\n)\n\nexport type SizableTextProps = GetProps<typeof SizableText>\n"],
4
+ "sourcesContent": ["import { GetProps, Text, getFont, styled } from '@tamagui/core'\n\nexport const SizableText = styled(\n Text,\n {\n name: 'SizableText',\n fontFamily: '$body',\n\n variants: {\n size: getFont,\n },\n\n defaultVariants: {\n size: '$4',\n },\n },\n {\n inlineWhenUnflattened: new Set(['fontFamily']),\n }\n)\n\nexport type SizableTextProps = GetProps<typeof SizableText>\n"],
5
5
  "mappings": "AAAA;AAEO,MAAM,cAAc,OACzB,MACA;AAAA,EACE,MAAM;AAAA,EACN,YAAY;AAAA,EAEZ,UAAU;AAAA,IACR,MAAM;AAAA,EACR;AAAA,EAEA,iBAAiB;AAAA,IACf,MAAM;AAAA,EACR;AACF,GACA;AAAA,EACE,uBAAuB,oBAAI,IAAI,CAAC,YAAY,CAAC;AAC/C,CACF;",
6
6
  "names": []
7
7
  }
package/dist/jsx/Texts.js CHANGED
File without changes
File without changes
package/dist/jsx/index.js CHANGED
@@ -1,4 +1,5 @@
1
1
  export * from "./SizableText";
2
2
  export * from "./Paragraph";
3
3
  export * from "./Headings";
4
+ export * from "./wrapChildrenInText";
4
5
  //# sourceMappingURL=index.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/index.tsx"],
4
- "sourcesContent": ["export * from './SizableText'\nexport * from './Paragraph'\nexport * from './Headings'\n"],
5
- "mappings": "AAAA;AACA;AACA;",
4
+ "sourcesContent": ["export * from './SizableText'\nexport * from './Paragraph'\nexport * from './Headings'\nexport * from './wrapChildrenInText'\n"],
5
+ "mappings": "AAAA;AACA;AACA;AACA;",
6
6
  "names": []
7
7
  }
@@ -0,0 +1,61 @@
1
+ import React from "react";
2
+ function wrapChildrenInText(TextComponent, {
3
+ children,
4
+ textProps,
5
+ size,
6
+ noTextWrap,
7
+ color,
8
+ fontFamily,
9
+ fontSize,
10
+ fontWeight,
11
+ letterSpacing,
12
+ textAlign
13
+ }) {
14
+ if (noTextWrap || !children) {
15
+ return children;
16
+ }
17
+ let allChildren = React.Children.toArray(children);
18
+ let nextChildren = [];
19
+ let lastIsString = false;
20
+ const directTextProps = {};
21
+ if (color)
22
+ directTextProps.color = color;
23
+ if (fontFamily)
24
+ directTextProps.fontFamily = fontFamily;
25
+ if (fontSize)
26
+ directTextProps.fontSize = fontSize;
27
+ if (fontWeight)
28
+ directTextProps.fontWeight = fontWeight;
29
+ if (letterSpacing)
30
+ directTextProps.letterSpacing = letterSpacing;
31
+ if (textAlign)
32
+ directTextProps.textAlign = textAlign;
33
+ function concatStringChildren() {
34
+ if (!lastIsString)
35
+ return;
36
+ const index = nextChildren.length - 1;
37
+ const childrenStrings = nextChildren[index];
38
+ nextChildren[index] = <TextComponent key={index} {...directTextProps} size={size} {...textProps}>{childrenStrings}</TextComponent>;
39
+ }
40
+ for (const child of allChildren) {
41
+ const last = nextChildren[nextChildren.length - 1];
42
+ const isString = typeof child === "string";
43
+ if (isString) {
44
+ if (lastIsString) {
45
+ last.push(child);
46
+ } else {
47
+ nextChildren.push([child]);
48
+ }
49
+ } else {
50
+ concatStringChildren();
51
+ nextChildren.push(child);
52
+ }
53
+ lastIsString = isString;
54
+ }
55
+ concatStringChildren();
56
+ return nextChildren;
57
+ }
58
+ export {
59
+ wrapChildrenInText
60
+ };
61
+ //# sourceMappingURL=wrapChildrenInText.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/wrapChildrenInText.tsx"],
4
+ "sourcesContent": ["import type { SizeTokens } from '@tamagui/core'\nimport React from 'react'\n\nimport { SizableTextProps } from './SizableText'\n\nexport type TextParentStyles = {\n color?: SizableTextProps['color']\n fontWeight?: SizableTextProps['fontWeight']\n fontSize?: SizableTextProps['fontSize']\n fontFamily?: SizableTextProps['fontFamily']\n letterSpacing?: SizableTextProps['letterSpacing']\n textAlign?: SizableTextProps['textAlign']\n // all the other text controls\n textProps?: Partial<SizableTextProps>\n noTextWrap?: boolean\n}\n\ntype Props = TextParentStyles & {\n children?: React.ReactNode\n size?: SizeTokens\n}\n\nexport function wrapChildrenInText(\n TextComponent: any,\n {\n children,\n textProps,\n size,\n noTextWrap,\n color,\n fontFamily,\n fontSize,\n fontWeight,\n letterSpacing,\n textAlign,\n }: Props\n) {\n if (noTextWrap || !children) {\n return children\n }\n\n // in the case of using variables, like so:\n // <ListItem>Hello, {name}</ListItem>\n // it gives us props.children as ['Hello, ', 'name']\n // but we don't want to wrap multiple SizableText around each part\n // so we group them\n let allChildren = React.Children.toArray(children)\n let nextChildren: any[] = []\n let lastIsString = false\n const directTextProps: any = {}\n // to avoid setting undefined\n if (color) directTextProps.color = color\n if (fontFamily) directTextProps.fontFamily = fontFamily\n if (fontSize) directTextProps.fontSize = fontSize\n if (fontWeight) directTextProps.fontWeight = fontWeight\n if (letterSpacing) directTextProps.letterSpacing = letterSpacing\n if (textAlign) directTextProps.textAlign = textAlign\n\n function concatStringChildren() {\n if (!lastIsString) return\n const index = nextChildren.length - 1\n const childrenStrings = nextChildren[index]\n nextChildren[index] = (\n <TextComponent key={index} {...directTextProps} size={size} {...textProps}>\n {childrenStrings}\n </TextComponent>\n )\n }\n\n for (const child of allChildren) {\n const last = nextChildren[nextChildren.length - 1]\n const isString = typeof child === 'string'\n if (isString) {\n if (lastIsString) {\n last.push(child)\n } else {\n nextChildren.push([child])\n }\n } else {\n concatStringChildren()\n nextChildren.push(child)\n }\n lastIsString = isString\n }\n concatStringChildren()\n\n return nextChildren\n}\n"],
5
+ "mappings": "AACA;AAqBO,4BACL,eACA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,GAEF;AACA,MAAI,cAAc,CAAC,UAAU;AAC3B,WAAO;AAAA,EACT;AAOA,MAAI,cAAc,MAAM,SAAS,QAAQ,QAAQ;AACjD,MAAI,eAAsB,CAAC;AAC3B,MAAI,eAAe;AACnB,QAAM,kBAAuB,CAAC;AAE9B,MAAI;AAAO,oBAAgB,QAAQ;AACnC,MAAI;AAAY,oBAAgB,aAAa;AAC7C,MAAI;AAAU,oBAAgB,WAAW;AACzC,MAAI;AAAY,oBAAgB,aAAa;AAC7C,MAAI;AAAe,oBAAgB,gBAAgB;AACnD,MAAI;AAAW,oBAAgB,YAAY;AAE3C,kCAAgC;AAC9B,QAAI,CAAC;AAAc;AACnB,UAAM,QAAQ,aAAa,SAAS;AACpC,UAAM,kBAAkB,aAAa;AACrC,iBAAa,SACX,CAAC,cAAc,KAAK,WAAW,iBAAiB,MAAM,UAAU,YAC7D,gBACH,EAFC;AAAA,EAIL;AAEA,aAAW,SAAS,aAAa;AAC/B,UAAM,OAAO,aAAa,aAAa,SAAS;AAChD,UAAM,WAAW,OAAO,UAAU;AAClC,QAAI,UAAU;AACZ,UAAI,cAAc;AAChB,aAAK,KAAK,KAAK;AAAA,MACjB,OAAO;AACL,qBAAa,KAAK,CAAC,KAAK,CAAC;AAAA,MAC3B;AAAA,IACF,OAAO;AACL,2BAAqB;AACrB,mBAAa,KAAK,KAAK;AAAA,IACzB;AACA,mBAAe;AAAA,EACjB;AACA,uBAAqB;AAErB,SAAO;AACT;",
6
+ "names": []
7
+ }
@@ -0,0 +1,29 @@
1
+ import { expect, test } from "vitest";
2
+ import { wrapChildrenInText } from "./wrapChildrenInText";
3
+ const Comp = () => {
4
+ };
5
+ const re = <div data-id={Math.random()} />;
6
+ const reID = re.props["data-id"];
7
+ test("should wrap all string children, not wrap others", () => {
8
+ const out = wrapChildrenInText(Comp, {
9
+ children: [re, "a", "b", re, "c", re, "d"]
10
+ });
11
+ expect(out[0].props["data-id"]).toBe(reID);
12
+ expect(out[1].type).toBe(Comp);
13
+ expect(out[1].props.children).toStrictEqual(["a", "b"]);
14
+ expect(out[2].props["data-id"]).toBe(reID);
15
+ expect(out[3].type).toBe(Comp);
16
+ expect(out[3].props.children).toStrictEqual(["c"]);
17
+ expect(out[4].props["data-id"]).toBe(reID);
18
+ expect(out[5].type).toBe(Comp);
19
+ expect(out[5].props.children).toStrictEqual(["d"]);
20
+ });
21
+ test("should first child string", () => {
22
+ const out = wrapChildrenInText(Comp, {
23
+ children: ["a", re]
24
+ });
25
+ expect(out[0].type).toBe(Comp);
26
+ expect(out[0].props.children).toStrictEqual(["a"]);
27
+ expect(out[1].props["data-id"]).toBe(reID);
28
+ });
29
+ //# sourceMappingURL=wrapChildrenInText.test.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/wrapChildrenInText.test.tsx"],
4
+ "sourcesContent": ["import { expect, test } from 'vitest'\n\nimport { wrapChildrenInText } from './wrapChildrenInText'\n\nconst Comp = () => {}\nconst re = <div data-id={Math.random()} />\nconst reID = re.props['data-id']\n\ntest('should wrap all string children, not wrap others', () => {\n const out = wrapChildrenInText(Comp, {\n children: [re, 'a', 'b', re, 'c', re, 'd'],\n }) as any\n\n expect(out[0].props['data-id']).toBe(reID)\n\n expect(out[1].type).toBe(Comp)\n expect(out[1].props.children).toStrictEqual(['a', 'b'])\n\n expect(out[2].props['data-id']).toBe(reID)\n\n expect(out[3].type).toBe(Comp)\n expect(out[3].props.children).toStrictEqual(['c'])\n\n expect(out[4].props['data-id']).toBe(reID)\n\n expect(out[5].type).toBe(Comp)\n expect(out[5].props.children).toStrictEqual(['d'])\n})\n\ntest('should first child string', () => {\n const out = wrapChildrenInText(Comp, {\n children: ['a', re],\n }) as any\n\n expect(out[0].type).toBe(Comp)\n expect(out[0].props.children).toStrictEqual(['a'])\n\n expect(out[1].props['data-id']).toBe(reID)\n})\n"],
5
+ "mappings": "AAAA;AAEA;AAEA,MAAM,OAAO,MAAM;AAAC;AACpB,MAAM,KAAK,CAAC,IAAI,SAAS,KAAK,OAAO,GAAG;AACxC,MAAM,OAAO,GAAG,MAAM;AAEtB,KAAK,oDAAoD,MAAM;AAC7D,QAAM,MAAM,mBAAmB,MAAM;AAAA,IACnC,UAAU,CAAC,IAAI,KAAK,KAAK,IAAI,KAAK,IAAI,GAAG;AAAA,EAC3C,CAAC;AAED,SAAO,IAAI,GAAG,MAAM,UAAU,EAAE,KAAK,IAAI;AAEzC,SAAO,IAAI,GAAG,IAAI,EAAE,KAAK,IAAI;AAC7B,SAAO,IAAI,GAAG,MAAM,QAAQ,EAAE,cAAc,CAAC,KAAK,GAAG,CAAC;AAEtD,SAAO,IAAI,GAAG,MAAM,UAAU,EAAE,KAAK,IAAI;AAEzC,SAAO,IAAI,GAAG,IAAI,EAAE,KAAK,IAAI;AAC7B,SAAO,IAAI,GAAG,MAAM,QAAQ,EAAE,cAAc,CAAC,GAAG,CAAC;AAEjD,SAAO,IAAI,GAAG,MAAM,UAAU,EAAE,KAAK,IAAI;AAEzC,SAAO,IAAI,GAAG,IAAI,EAAE,KAAK,IAAI;AAC7B,SAAO,IAAI,GAAG,MAAM,QAAQ,EAAE,cAAc,CAAC,GAAG,CAAC;AACnD,CAAC;AAED,KAAK,6BAA6B,MAAM;AACtC,QAAM,MAAM,mBAAmB,MAAM;AAAA,IACnC,UAAU,CAAC,KAAK,EAAE;AAAA,EACpB,CAAC;AAED,SAAO,IAAI,GAAG,IAAI,EAAE,KAAK,IAAI;AAC7B,SAAO,IAAI,GAAG,MAAM,QAAQ,EAAE,cAAc,CAAC,GAAG,CAAC;AAEjD,SAAO,IAAI,GAAG,MAAM,UAAU,EAAE,KAAK,IAAI;AAC3C,CAAC;",
6
+ "names": []
7
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tamagui/text",
3
- "version": "1.0.1-beta.92",
3
+ "version": "1.0.1-beta.95",
4
4
  "sideEffects": [
5
5
  "*.css"
6
6
  ],
@@ -16,19 +16,24 @@
16
16
  ],
17
17
  "scripts": {
18
18
  "build": "tamagui-build",
19
- "watch": "tamagui-build --watch"
19
+ "watch": "tamagui-build --watch",
20
+ "clean": "tamagui-build clean",
21
+ "clean:build": "tamagui-build clean:build",
22
+ "test": "vitest --config ../vite-plugin-internal/vite.config.ts"
20
23
  },
21
24
  "dependencies": {
22
- "@tamagui/core": "^1.0.1-beta.92"
25
+ "@tamagui/core": "^1.0.1-beta.95"
23
26
  },
24
27
  "peerDependencies": {
25
28
  "react": "*",
26
29
  "react-dom": "*"
27
30
  },
28
31
  "devDependencies": {
29
- "@tamagui/build": "^1.0.1-beta.92",
32
+ "@tamagui/build": "^1.0.1-beta.95",
33
+ "@tamagui/vite-plugin-internal": "^1.0.1-beta.95",
30
34
  "react": "*",
31
- "react-dom": "*"
35
+ "react-dom": "*",
36
+ "vitest": "^0.16.0"
32
37
  },
33
38
  "publishConfig": {
34
39
  "access": "public"
@@ -1,4 +1,4 @@
1
- import { GetProps, Text, getTextSize, styled } from '@tamagui/core'
1
+ import { GetProps, Text, getFont, styled } from '@tamagui/core'
2
2
 
3
3
  export const SizableText = styled(
4
4
  Text,
@@ -7,7 +7,7 @@ export const SizableText = styled(
7
7
  fontFamily: '$body',
8
8
 
9
9
  variants: {
10
- size: getTextSize,
10
+ size: getFont,
11
11
  },
12
12
 
13
13
  defaultVariants: {
package/src/index.tsx CHANGED
@@ -1,3 +1,4 @@
1
1
  export * from './SizableText'
2
2
  export * from './Paragraph'
3
3
  export * from './Headings'
4
+ export * from './wrapChildrenInText'
@@ -0,0 +1,39 @@
1
+ import { expect, test } from 'vitest'
2
+
3
+ import { wrapChildrenInText } from './wrapChildrenInText'
4
+
5
+ const Comp = () => {}
6
+ const re = <div data-id={Math.random()} />
7
+ const reID = re.props['data-id']
8
+
9
+ test('should wrap all string children, not wrap others', () => {
10
+ const out = wrapChildrenInText(Comp, {
11
+ children: [re, 'a', 'b', re, 'c', re, 'd'],
12
+ }) as any
13
+
14
+ expect(out[0].props['data-id']).toBe(reID)
15
+
16
+ expect(out[1].type).toBe(Comp)
17
+ expect(out[1].props.children).toStrictEqual(['a', 'b'])
18
+
19
+ expect(out[2].props['data-id']).toBe(reID)
20
+
21
+ expect(out[3].type).toBe(Comp)
22
+ expect(out[3].props.children).toStrictEqual(['c'])
23
+
24
+ expect(out[4].props['data-id']).toBe(reID)
25
+
26
+ expect(out[5].type).toBe(Comp)
27
+ expect(out[5].props.children).toStrictEqual(['d'])
28
+ })
29
+
30
+ test('should first child string', () => {
31
+ const out = wrapChildrenInText(Comp, {
32
+ children: ['a', re],
33
+ }) as any
34
+
35
+ expect(out[0].type).toBe(Comp)
36
+ expect(out[0].props.children).toStrictEqual(['a'])
37
+
38
+ expect(out[1].props['data-id']).toBe(reID)
39
+ })
@@ -0,0 +1,88 @@
1
+ import type { SizeTokens } from '@tamagui/core'
2
+ import React from 'react'
3
+
4
+ import { SizableTextProps } from './SizableText'
5
+
6
+ export type TextParentStyles = {
7
+ color?: SizableTextProps['color']
8
+ fontWeight?: SizableTextProps['fontWeight']
9
+ fontSize?: SizableTextProps['fontSize']
10
+ fontFamily?: SizableTextProps['fontFamily']
11
+ letterSpacing?: SizableTextProps['letterSpacing']
12
+ textAlign?: SizableTextProps['textAlign']
13
+ // all the other text controls
14
+ textProps?: Partial<SizableTextProps>
15
+ noTextWrap?: boolean
16
+ }
17
+
18
+ type Props = TextParentStyles & {
19
+ children?: React.ReactNode
20
+ size?: SizeTokens
21
+ }
22
+
23
+ export function wrapChildrenInText(
24
+ TextComponent: any,
25
+ {
26
+ children,
27
+ textProps,
28
+ size,
29
+ noTextWrap,
30
+ color,
31
+ fontFamily,
32
+ fontSize,
33
+ fontWeight,
34
+ letterSpacing,
35
+ textAlign,
36
+ }: Props
37
+ ) {
38
+ if (noTextWrap || !children) {
39
+ return children
40
+ }
41
+
42
+ // in the case of using variables, like so:
43
+ // <ListItem>Hello, {name}</ListItem>
44
+ // it gives us props.children as ['Hello, ', 'name']
45
+ // but we don't want to wrap multiple SizableText around each part
46
+ // so we group them
47
+ let allChildren = React.Children.toArray(children)
48
+ let nextChildren: any[] = []
49
+ let lastIsString = false
50
+ const directTextProps: any = {}
51
+ // to avoid setting undefined
52
+ if (color) directTextProps.color = color
53
+ if (fontFamily) directTextProps.fontFamily = fontFamily
54
+ if (fontSize) directTextProps.fontSize = fontSize
55
+ if (fontWeight) directTextProps.fontWeight = fontWeight
56
+ if (letterSpacing) directTextProps.letterSpacing = letterSpacing
57
+ if (textAlign) directTextProps.textAlign = textAlign
58
+
59
+ function concatStringChildren() {
60
+ if (!lastIsString) return
61
+ const index = nextChildren.length - 1
62
+ const childrenStrings = nextChildren[index]
63
+ nextChildren[index] = (
64
+ <TextComponent key={index} {...directTextProps} size={size} {...textProps}>
65
+ {childrenStrings}
66
+ </TextComponent>
67
+ )
68
+ }
69
+
70
+ for (const child of allChildren) {
71
+ const last = nextChildren[nextChildren.length - 1]
72
+ const isString = typeof child === 'string'
73
+ if (isString) {
74
+ if (lastIsString) {
75
+ last.push(child)
76
+ } else {
77
+ nextChildren.push([child])
78
+ }
79
+ } else {
80
+ concatStringChildren()
81
+ nextChildren.push(child)
82
+ }
83
+ lastIsString = isString
84
+ }
85
+ concatStringChildren()
86
+
87
+ return nextChildren
88
+ }
File without changes
File without changes
@@ -1 +1 @@
1
- {"version":3,"file":"SizableText.d.ts","sourceRoot":"","sources":["../src/SizableText.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAA6B,MAAM,eAAe,CAAA;AAEnE,eAAO,MAAM,WAAW;;;;;;;;EAiBvB,CAAA;AAED,oBAAY,gBAAgB,GAAG,QAAQ,CAAC,OAAO,WAAW,CAAC,CAAA"}
1
+ {"version":3,"file":"SizableText.d.ts","sourceRoot":"","sources":["../src/SizableText.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAyB,MAAM,eAAe,CAAA;AAE/D,eAAO,MAAM,WAAW;;;;;;;;EAiBvB,CAAA;AAED,oBAAY,gBAAgB,GAAG,QAAQ,CAAC,OAAO,WAAW,CAAC,CAAA"}
package/types/index.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  export * from './SizableText';
2
2
  export * from './Paragraph';
3
3
  export * from './Headings';
4
+ export * from './wrapChildrenInText';
4
5
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.tsx"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAA;AAC7B,cAAc,aAAa,CAAA;AAC3B,cAAc,YAAY,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.tsx"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAA;AAC7B,cAAc,aAAa,CAAA;AAC3B,cAAc,YAAY,CAAA;AAC1B,cAAc,sBAAsB,CAAA"}
@@ -0,0 +1,20 @@
1
+ import type { SizeTokens } from '@tamagui/core';
2
+ import React from 'react';
3
+ import { SizableTextProps } from './SizableText';
4
+ export declare type TextParentStyles = {
5
+ color?: SizableTextProps['color'];
6
+ fontWeight?: SizableTextProps['fontWeight'];
7
+ fontSize?: SizableTextProps['fontSize'];
8
+ fontFamily?: SizableTextProps['fontFamily'];
9
+ letterSpacing?: SizableTextProps['letterSpacing'];
10
+ textAlign?: SizableTextProps['textAlign'];
11
+ textProps?: Partial<SizableTextProps>;
12
+ noTextWrap?: boolean;
13
+ };
14
+ declare type Props = TextParentStyles & {
15
+ children?: React.ReactNode;
16
+ size?: SizeTokens;
17
+ };
18
+ export declare function wrapChildrenInText(TextComponent: any, { children, textProps, size, noTextWrap, color, fontFamily, fontSize, fontWeight, letterSpacing, textAlign, }: Props): string | number | boolean | any[] | React.ReactElement<any, string | React.JSXElementConstructor<any>> | React.ReactFragment | null | undefined;
19
+ export {};
20
+ //# sourceMappingURL=wrapChildrenInText.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"wrapChildrenInText.d.ts","sourceRoot":"","sources":["../src/wrapChildrenInText.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,eAAe,CAAA;AAC/C,OAAO,KAAK,MAAM,OAAO,CAAA;AAEzB,OAAO,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAA;AAEhD,oBAAY,gBAAgB,GAAG;IAC7B,KAAK,CAAC,EAAE,gBAAgB,CAAC,OAAO,CAAC,CAAA;IACjC,UAAU,CAAC,EAAE,gBAAgB,CAAC,YAAY,CAAC,CAAA;IAC3C,QAAQ,CAAC,EAAE,gBAAgB,CAAC,UAAU,CAAC,CAAA;IACvC,UAAU,CAAC,EAAE,gBAAgB,CAAC,YAAY,CAAC,CAAA;IAC3C,aAAa,CAAC,EAAE,gBAAgB,CAAC,eAAe,CAAC,CAAA;IACjD,SAAS,CAAC,EAAE,gBAAgB,CAAC,WAAW,CAAC,CAAA;IAEzC,SAAS,CAAC,EAAE,OAAO,CAAC,gBAAgB,CAAC,CAAA;IACrC,UAAU,CAAC,EAAE,OAAO,CAAA;CACrB,CAAA;AAED,aAAK,KAAK,GAAG,gBAAgB,GAAG;IAC9B,QAAQ,CAAC,EAAE,KAAK,CAAC,SAAS,CAAA;IAC1B,IAAI,CAAC,EAAE,UAAU,CAAA;CAClB,CAAA;AAED,wBAAgB,kBAAkB,CAChC,aAAa,EAAE,GAAG,EAClB,EACE,QAAQ,EACR,SAAS,EACT,IAAI,EACJ,UAAU,EACV,KAAK,EACL,UAAU,EACV,QAAQ,EACR,UAAU,EACV,aAAa,EACb,SAAS,GACV,EAAE,KAAK,mJAoDT"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=wrapChildrenInText.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"wrapChildrenInText.test.d.ts","sourceRoot":"","sources":["../src/wrapChildrenInText.test.tsx"],"names":[],"mappings":""}
@@ -1 +0,0 @@
1
- {"version":3,"file":"Texts.d.ts","sourceRoot":"","sources":["../src/Texts.tsx"],"names":[],"mappings":""}