@nocobase/plugin-china-region
Advanced tools
Comparing version 0.13.0-alpha.4 to 0.13.0-alpha.5
@@ -1,78 +0,1 @@ | ||
(function(global, factory) { | ||
typeof exports === "object" && typeof module !== "undefined" ? factory(exports, require("@nocobase/client"), require("@formily/react")) : typeof define === "function" && define.amd ? define(["exports", "@nocobase/client", "@formily/react"], factory) : (global = typeof globalThis !== "undefined" ? globalThis : global || self, factory(global["@nocobase/plugin-china-region"] = {}, global["@nocobase/client"], global["@formily/react"])); | ||
})(this, function(exports2, client, react) { | ||
"use strict"; | ||
const useChinaRegionDataSource = (options) => { | ||
const field = react.useField(); | ||
const maxLevel = field.componentProps.maxLevel; | ||
return client.useRequest( | ||
{ | ||
resource: "chinaRegions", | ||
action: "list", | ||
params: { | ||
sort: "code", | ||
paginate: false, | ||
filter: { | ||
level: 1 | ||
} | ||
} | ||
}, | ||
{ | ||
...options, | ||
onSuccess(data) { | ||
var _a; | ||
options == null ? void 0 : options.onSuccess({ | ||
data: ((_a = data == null ? void 0 : data.data) == null ? void 0 : _a.map((item) => { | ||
if (maxLevel !== 1) { | ||
item.isLeaf = false; | ||
} | ||
return item; | ||
})) || [] | ||
}); | ||
}, | ||
manual: true | ||
} | ||
); | ||
}; | ||
const useChinaRegionLoadData = () => { | ||
const api = client.useAPIClient(); | ||
const field = react.useField(); | ||
const maxLevel = field.componentProps.maxLevel; | ||
return (selectedOptions) => { | ||
var _a; | ||
const targetOption = selectedOptions[selectedOptions.length - 1]; | ||
if (((_a = targetOption == null ? void 0 : targetOption.children) == null ? void 0 : _a.length) > 0) { | ||
return; | ||
} | ||
targetOption.loading = true; | ||
api.resource("chinaRegions").list({ | ||
sort: "code", | ||
paginate: false, | ||
filter: { | ||
parentCode: targetOption.code | ||
} | ||
}).then(({ data }) => { | ||
var _a2; | ||
targetOption.loading = false; | ||
targetOption.children = ((_a2 = data == null ? void 0 : data.data) == null ? void 0 : _a2.map((item) => { | ||
if (maxLevel > item.level) { | ||
item.isLeaf = false; | ||
} | ||
return item; | ||
})) || []; | ||
field.dataSource = [...field.dataSource]; | ||
}); | ||
}; | ||
}; | ||
class ChinaRegionPlugin extends client.Plugin { | ||
async load() { | ||
this.app.addScopes({ | ||
useChinaRegionDataSource, | ||
useChinaRegionLoadData | ||
}); | ||
} | ||
} | ||
exports2.ChinaRegionPlugin = ChinaRegionPlugin; | ||
exports2.default = ChinaRegionPlugin; | ||
Object.defineProperties(exports2, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } }); | ||
}); | ||
(function(n,e){typeof exports=="object"&&typeof module!="undefined"?e(exports,require("@nocobase/client"),require("@formily/react")):typeof define=="function"&&define.amd?define(["exports","@nocobase/client","@formily/react"],e):(n=typeof globalThis!="undefined"?globalThis:n||self,e(n["@nocobase/plugin-china-region"]={},n["@nocobase/client"],n["@formily/react"]))})(this,function(n,e,i){"use strict";var L=Object.defineProperty,P=Object.defineProperties;var R=Object.getOwnPropertyDescriptors;var p=Object.getOwnPropertySymbols;var x=Object.prototype.hasOwnProperty,C=Object.prototype.propertyIsEnumerable;var m=(n,e,i)=>e in n?L(n,e,{enumerable:!0,configurable:!0,writable:!0,value:i}):n[e]=i,v=(n,e)=>{for(var i in e||(e={}))x.call(e,i)&&m(n,i,e[i]);if(p)for(var i of p(e))C.call(e,i)&&m(n,i,e[i]);return n},S=(n,e)=>P(n,R(e));var y=(n,e,i)=>new Promise((f,u)=>{var t=o=>{try{r(i.next(o))}catch(s){u(s)}},l=o=>{try{r(i.throw(o))}catch(s){u(s)}},r=o=>o.done?f(o.value):Promise.resolve(o.value).then(t,l);r((i=i.apply(n,e)).next())});const f=l=>{const o=i.useField().componentProps.maxLevel;return e.useRequest({resource:"chinaRegions",action:"list",params:{sort:"code",paginate:!1,filter:{level:1}}},S(v({},l),{onSuccess(s){var a;l==null||l.onSuccess({data:((a=s==null?void 0:s.data)==null?void 0:a.map(c=>(o!==1&&(c.isLeaf=!1),c)))||[]})},manual:!0}))},u=()=>{const l=e.useAPIClient(),r=i.useField(),o=r.componentProps.maxLevel;return s=>{var c;const a=s[s.length-1];((c=a==null?void 0:a.children)==null?void 0:c.length)>0||(a.loading=!0,l.resource("chinaRegions").list({sort:"code",paginate:!1,filter:{parentCode:a.code}}).then(({data:d})=>{var h;a.loading=!1,a.children=((h=d==null?void 0:d.data)==null?void 0:h.map(g=>(o>g.level&&(g.isLeaf=!1),g)))||[],r.dataSource=[...r.dataSource]}))}};class t extends e.Plugin{load(){return y(this,null,function*(){this.app.addScopes({useChinaRegionDataSource:f,useChinaRegionLoadData:u})})}}n.ChinaRegionPlugin=t,n.default=t,Object.defineProperties(n,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})}); |
@@ -1,18 +0,39 @@ | ||
'use strict'; | ||
Object.defineProperty(exports, '__esModule', { value: true }); | ||
var server = require('./server'); | ||
Object.defineProperty(exports, 'default', { | ||
enumerable: true, | ||
get: function () { return server__namespace.default; } | ||
var __create = Object.create; | ||
var __defProp = Object.defineProperty; | ||
var __getOwnPropDesc = Object.getOwnPropertyDescriptor; | ||
var __getOwnPropNames = Object.getOwnPropertyNames; | ||
var __getProtoOf = Object.getPrototypeOf; | ||
var __hasOwnProp = Object.prototype.hasOwnProperty; | ||
var __export = (target, all) => { | ||
for (var name in all) | ||
__defProp(target, name, { get: all[name], enumerable: true }); | ||
}; | ||
var __copyProps = (to, from, except, desc) => { | ||
if (from && typeof from === "object" || typeof from === "function") { | ||
for (let key of __getOwnPropNames(from)) | ||
if (!__hasOwnProp.call(to, key) && key !== except) | ||
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); | ||
} | ||
return to; | ||
}; | ||
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default")); | ||
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps( | ||
// If the importer is in node compatibility mode or this is not an ESM | ||
// file that has been converted to a CommonJS file using a Babel- | ||
// compatible transform (i.e. "__esModule" has not been set), then set | ||
// "default" to the CommonJS "module.exports" for node compatibility. | ||
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, | ||
mod | ||
)); | ||
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); | ||
var src_exports = {}; | ||
__export(src_exports, { | ||
default: () => import_server.default | ||
}); | ||
Object.keys(server).forEach(function (k) { | ||
if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, { | ||
enumerable: true, | ||
get: function () { return server[k]; } | ||
}); | ||
module.exports = __toCommonJS(src_exports); | ||
__reExport(src_exports, require("./server"), module.exports); | ||
var import_server = __toESM(require("./server")); | ||
// Annotate the CommonJS export names for ESM import in node: | ||
0 && (module.exports = { | ||
...require("./server") | ||
}); |
@@ -1,6 +0,25 @@ | ||
'use strict'; | ||
var database = require('@nocobase/database'); | ||
var chinaRegions_default = database.defineCollection({ | ||
var __defProp = Object.defineProperty; | ||
var __getOwnPropDesc = Object.getOwnPropertyDescriptor; | ||
var __getOwnPropNames = Object.getOwnPropertyNames; | ||
var __hasOwnProp = Object.prototype.hasOwnProperty; | ||
var __export = (target, all) => { | ||
for (var name in all) | ||
__defProp(target, name, { get: all[name], enumerable: true }); | ||
}; | ||
var __copyProps = (to, from, except, desc) => { | ||
if (from && typeof from === "object" || typeof from === "function") { | ||
for (let key of __getOwnPropNames(from)) | ||
if (!__hasOwnProp.call(to, key) && key !== except) | ||
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); | ||
} | ||
return to; | ||
}; | ||
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); | ||
var chinaRegions_exports = {}; | ||
__export(chinaRegions_exports, { | ||
default: () => chinaRegions_default | ||
}); | ||
module.exports = __toCommonJS(chinaRegions_exports); | ||
var import_database = require("@nocobase/database"); | ||
var chinaRegions_default = (0, import_database.defineCollection)({ | ||
namespace: "china-region.china-region", | ||
@@ -43,3 +62,1 @@ duplicator: "skip", | ||
}); | ||
module.exports = chinaRegions_default; |
@@ -1,8 +0,26 @@ | ||
'use strict'; | ||
Object.defineProperty(exports, '__esModule', { value: true }); | ||
var server = require('@nocobase/server'); | ||
var path = require('path'); | ||
var __defProp = Object.defineProperty; | ||
var __getOwnPropDesc = Object.getOwnPropertyDescriptor; | ||
var __getOwnPropNames = Object.getOwnPropertyNames; | ||
var __hasOwnProp = Object.prototype.hasOwnProperty; | ||
var __export = (target, all) => { | ||
for (var name in all) | ||
__defProp(target, name, { get: all[name], enumerable: true }); | ||
}; | ||
var __copyProps = (to, from, except, desc) => { | ||
if (from && typeof from === "object" || typeof from === "function") { | ||
for (let key of __getOwnPropNames(from)) | ||
if (!__hasOwnProp.call(to, key) && key !== except) | ||
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); | ||
} | ||
return to; | ||
}; | ||
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); | ||
var server_exports = {}; | ||
__export(server_exports, { | ||
PluginChinaRegion: () => PluginChinaRegion, | ||
default: () => server_default | ||
}); | ||
module.exports = __toCommonJS(server_exports); | ||
var import_server = require("@nocobase/server"); | ||
var import_path = require("path"); | ||
function getChinaDivisionData(key) { | ||
@@ -16,3 +34,3 @@ try { | ||
} | ||
class PluginChinaRegion extends server.Plugin { | ||
class PluginChinaRegion extends import_server.Plugin { | ||
async install() { | ||
@@ -23,3 +41,3 @@ await this.importData(); | ||
await this.db.import({ | ||
directory: path.resolve(__dirname, "collections") | ||
directory: (0, import_path.resolve)(__dirname, "collections") | ||
}); | ||
@@ -40,2 +58,3 @@ this.app.acl.allow("chinaRegions", "list", "loggedIn"); | ||
const provinces = getChinaDivisionData("provinces"); | ||
const timer = Date.now(); | ||
const ChinaRegion = this.db.getModel("chinaRegions"); | ||
@@ -65,8 +84,9 @@ await ChinaRegion.bulkCreate( | ||
); | ||
await ChinaRegion.count(); | ||
const count = await ChinaRegion.count(); | ||
} | ||
} | ||
var server_default = PluginChinaRegion; | ||
exports.PluginChinaRegion = PluginChinaRegion; | ||
exports.default = server_default; | ||
// Annotate the CommonJS export names for ESM import in node: | ||
0 && (module.exports = { | ||
PluginChinaRegion | ||
}); |
{ | ||
"name": "@nocobase/plugin-china-region", | ||
"version": "0.13.0-alpha.4", | ||
"version": "0.13.0-alpha.5", | ||
"displayName": "China region", | ||
@@ -23,3 +23,3 @@ "displayName.zh-CN": "中国行政区", | ||
}, | ||
"gitHead": "29594e9dbb2455e2f3f6bea95340c4ed75789b61" | ||
"gitHead": "9eabe607b4a20c356fdb2fd95e40fa476986dcb0" | ||
} |
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 1 instance in 1 package
296643
307
3