reborn-ui 0.1.69 → 0.1.73

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 (40) hide show
  1. package/dist/index.js +338 -40
  2. package/dist/index.js.map +1 -1
  3. package/package.json +53 -52
  4. package/registry/components/animate-grid.json +2 -2
  5. package/registry/components/bending-gallery.json +2 -2
  6. package/registry/components/bg-bubbles.json +2 -2
  7. package/registry/components/bg-falling-stars.json +2 -2
  8. package/registry/components/color-picker.json +2 -2
  9. package/registry/components/dither-shader.json +2 -2
  10. package/registry/components/flip-words.json +2 -2
  11. package/registry/components/github-globe.json +2 -2
  12. package/registry/components/hyper-text.json +2 -2
  13. package/registry/components/icon-cloud.json +2 -2
  14. package/registry/components/image-trail-cursor.json +1 -1
  15. package/registry/components/images-slider.json +2 -2
  16. package/registry/components/infinite-grid.json +1 -1
  17. package/registry/components/light-speed.json +1 -1
  18. package/registry/components/particle-image.json +1 -1
  19. package/registry/components/particles-bg.json +2 -2
  20. package/registry/components/reborn-affix.json +25 -0
  21. package/registry/components/reborn-back-top.json +30 -0
  22. package/registry/components/reborn-badge.json +3 -3
  23. package/registry/components/reborn-button.json +3 -3
  24. package/registry/components/reborn-checkbox.json +3 -3
  25. package/registry/components/reborn-chip.json +31 -0
  26. package/registry/components/reborn-collapse.json +31 -0
  27. package/registry/components/reborn-form.json +50 -0
  28. package/registry/components/reborn-image.json +35 -0
  29. package/registry/components/reborn-input-number.json +3 -3
  30. package/registry/components/reborn-input.json +4 -4
  31. package/registry/components/reborn-sticky.json +29 -0
  32. package/registry/components/reborn-switch.json +3 -3
  33. package/registry/components/reborn-tabs.json +8 -28
  34. package/registry/components/reborn-textarea.json +32 -0
  35. package/registry/components/shader-toy.json +3 -3
  36. package/registry/components/sparkles-text.json +2 -2
  37. package/registry/components/sparkles.json +2 -2
  38. package/registry/components/vanishing-input.json +2 -2
  39. package/registry/components/video-text.json +2 -2
  40. package/registry/registry.json +267 -40
package/dist/index.js CHANGED
@@ -254,7 +254,7 @@ function addCommand() {
254
254
  if (opts.yes) {
255
255
  throw new Error("\u672A\u6307\u5B9A\u7EC4\u4EF6\u540D\uFF1B\u8BF7\u4F20\u5165\u7EC4\u4EF6\u53C2\u6570\u6216\u53BB\u6389 --yes \u4EE5\u4EA4\u4E92\u9009\u62E9\u3002");
256
256
  }
257
- const choices = registry.components.map((c) => ({
257
+ const choices = registry.components?.map((c) => ({
258
258
  title: c.name,
259
259
  value: c.name
260
260
  }));
@@ -431,11 +431,11 @@ function buildCommand() {
431
431
  const sourceDir = path5.join(rootDir, opts.source);
432
432
  const uniappSourceDir = opts.uniappSource ? path5.join(rootDir, opts.uniappSource) : "";
433
433
  const outPath = path5.join(rootDir, opts.out);
434
- const alsoOutPaths = (opts.alsoOut ?? []).map(
434
+ const alsoOutPaths = (opts.alsoOut ?? [])?.map(
435
435
  (p) => path5.join(rootDir, p)
436
436
  );
437
437
  const dirents = await fs4.readdir(sourceDir, { withFileTypes: true });
438
- const componentDirs = dirents.filter((d) => d.isDirectory()).map((d) => path5.join(sourceDir, d.name)).sort((a, b) => a.localeCompare(b));
438
+ const componentDirs = dirents.filter((d) => d.isDirectory())?.map((d) => path5.join(sourceDir, d.name)).sort((a, b) => a.localeCompare(b));
439
439
  const components = [];
440
440
  for (const absComponentDir of componentDirs) {
441
441
  const name = path5.basename(absComponentDir);
@@ -519,7 +519,7 @@ function buildCommand() {
519
519
  {
520
520
  ...c,
521
521
  fileCount: c.files.length,
522
- contentHash: sha1(JSON.stringify(c.files.map((f) => f.content)))
522
+ contentHash: sha1(JSON.stringify(c.files?.map((f) => f.content)))
523
523
  }
524
524
  );
525
525
  }
@@ -554,6 +554,295 @@ function findNearestPackageRoot2(from) {
554
554
  }
555
555
  }
556
556
 
557
+ // src/generated/templates.ts
558
+ var TEMPLATES = {
559
+ "web": {
560
+ "lib/tv.ts": 'import { createTV } from "tailwind-variants";\r\nimport { twMergeConfig } from "./utils";\r\n\r\nexport const tv = createTV({\r\n twMergeConfig,\r\n});\r\nexport type { VariantProps } from "tailwind-variants";\r\n',
561
+ "lib/utils.ts": 'import type { ClassValue } from "clsx";\r\nimport { clsx } from "clsx";\r\nimport { extendTailwindMerge } from "tailwind-merge";\r\n\r\nexport const twMergeConfig = {\r\n extend: {\r\n classGroups: {\r\n "font-size": [{ text: [(value: string) => !isNaN(Number(value))] }],\r\n },\r\n },\r\n};\r\n\r\nconst customTwMerge = extendTailwindMerge(twMergeConfig);\r\n\r\nexport function cn(...inputs: ClassValue[]) {\r\n return customTwMerge(clsx(inputs));\r\n}\r\n\r\nexport type ObjectValues<T> = T[keyof T];\r\n',
562
+ "composables/useFieldGroup.ts": "\r\nimport { ref } from 'vue'\r\n\r\nexport function useFieldGroup(props: any) {\r\n return {\r\n disabled: ref(undefined),\r\n isError: ref(undefined),\r\n orientation: ref(undefined),\r\n size: ref(undefined)\r\n }\r\n}\r\n",
563
+ "composables/useMouseState.ts": 'import { readonly, ref } from "vue";\r\n\r\nexport function useMouseState() {\r\n const isMouseEntered = ref(false);\r\n\r\n function setMouseEntered(value: boolean) {\r\n isMouseEntered.value = value;\r\n }\r\n\r\n return {\r\n isMouseEntered: readonly(isMouseEntered),\r\n setMouseEntered,\r\n };\r\n}\r\n',
564
+ "composables/useNavigation.ts": `import type { ContentNavigationItem } from "@nuxt/content";\r
565
+ \r
566
+ export function useNavigation(navigation?: Ref<ContentNavigationItem[]>) {\r
567
+ const route = useRoute();\r
568
+ \r
569
+ const children = computed(() => {\r
570
+ const nav = toValue(navigation);\r
571
+ \r
572
+ // Get the current path segments\r
573
+ const pathSegments = route.path.split("/").filter(Boolean);\r
574
+ \r
575
+ // Need at least one section (e.g., ['components', 'button'])\r
576
+ if (pathSegments.length < 1) {\r
577
+ return [];\r
578
+ }\r
579
+ \r
580
+ // Build the top parent path (e.g., '/components')\r
581
+ const topParentPath = \`/\${pathSegments[0]}\`;\r
582
+ \r
583
+ // Find the matching top-level navigation item\r
584
+ const topParent = nav?.find((item) => item.path === topParentPath);\r
585
+ \r
586
+ return topParent?.children || [];\r
587
+ });\r
588
+ \r
589
+ const isFlatList = computed(() => {\r
590
+ return children.value.every((child) => !child.children || child.children.length === 0);\r
591
+ });\r
592
+ \r
593
+ const nav = computed(() => {\r
594
+ if (isFlatList.value) {\r
595
+ return [\r
596
+ {\r
597
+ title: "Overview",\r
598
+ path: children.value.at(0)?.path || "",\r
599
+ children: children.value,\r
600
+ },\r
601
+ ];\r
602
+ }\r
603
+ \r
604
+ return children.value;\r
605
+ });\r
606
+ \r
607
+ return {\r
608
+ nav,\r
609
+ };\r
610
+ }\r
611
+ `
612
+ },
613
+ "uniapp": {
614
+ "lib/tv.ts": `// @ts-ignore\r
615
+ import type { TV } from "tailwind-variants";\r
616
+ import { create } from '@weapp-tailwindcss/variants-v3'\r
617
+ \r
618
+ // @ts-ignore\r
619
+ const isH5 = process.env.UNI_PLATFORM === 'h5'\r
620
+ \r
621
+ const { tv: createTV } = create({\r
622
+ // @ts-ignore\r
623
+ escape: !isH5,\r
624
+ // @ts-ignore\r
625
+ unescape: !isH5,\r
626
+ })\r
627
+ \r
628
+ const textSizeKeys = ['20', '22', '24', '26', '28', '30', '32', '36', '40', '48', '52']\r
629
+ \r
630
+ const twMergeConfig = {\r
631
+ extend: {\r
632
+ classGroups: {\r
633
+ 'font-size': [{ text: textSizeKeys }],\r
634
+ },\r
635
+ },\r
636
+ } as const\r
637
+ \r
638
+ export const tv: TV = (options, config) =>\r
639
+ createTV(options, {\r
640
+ ...config,\r
641
+ twMerge: config?.twMerge ?? true,\r
642
+ twMergeConfig: {\r
643
+ ...config?.twMergeConfig,\r
644
+ ...twMergeConfig,\r
645
+ },\r
646
+ });\r
647
+ `,
648
+ "lib/utils.ts": "import { type ClassValue, clsx } from 'clsx'\r\nimport { create } from '@weapp-tailwindcss/merge-v3'\r\n\r\n// @ts-ignore\r\nconst isH5 = process.env.UNI_PLATFORM === 'h5'\r\nconst { twMerge } = create({\r\n escape: !isH5,\r\n unescape: !isH5,\r\n // @ts-ignore\r\n extend: {\r\n classGroups: {\r\n 'font-size': [{ text: ['20', '22', '24', '26', '28', '30', '32', '36', '40', '48', '52'] }],\r\n },\r\n },\r\n})\r\n\r\nexport function cn(...inputs: ClassValue[]) {\r\n return twMerge(clsx(inputs))\r\n}\r\n",
649
+ "composables/useDarkMode.ts": "export const useDarkMode = () => {\r\n const isDark = ref(false)\r\n\r\n const toggleDarkMode = () => {\r\n isDark.value = !isDark.value\r\n updateTheme()\r\n }\r\n\r\n const updateTheme = () => {\r\n const value = isDark.value\r\n uni.setStorageSync('darkMode', value)\r\n\r\n // #ifdef H5\r\n if (value) {\r\n document.documentElement.classList.add('dark')\r\n } else {\r\n document.documentElement.classList.remove('dark')\r\n }\r\n // #endif\r\n\r\n }\r\n\r\n const initTheme = () => {\r\n const saved = uni.getStorageSync('darkMode')\r\n if (saved !== '') {\r\n isDark.value = !!saved\r\n } else {\r\n isDark.value = false\r\n }\r\n updateTheme()\r\n }\r\n\r\n initTheme()\r\n\r\n return {\r\n isDark,\r\n toggleDarkMode\r\n }\r\n}\r\n",
650
+ "composables/useFieldGroup.ts": `import { ref, provide, inject, computed, watch, onMounted, onUnmounted, getCurrentInstance } from 'vue';\r
651
+ import * as z from 'zod';\r
652
+ \r
653
+ export type FormValidateError = {\r
654
+ field: string;\r
655
+ message: string;\r
656
+ };\r
657
+ \r
658
+ export interface UseFieldGroupProps {\r
659
+ modelValue?: any;\r
660
+ }\r
661
+ \r
662
+ export function useFieldGroup() {\r
663
+ \r
664
+ // Data & Context\r
665
+ const errors = ref(new Map<string, string>());\r
666
+ const fields = ref(new Set<string>([]));\r
667
+ const fieldInstances = ref<any[]>([]);\r
668
+ \r
669
+ // --- Field Management ---\r
670
+ const addField = (field: any) => {\r
671
+ fieldInstances.value.push(field);\r
672
+ if (field.prop) {\r
673
+ fields.value.add(field.prop);\r
674
+ }\r
675
+ };\r
676
+ \r
677
+ const removeField = (field: any) => {\r
678
+ const index = fieldInstances.value.indexOf(field);\r
679
+ if (index > -1) {\r
680
+ fieldInstances.value.splice(index, 1);\r
681
+ }\r
682
+ if (field.prop) {\r
683
+ fields.value.delete(field.prop);\r
684
+ }\r
685
+ };\r
686
+ \r
687
+ // --- Error Management ---\r
688
+ const errorLock = ref(false);\r
689
+ \r
690
+ function setError(prop: string, error: string) {\r
691
+ if (errorLock.value) return;\r
692
+ if (prop !== "") errors.value.set(prop, error);\r
693
+ }\r
694
+ \r
695
+ function removeError(prop: string) {\r
696
+ if (prop !== "") errors.value.delete(prop);\r
697
+ }\r
698
+ \r
699
+ function getError(prop: string): string {\r
700
+ if (prop !== "") return errors.value.get(prop) ?? "";\r
701
+ return "";\r
702
+ }\r
703
+ \r
704
+ async function getErrors(): Promise<FormValidateError[]> {\r
705
+ const errs = [] as FormValidateError[];\r
706
+ errors.value.forEach((msg, field) => {\r
707
+ errs.push({ field, message: msg });\r
708
+ });\r
709
+ return errs;\r
710
+ }\r
711
+ \r
712
+ function clearValidate(fieldsToClear?: string | string[]) {\r
713
+ if (fieldsToClear) {\r
714
+ const propsArray = Array.isArray(fieldsToClear) ? fieldsToClear : [fieldsToClear];\r
715
+ propsArray.forEach(prop => removeError(prop));\r
716
+ } else {\r
717
+ errors.value.clear();\r
718
+ }\r
719
+ }\r
720
+ \r
721
+ return {\r
722
+ errors,\r
723
+ fields,\r
724
+ fieldInstances,\r
725
+ addField,\r
726
+ removeField,\r
727
+ setError,\r
728
+ removeError,\r
729
+ getError, // Used by children\r
730
+ getErrors, // Used by validate\r
731
+ clearValidate\r
732
+ };\r
733
+ }\r
734
+ \r
735
+ \r
736
+ export interface UseFieldGroupItemProps {\r
737
+ prop?: string;\r
738
+ label?: string;\r
739
+ labelPosition?: string;\r
740
+ labelWidth?: string | number;\r
741
+ ui?: any;\r
742
+ }\r
743
+ \r
744
+ export function useFieldGroupItem(props: UseFieldGroupItemProps) {\r
745
+ const form = inject<any>('rebornForm', undefined);\r
746
+ const instance = getCurrentInstance();\r
747
+ \r
748
+ \r
749
+ const error = computed(() => {\r
750
+ if (!form || !props.prop) return '';\r
751
+ return form.getError ? form.getError(props.prop) : '';\r
752
+ });\r
753
+ \r
754
+ const labelPosition = computed(() => {\r
755
+ return props.labelPosition || form?.props?.labelPosition || 'left';\r
756
+ });\r
757
+ \r
758
+ const labelWidth = computed(() => {\r
759
+ if (labelPosition.value === 'top') return 'auto';\r
760
+ return props.labelWidth || form?.props?.labelWidth || 'auto';\r
761
+ });\r
762
+ \r
763
+ const size = computed(() => {\r
764
+ const s = form?.props?.size;\r
765
+ if (s && ['sm', 'md', 'lg'].includes(s)) {\r
766
+ return s as "sm" | "md" | "lg";\r
767
+ }\r
768
+ return 'sm';\r
769
+ });\r
770
+ \r
771
+ const getBoundingClientRect = (callback: (res: any) => void) => {\r
772
+ uni.createSelectorQuery()\r
773
+ .in(instance?.proxy)\r
774
+ .select('.re-form-item')\r
775
+ .boundingClientRect(callback)\r
776
+ .exec();\r
777
+ };\r
778
+ \r
779
+ // Watch for prop changes to update registration\r
780
+ watch(() => props.prop, (newProp, oldProp) => {\r
781
+ if (form) {\r
782
+ if (oldProp) {\r
783
+ form.removeField({ uid: instance?.uid, prop: oldProp });\r
784
+ }\r
785
+ if (newProp) {\r
786
+ form.addField({ uid: instance?.uid, prop: newProp, getBoundingClientRect });\r
787
+ }\r
788
+ }\r
789
+ });\r
790
+ \r
791
+ onMounted(() => {\r
792
+ if (form && props.prop) {\r
793
+ form.addField({ uid: instance?.uid, prop: props.prop, getBoundingClientRect });\r
794
+ }\r
795
+ });\r
796
+ \r
797
+ onUnmounted(() => {\r
798
+ if (form && props.prop) {\r
799
+ form.removeField({ uid: instance?.uid, prop: props.prop });\r
800
+ }\r
801
+ });\r
802
+ \r
803
+ return {\r
804
+ form,\r
805
+ error,\r
806
+ labelPosition,\r
807
+ labelWidth,\r
808
+ size,\r
809
+ getBoundingClientRect\r
810
+ };\r
811
+ }\r
812
+ \r
813
+ // Consumer for inner components (Input, Select, etc.)\r
814
+ export function useFormInject(props: any) {\r
815
+ const form = inject<any>('rebornForm', null);\r
816
+ const formItem = inject<any>('rebornFormItem', null);\r
817
+ \r
818
+ const size = computed(() => {\r
819
+ return form?.props?.size || props.size;\r
820
+ });\r
821
+ \r
822
+ const disabled = computed(() => {\r
823
+ return form?.props?.disabled || props.disabled;\r
824
+ });\r
825
+ \r
826
+ const orientation = computed(() => {\r
827
+ return form?.props?.orientation || props.orientation;\r
828
+ });\r
829
+ \r
830
+ const isError = computed(() => {\r
831
+ return formItem?.isError?.value || false;\r
832
+ });\r
833
+ \r
834
+ return {\r
835
+ form,\r
836
+ size,\r
837
+ disabled,\r
838
+ orientation,\r
839
+ isError\r
840
+ };\r
841
+ }\r
842
+ `
843
+ }
844
+ };
845
+
557
846
  // src/commands/init.ts
558
847
  function looksLikeNuxtProject(cwd) {
559
848
  return Promise.all([
@@ -598,40 +887,48 @@ async function rewriteAliasInDir(params) {
598
887
  }
599
888
  async function copyTemplates(params) {
600
889
  const { cwd, workspaceRoot, platform, cfg, overwrite } = params;
601
- if (platform === "uniapp") {
602
- const uniappLibSrc = path7.join(workspaceRoot, "packages/uniapp-project/src/lib");
603
- const uniappComposablesSrc = path7.join(workspaceRoot, "packages/uniapp-project/src/composables");
604
- if (await pathExists(uniappLibSrc)) {
605
- await copyDirRecursive({
606
- fromDir: uniappLibSrc,
607
- toDir: path7.join(cwd, cfg.libDir),
608
- overwrite
609
- });
610
- }
611
- if (await pathExists(uniappComposablesSrc)) {
612
- await copyDirRecursive({
613
- fromDir: uniappComposablesSrc,
614
- toDir: path7.join(cwd, cfg.composablesDir),
615
- overwrite
616
- });
617
- }
618
- } else {
619
- const webLibSrc = path7.join(workspaceRoot, "app/lib");
620
- const webComposablesSrc = path7.join(workspaceRoot, "app/composables");
621
- if (await pathExists(webLibSrc)) {
622
- await copyDirRecursive({
623
- fromDir: webLibSrc,
624
- toDir: path7.join(cwd, cfg.libDir),
625
- overwrite
626
- });
890
+ const repoPaths = {
891
+ web: {
892
+ lib: path7.join(workspaceRoot, "app/lib"),
893
+ composables: path7.join(workspaceRoot, "app/composables")
894
+ },
895
+ uniapp: {
896
+ lib: path7.join(workspaceRoot, "packages/uniapp-project/src/lib"),
897
+ composables: path7.join(workspaceRoot, "packages/uniapp-project/src/composables")
627
898
  }
628
- if (await pathExists(webComposablesSrc)) {
629
- await copyDirRecursive({
630
- fromDir: webComposablesSrc,
631
- toDir: path7.join(cwd, cfg.composablesDir),
632
- overwrite,
633
- ignoreFileNames: /* @__PURE__ */ new Set(["useComponentCode.ts", "useCopyToClipboard.ts"])
634
- });
899
+ };
900
+ const currentRepoPaths = repoPaths[platform];
901
+ let copiedFromRepo = false;
902
+ if (await pathExists(currentRepoPaths.lib)) {
903
+ await copyDirRecursive({
904
+ fromDir: currentRepoPaths.lib,
905
+ toDir: path7.join(cwd, cfg.libDir),
906
+ overwrite
907
+ });
908
+ copiedFromRepo = true;
909
+ }
910
+ if (await pathExists(currentRepoPaths.composables)) {
911
+ await copyDirRecursive({
912
+ fromDir: currentRepoPaths.composables,
913
+ toDir: path7.join(cwd, cfg.composablesDir),
914
+ overwrite,
915
+ ignoreFileNames: platform === "web" ? /* @__PURE__ */ new Set(["useComponentCode.ts", "useCopyToClipboard.ts", "getComponentCode.ts", "getUniappCode.ts"]) : void 0
916
+ });
917
+ copiedFromRepo = true;
918
+ }
919
+ if (!copiedFromRepo) {
920
+ const platformTemplates = TEMPLATES[platform];
921
+ for (const [relPath, content] of Object.entries(platformTemplates)) {
922
+ let targetPath = "";
923
+ if (relPath.startsWith("lib/")) {
924
+ targetPath = path7.join(cwd, cfg.libDir, relPath.replace("lib/", ""));
925
+ } else if (relPath.startsWith("composables/")) {
926
+ targetPath = path7.join(cwd, cfg.composablesDir, relPath.replace("composables/", ""));
927
+ }
928
+ if (targetPath) {
929
+ if (!overwrite && await pathExists(targetPath)) continue;
930
+ await writeTextFile(targetPath, content);
931
+ }
635
932
  }
636
933
  }
637
934
  }
@@ -790,7 +1087,7 @@ function initCommand() {
790
1087
  // package.json
791
1088
  var package_default = {
792
1089
  name: "reborn-ui",
793
- version: "0.1.69",
1090
+ version: "0.1.73",
794
1091
  description: "A CLI for Reborn UI",
795
1092
  author: "1997liuyh-boop",
796
1093
  license: "MIT",
@@ -816,9 +1113,10 @@ var package_default = {
816
1113
  dev: "tsx src/index.ts",
817
1114
  clean: "rimraf dist",
818
1115
  prepare: "tsup",
1116
+ "templates:sync": "tsx src/scripts/sync-templates.ts",
819
1117
  "registry:build": "tsx src/index.ts build --root ../.. --uniapp-source packages/uniapp-project/src/components",
820
- prepack: "npm run build && npm run registry:build",
821
- prepublishOnly: "npm run build && npm run registry:build"
1118
+ prepack: "npm run templates:sync && npm run build && npm run registry:build",
1119
+ prepublishOnly: "npm run templates:sync && npm run build && npm run registry:build"
822
1120
  },
823
1121
  dependencies: {
824
1122
  chalk: "^5.6.2",