Explorar el Código

Bugfix: Documantation implementation wrong infos fixed.

lfabl hace 2 semanas
padre
commit
dc95993e3e

+ 35 - 19
example/src/pages/coreFeatures/toolsUsage/index.tsx

@@ -53,35 +53,48 @@ const ToolsUsage = () => {
         localize
     ]);
 
-    const codeTheme = `import { NCoreUIKitTheme } from "ncore-ui-kit";
+    const codeTheme = `import {
+    NCoreUIKitTheme
+} from "ncore-ui-kit";
 
 const MyComponent = () => {
-    // Access current theme colors, spaces, and active preferences
+    // ${localize("toolsUsage-codeThemeComment")}
     const {
-        colors,
-    spaces,
+        activePalette,
         activeTheme,
-    activePalette
+        spaces,
+        colors
     } = NCoreUIKitTheme.useContext();
 
     return (
-        <View style={[
+        <View
+            style={[
                 stylesheet.borderedCard,
-                { backgroundColor: colors.content.container.default, padding: spaces.spacingMd
+                {
+                    backgroundColor: colors.content.container.default, padding: spaces.spacingMd
                 }
-            ]}>
-            <Text style={{ color: colors.content.text.high }}>Current Theme: {activeTheme}</Text>
+            ]}
+        >
+            <Text
+                style={{
+                    color: colors.content.text.high
+                }}
+            >
+                Current Theme: {activeTheme}
+            </Text>
         </View>
     );
 };`;
 
-    const codeLocale = `import { NCoreUIKitLocalize } from "ncore-ui-kit";
+    const codeLocale = `import {
+    NCoreUIKitLocalize
+} from "ncore-ui-kit";
 
 const MyComponent = () => {
-    // Access current localization translations and active language
+    // ${localize("toolsUsage-codeLocaleComment")}
     const {
-        localize,
-    activeLocale
+        activeLocale,
+        localize
     } = NCoreUIKitLocalize.useContext();
 
     return (
@@ -91,13 +104,13 @@ const MyComponent = () => {
     );
 };`;
 
-    const codeToast = `import { NCoreUIKitToast } from "ncore-ui-kit";
+    const codeToast = `import {
+    NCoreUIKitToast
+} from "ncore-ui-kit";
 
 const MyComponent = () => {
-    const { showToast } = NCoreUIKitToast.useContext();
-
     const handlePress = () => {
-        showToast({
+        NCoreUIKitToast.open({
             title: "Success",
             content: "Action completed successfully!",
             variant: "success",
@@ -105,7 +118,10 @@ const MyComponent = () => {
         });
     };
 
-    return <Button title="Show Toast" onPress={handlePress} />;
+    return <Button
+        onPress={handlePress}
+        title="Show Toast"
+    />;
 };`;
 
     return <PageContainer
@@ -187,7 +203,7 @@ const MyComponent = () => {
                 marginTop: spaces.spacingXl
             }}
         >
-            NCoreUIKitToast.useContext
+            NCoreUIKitToast.open
         </Text>
         <Text
             color="mid"

+ 35 - 19
example/src/pages/coreFeatures/typesOverride/index.tsx

@@ -26,27 +26,43 @@ import {
     ChevronRightIcon
 } from "lucide-react-native";
 
-const codeGlobalDts = `import "ncore-ui-kit";
-
-// Kendi projenizin kök dizinine global.d.ts oluşturun.
-// Ardından NCoreUIKit tiplerini extend edin.
-declare module "ncore-ui-kit" {
-    export namespace NCoreUIKit {
-        export type ThemeKey = "dark" | "light";
-        export type PaletteKey = "default" | "red" | "green";
-        export type LocalesKey = "tr-TR" | "en-US";
-
-        export interface ThemeColors {
-            // Theme colors override here if needed
-            myCustomColor: string;
+const codeGlobalDts = `import defaultLocaleJSON from "./variants/locales/default.json";
+import defaultThemeJSON from "./variants/themes/default.json";
+
+declare global {
+    namespace NCoreUIKit {
+        type PaletteNames = "gmcore";
+
+        interface PaletteKey extends Record<PaletteType, unknown>, Record<PaletteNames, unknown> {
+        }
+
+        type ProjectLocalizationL = typeof defaultLocaleJSON[0];
+
+        type GeneratedProjectTranslations = {
+            [K in keyof ProjectLocalizationL["translations"]]: ProjectLocalizationL["translations"][K];
+        };
+
+        interface Translation extends GeneratedTranslations, GeneratedProjectTranslations {
+        }
+
+        type DefaultPaletteL = typeof defaultThemeJSON.palettes[0];
+
+        type ProjectDataL = DefaultPaletteL["themes"]["dark"]["project"];
+        type DefaultProjectColorsL = ProjectDataL;
+
+        interface ProjectColorPalette extends DefaultProjectColors, DefaultProjectColorsL {
         }
 
-        export interface LanguageObject {
-            translations: {
-                "welcome-msg": string;
-                "submit-btn": string;
-                // Add your project's custom keys here
-            }
+        type SystemDataL = DefaultPaletteL["themes"]["dark"]["system"];
+        type DefaultSystemColorsL = SystemDataL;
+
+        interface SystemColorPalette extends DefaultSystemColors, DefaultSystemColorsL {
+        }
+
+        type ContentDataL = DefaultPaletteL["themes"]["dark"]["content"];
+        type DefaultContentColorsL = ContentDataL;
+
+        interface ContentColorPalette extends DefaultContentColors, DefaultContentColorsL {
         }
     }
 }`;

+ 1 - 1
example/src/pages/installation/index.tsx

@@ -117,7 +117,7 @@ const Installation = () => {
                     {localize("installation-peerDepsDesc")}
                 </Text>
                 <CodeViewer
-                    code="yarn add @react-native-clipboard/clipboard lucide-react-native moment ncore-context react-native-safe-area-context react-native-svg rrule"
+                    code="yarn add @react-native-clipboard/clipboard lucide-react-native moment@https://git.nibgat.space/nibgat-community/moment.git ncore-context react-native-safe-area-context react-native-svg rrule@https://git.nibgat.space/nibgat-community/rrule.git"
                     language="bash"
                 />
             </View>

+ 6 - 2
example/src/variants/locales/default.json

@@ -360,7 +360,9 @@
             "close": "Kapat",
             "right": "Sağ",
             "chip": "Çip",
-            "left": "Sol"
+            "left": "Sol",
+            "toolsUsage-codeThemeComment": "Mevcut tema renklerine, boşluklarına ve aktif tercihlere erişin",
+            "toolsUsage-codeLocaleComment": "Mevcut çevirilere ve aktif dile erişin"
         },
         "locale": "tr-TR",
         "isRTL": false
@@ -726,7 +728,9 @@
             "chip": "Chip",
             "left": "Left",
             "next": "Next",
-            "text": "Text"
+            "text": "Text",
+            "toolsUsage-codeThemeComment": "Access current theme colors, spaces, and active preferences",
+            "toolsUsage-codeLocaleComment": "Access current localization translations and active language"
         },
         "locale": "en-US",
         "isRTL": false

+ 5 - 2
src/components/codeViewer/index.tsx

@@ -55,7 +55,7 @@ const CodeViewer = ({
 
     const timeoutRef = useRef<NodeJS.Timeout | null>(null);
 
-    const containerRef = useRef<import("react").ElementRef<typeof View>>(null);
+    const containerRef = useRef<import("react").ComponentRef<typeof View>>(null);
 
     const [
         stickyTop,
@@ -133,7 +133,10 @@ const CodeViewer = ({
     const handleCopyCode = async () => {
         if (isCopied) return;
 
-        const replacedCode = code.replace(/\/\*[\s\S]*?\*\/|\/\/.*/g, "");
+        const replacedCode = tokens
+            .filter(token => token.type !== "comment")
+            .map(token => token.value)
+            .join("");
 
         let isSuccess = false;
 

+ 33 - 3
src/components/codeViewer/parser.ts

@@ -555,12 +555,42 @@ const getTokenRegex = (language?: string): RegExp => {
         }
     }
 
-    const keywordsRegexStr = "\\b(?:" + keywordList.join("|") + ")\\b";
+    const keywordsRegexStr = "(?<!\\.)\\b(?:" + keywordList.join("|") + ")\\b";
 
-    const keywordControlRegexStr = "\\b(?:return|if|else|for|while|try|catch|finally|switch|case|break|continue|throw|yield)\\b";
+    const keywordControlRegexStr = "(?<!\\.)\\b(?:return|if|else|for|while|try|catch|finally|switch|case|break|continue|throw|yield)\\b";
 
-    const regexStr = "(?<comment>//.*|/\\*[\\s\\S]*?\\*/|#.*|<!--[\\s\\S]*?-->)|" +
+    let commentRegexStr = "//.*|/\\*[\\s\\S]*?\\*/|#.*|<!--[\\s\\S]*?-->";
+    if (language) {
+        switch (language.toLowerCase()) {
+            case "bash":
+            case "python":
+                commentRegexStr = "#.*";
+                break;
+            case "sql":
+                commentRegexStr = "--.*|/\\*[\\s\\S]*?\\*/";
+                break;
+            case "html":
+            case "xml":
+                commentRegexStr = "<!--[\\s\\S]*?-->";
+                break;
+            case "javascript":
+            case "typescript":
+            case "jsx":
+            case "tsx":
+            case "csharp":
+                commentRegexStr = "//.*|/\\*[\\s\\S]*?\\*/";
+                break;
+        }
+    }
+
+    let bashTextRegexStr = "";
+    if (language && language.toLowerCase() === "bash") {
+        bashTextRegexStr = "(?<text>(?:[a-zA-Z0-9_@]+[.:/-]+)+[a-zA-Z0-9_@]+)|";
+    }
+
+    const regexStr = "(?<comment>" + commentRegexStr + ")|" +
         '(?<string>(["\\\'`])(?:(?=(\\\\?))\\4.)*?\\3)|' +
+        bashTextRegexStr +
         "(?<keywordControl>" + keywordControlRegexStr + ")|" +
         "(?<keyword>" + keywordsRegexStr + ")|" +
         "(?<htmlTag>(?<=<\\/?)[a-z][a-zA-Z0-9-]*\\b)|" +