xctc-utils 1.0.1 → 1.0.2
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/dist/index.d.ts +9 -2
- package/dist/index.js +16 -8
- package/dist/storage/index.d.ts +4 -0
- package/dist/storage/index.js +52 -0
- package/dist/types.d.ts +4 -0
- package/dist/types.js +2 -0
- package/dist/utils.d.ts +5 -0
- package/dist/utils.js +69 -0
- package/package.json +1 -1
    
        package/dist/index.d.ts
    CHANGED
    
    | @@ -1,5 +1,12 @@ | |
| 1 | 
            -
            export declare function add(a: number, b: number): number;
         | 
| 2 1 | 
             
            declare const obj: {
         | 
| 3 | 
            -
                 | 
| 2 | 
            +
                isJson(str: string): any;
         | 
| 3 | 
            +
                $id(id: string): false | HTMLElement;
         | 
| 4 | 
            +
                checkIframeContentHeight(option: import("./types").UeditorHeightOption): string;
         | 
| 5 | 
            +
                getIframeContentHeight(id: string): any;
         | 
| 6 | 
            +
                useLocalStorage(key: string, value: any): false | undefined;
         | 
| 7 | 
            +
                getLocalStorage(key: string): any;
         | 
| 8 | 
            +
                useSessionStorage(key: string, value: any): false | undefined;
         | 
| 9 | 
            +
                getSessionStorage(key: string): any;
         | 
| 4 10 | 
             
            };
         | 
| 11 | 
            +
            export { obj };
         | 
| 5 12 | 
             
            export default obj;
         | 
    
        package/dist/index.js
    CHANGED
    
    | @@ -1,11 +1,19 @@ | |
| 1 1 | 
             
            "use strict";
         | 
| 2 | 
            -
             | 
| 3 | 
            -
             | 
| 4 | 
            -
             | 
| 5 | 
            -
             | 
| 6 | 
            -
             | 
| 7 | 
            -
             | 
| 8 | 
            -
             | 
| 9 | 
            -
             | 
| 2 | 
            +
            var __assign = (this && this.__assign) || function () {
         | 
| 3 | 
            +
                __assign = Object.assign || function(t) {
         | 
| 4 | 
            +
                    for (var s, i = 1, n = arguments.length; i < n; i++) {
         | 
| 5 | 
            +
                        s = arguments[i];
         | 
| 6 | 
            +
                        for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
         | 
| 7 | 
            +
                            t[p] = s[p];
         | 
| 8 | 
            +
                    }
         | 
| 9 | 
            +
                    return t;
         | 
| 10 | 
            +
                };
         | 
| 11 | 
            +
                return __assign.apply(this, arguments);
         | 
| 10 12 | 
             
            };
         | 
| 13 | 
            +
            Object.defineProperty(exports, "__esModule", { value: true });
         | 
| 14 | 
            +
            exports.obj = void 0;
         | 
| 15 | 
            +
            var storage = require("./storage/index");
         | 
| 16 | 
            +
            var utils = require("./utils");
         | 
| 17 | 
            +
            var obj = __assign(__assign({}, storage), utils);
         | 
| 18 | 
            +
            exports.obj = obj;
         | 
| 11 19 | 
             
            exports.default = obj;
         | 
| @@ -0,0 +1,4 @@ | |
| 1 | 
            +
            export declare function useLocalStorage(key: string, value: any): false | undefined;
         | 
| 2 | 
            +
            export declare function getLocalStorage(key: string): any;
         | 
| 3 | 
            +
            export declare function useSessionStorage(key: string, value: any): false | undefined;
         | 
| 4 | 
            +
            export declare function getSessionStorage(key: string): any;
         | 
| @@ -0,0 +1,52 @@ | |
| 1 | 
            +
            "use strict";
         | 
| 2 | 
            +
            Object.defineProperty(exports, "__esModule", { value: true });
         | 
| 3 | 
            +
            exports.getSessionStorage = exports.useSessionStorage = exports.getLocalStorage = exports.useLocalStorage = void 0;
         | 
| 4 | 
            +
            var wls = window.localStorage;
         | 
| 5 | 
            +
            var wss = window.sessionStorage;
         | 
| 6 | 
            +
            var utils_1 = require("../utils");
         | 
| 7 | 
            +
            function useLocalStorage(key, value) {
         | 
| 8 | 
            +
                if (!key || !value) {
         | 
| 9 | 
            +
                    console.log("useLocalStorage存储时缺少key:value");
         | 
| 10 | 
            +
                    return false;
         | 
| 11 | 
            +
                }
         | 
| 12 | 
            +
                useStorage(key, value, wls);
         | 
| 13 | 
            +
            }
         | 
| 14 | 
            +
            exports.useLocalStorage = useLocalStorage;
         | 
| 15 | 
            +
            function getLocalStorage(key) {
         | 
| 16 | 
            +
                if (!key)
         | 
| 17 | 
            +
                    return;
         | 
| 18 | 
            +
                return getStorage(key, wls);
         | 
| 19 | 
            +
            }
         | 
| 20 | 
            +
            exports.getLocalStorage = getLocalStorage;
         | 
| 21 | 
            +
            function useSessionStorage(key, value) {
         | 
| 22 | 
            +
                if (!key || !value) {
         | 
| 23 | 
            +
                    console.log("useSessionStorage存储时缺少key:value");
         | 
| 24 | 
            +
                    return false;
         | 
| 25 | 
            +
                }
         | 
| 26 | 
            +
                useStorage(key, value, wss);
         | 
| 27 | 
            +
            }
         | 
| 28 | 
            +
            exports.useSessionStorage = useSessionStorage;
         | 
| 29 | 
            +
            function getSessionStorage(key) {
         | 
| 30 | 
            +
                if (!key)
         | 
| 31 | 
            +
                    return;
         | 
| 32 | 
            +
                return getStorage(key, wss);
         | 
| 33 | 
            +
            }
         | 
| 34 | 
            +
            exports.getSessionStorage = getSessionStorage;
         | 
| 35 | 
            +
            function useStorage(key, value, obj) {
         | 
| 36 | 
            +
                if (value instanceof Object) {
         | 
| 37 | 
            +
                    obj.setItem(key, JSON.stringify(value));
         | 
| 38 | 
            +
                }
         | 
| 39 | 
            +
                else {
         | 
| 40 | 
            +
                    obj.setItem(key, value);
         | 
| 41 | 
            +
                }
         | 
| 42 | 
            +
            }
         | 
| 43 | 
            +
            function getStorage(key, obj) {
         | 
| 44 | 
            +
                var val = obj.getItem(key);
         | 
| 45 | 
            +
                if (val == 'undefined' || val == null) {
         | 
| 46 | 
            +
                    return "";
         | 
| 47 | 
            +
                }
         | 
| 48 | 
            +
                var data = (0, utils_1.isJson)(val);
         | 
| 49 | 
            +
                if (data)
         | 
| 50 | 
            +
                    val = data;
         | 
| 51 | 
            +
                return val;
         | 
| 52 | 
            +
            }
         | 
    
        package/dist/types.d.ts
    ADDED
    
    
    
        package/dist/types.js
    ADDED
    
    
    
        package/dist/utils.d.ts
    ADDED
    
    | @@ -0,0 +1,5 @@ | |
| 1 | 
            +
            import { UeditorHeightOption } from "./types";
         | 
| 2 | 
            +
            export declare function isJson(str: string): any;
         | 
| 3 | 
            +
            export declare function $id(id: string): false | HTMLElement;
         | 
| 4 | 
            +
            export declare function checkIframeContentHeight(option: UeditorHeightOption): string;
         | 
| 5 | 
            +
            export declare function getIframeContentHeight(id: string): any;
         | 
    
        package/dist/utils.js
    ADDED
    
    | @@ -0,0 +1,69 @@ | |
| 1 | 
            +
            "use strict";
         | 
| 2 | 
            +
            Object.defineProperty(exports, "__esModule", { value: true });
         | 
| 3 | 
            +
            exports.getIframeContentHeight = exports.checkIframeContentHeight = exports.$id = exports.isJson = void 0;
         | 
| 4 | 
            +
            function isJson(str) {
         | 
| 5 | 
            +
                if (!str)
         | 
| 6 | 
            +
                    return false;
         | 
| 7 | 
            +
                try {
         | 
| 8 | 
            +
                    var obj = JSON.parse(str);
         | 
| 9 | 
            +
                    if (obj && typeof obj == "object") {
         | 
| 10 | 
            +
                        return obj;
         | 
| 11 | 
            +
                    }
         | 
| 12 | 
            +
                    else {
         | 
| 13 | 
            +
                        return false;
         | 
| 14 | 
            +
                    }
         | 
| 15 | 
            +
                }
         | 
| 16 | 
            +
                catch (e) {
         | 
| 17 | 
            +
                    return false;
         | 
| 18 | 
            +
                }
         | 
| 19 | 
            +
            }
         | 
| 20 | 
            +
            exports.isJson = isJson;
         | 
| 21 | 
            +
            // 通过ID获取DOM元素
         | 
| 22 | 
            +
            function $id(id) {
         | 
| 23 | 
            +
                if (!id)
         | 
| 24 | 
            +
                    return false;
         | 
| 25 | 
            +
                var dom = document.getElementById(id);
         | 
| 26 | 
            +
                if (id && dom instanceof HTMLElement) {
         | 
| 27 | 
            +
                    return dom;
         | 
| 28 | 
            +
                }
         | 
| 29 | 
            +
                return false;
         | 
| 30 | 
            +
            }
         | 
| 31 | 
            +
            exports.$id = $id;
         | 
| 32 | 
            +
            // 设置当前富文本内容高度
         | 
| 33 | 
            +
            function checkIframeContentHeight(option) {
         | 
| 34 | 
            +
                var _a = option.id, id = _a === void 0 ? "ueditor_0" : _a, _b = option.content, content = _b === void 0 ? "" : _b;
         | 
| 35 | 
            +
                var ifm = $id(id); // 当前富文本id获取到iframe
         | 
| 36 | 
            +
                var subWeb = { body: "" };
         | 
| 37 | 
            +
                var tags = document.body.getElementsByTagName("iframe");
         | 
| 38 | 
            +
                if (tags && tags[0]) {
         | 
| 39 | 
            +
                    subWeb = tags[0]['contentDocument'];
         | 
| 40 | 
            +
                }
         | 
| 41 | 
            +
                else {
         | 
| 42 | 
            +
                    if (ifm && ifm.contentDocument)
         | 
| 43 | 
            +
                        subWeb = ifm.contentDocument;
         | 
| 44 | 
            +
                }
         | 
| 45 | 
            +
                if (subWeb && subWeb.body) {
         | 
| 46 | 
            +
                    var ifmBody = subWeb.body;
         | 
| 47 | 
            +
                    var last = ifmBody.lastElementChild;
         | 
| 48 | 
            +
                    var height = 0;
         | 
| 49 | 
            +
                    if (last) {
         | 
| 50 | 
            +
                        height = last.offsetTop;
         | 
| 51 | 
            +
                    }
         | 
| 52 | 
            +
                    return "<input type=\"hidden\" content-data-height=\"".concat(height, "\" id=\"ueditorHeight\" />").concat(content);
         | 
| 53 | 
            +
                }
         | 
| 54 | 
            +
                return content;
         | 
| 55 | 
            +
            }
         | 
| 56 | 
            +
            exports.checkIframeContentHeight = checkIframeContentHeight;
         | 
| 57 | 
            +
            // 获取到当前dom容器内所有内容的高度
         | 
| 58 | 
            +
            function getIframeContentHeight(id) {
         | 
| 59 | 
            +
                if (!id) {
         | 
| 60 | 
            +
                    id = "ueditorHeight";
         | 
| 61 | 
            +
                }
         | 
| 62 | 
            +
                var dom = $id(id);
         | 
| 63 | 
            +
                if (dom) {
         | 
| 64 | 
            +
                    var height = dom.getAttribute("content-data-height");
         | 
| 65 | 
            +
                    return height;
         | 
| 66 | 
            +
                }
         | 
| 67 | 
            +
                return 0;
         | 
| 68 | 
            +
            }
         | 
| 69 | 
            +
            exports.getIframeContentHeight = getIframeContentHeight;
         |