@idooel/components 0.0.2-beta.11 → 0.0.2-beta.12

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.
@@ -1,7 +1,7 @@
1
1
  import { parse as parse$1 } from '@idooel/expression';
2
2
  import moment from 'moment';
3
3
  import { type, net, route, util } from '@idooel/shared';
4
- import 'vue';
4
+ import { createDataPool } from '@idooel/runtime-context';
5
5
  import FileUpload from 'vue-upload-component';
6
6
 
7
7
  const CONTEXT = '__idooel__ele__context__';
@@ -1840,236 +1840,6 @@ __vue_render__$B._withStripped = true;
1840
1840
 
1841
1841
  __vue_component__$B.install = Vue => Vue.component(__vue_component__$B.name, __vue_component__$B);
1842
1842
 
1843
- const DEFAULT_NAMESPACE_PREFIX = "idooel";
1844
- class Context {
1845
- constructor(init) {
1846
- this.id = generateId();
1847
- this.store = /* @__PURE__ */new Map();
1848
- if (init) {
1849
- for (const ns of Object.keys(init)) {
1850
- const nsMap = /* @__PURE__ */new Map();
1851
- const obj = init[ns];
1852
- if (obj && typeof obj === "object") {
1853
- for (const key of Object.keys(obj)) {
1854
- nsMap.set(key, obj[key]);
1855
- }
1856
- }
1857
- this.store.set(ns, nsMap);
1858
- }
1859
- }
1860
- }
1861
- }
1862
- function generateId() {
1863
- return `ctx_${Date.now().toString(36)}_${Math.random().toString(36).slice(2, 10)}`;
1864
- }
1865
- function matchesFilter(filter, ns, key) {
1866
- if (!filter) return true;
1867
- if (filter.ns && filter.ns !== ns) return false;
1868
- if (filter.key && filter.key !== key) return false;
1869
- return true;
1870
- }
1871
- class DataPool {
1872
- constructor() {
1873
- this.globalStore = /* @__PURE__ */new Map();
1874
- this.contextStack = [];
1875
- this.subscribers = /* @__PURE__ */new Set();
1876
- }
1877
- /**
1878
- * Add idooel prefix to namespace if not already present
1879
- */
1880
- prefixNamespace(ns) {
1881
- if (!ns && ns !== "") return `${DEFAULT_NAMESPACE_PREFIX}.undefined`;
1882
- return ns.startsWith(`${DEFAULT_NAMESPACE_PREFIX}.`) ? ns : `${DEFAULT_NAMESPACE_PREFIX}.${ns}`;
1883
- }
1884
- currentContext() {
1885
- return this.contextStack.length ? this.contextStack[this.contextStack.length - 1] : null;
1886
- }
1887
- ensureNsMap(target, ns) {
1888
- let nsMap = target.get(ns);
1889
- if (!nsMap) {
1890
- nsMap = /* @__PURE__ */new Map();
1891
- target.set(ns, nsMap);
1892
- }
1893
- return nsMap;
1894
- }
1895
- notify(event) {
1896
- for (const sub of this.subscribers) {
1897
- if (matchesFilter(sub.filter, event.ns, event.key)) {
1898
- try {
1899
- sub.fn(event);
1900
- } catch {}
1901
- }
1902
- }
1903
- }
1904
- get(ns, key, fallback) {
1905
- const prefixedNs = this.prefixNamespace(ns);
1906
- const actualKey = !key && key !== "" ? "undefined" : key;
1907
- for (let i = this.contextStack.length - 1; i >= 0; i--) {
1908
- const ctx = this.contextStack[i];
1909
- const nsMap = ctx.store.get(prefixedNs);
1910
- if (nsMap && nsMap.has(actualKey)) return nsMap.get(actualKey);
1911
- }
1912
- const globalNs = this.globalStore.get(prefixedNs);
1913
- if (globalNs && globalNs.has(actualKey)) return globalNs.get(actualKey);
1914
- return fallback;
1915
- }
1916
- set(ns, key, value, options) {
1917
- const prefixedNs = this.prefixNamespace(ns);
1918
- const actualKey = !key && key !== "" ? "undefined" : key;
1919
- const targetStore = options?.target === "global" || !this.currentContext() ? this.globalStore : this.currentContext().store;
1920
- const nsMap = this.ensureNsMap(targetStore, prefixedNs);
1921
- nsMap.set(actualKey, value);
1922
- this.notify({
1923
- ns: prefixedNs,
1924
- key: actualKey,
1925
- value,
1926
- source: targetStore === this.globalStore ? "global" : "context",
1927
- contextId: this.currentContext()?.id ?? null
1928
- });
1929
- }
1930
- delete(ns, key) {
1931
- const prefixedNs = this.prefixNamespace(ns);
1932
- const actualKey = !key && key !== "" ? "undefined" : key;
1933
- let deleted = false;
1934
- for (let i = this.contextStack.length - 1; i >= 0; i--) {
1935
- const ctx = this.contextStack[i];
1936
- const nsMap = ctx.store.get(prefixedNs);
1937
- if (nsMap && nsMap.has(actualKey)) {
1938
- nsMap.delete(actualKey);
1939
- deleted = true;
1940
- break;
1941
- }
1942
- }
1943
- if (!deleted) {
1944
- const globalNs = this.globalStore.get(prefixedNs);
1945
- if (globalNs && globalNs.has(actualKey)) {
1946
- globalNs.delete(actualKey);
1947
- deleted = true;
1948
- }
1949
- }
1950
- if (deleted) {
1951
- this.notify({
1952
- ns: prefixedNs,
1953
- key: actualKey,
1954
- value: void 0,
1955
- source: "delete",
1956
- contextId: this.currentContext()?.id ?? null
1957
- });
1958
- }
1959
- }
1960
- clear(ns) {
1961
- const prefixedNs = ns ? this.prefixNamespace(ns) : void 0;
1962
- if (prefixedNs) {
1963
- this.globalStore.delete(prefixedNs);
1964
- for (const ctx of this.contextStack) {
1965
- ctx.store.delete(prefixedNs);
1966
- }
1967
- } else {
1968
- this.globalStore.clear();
1969
- for (const ctx of this.contextStack) {
1970
- ctx.store.clear();
1971
- }
1972
- }
1973
- this.notify({
1974
- ns: prefixedNs ?? "*",
1975
- key: "*",
1976
- value: void 0,
1977
- source: "clear",
1978
- contextId: this.currentContext()?.id ?? null
1979
- });
1980
- }
1981
- subscribe(filter, listener) {
1982
- const internalFilter = filter ? {
1983
- ns: filter.ns ? this.prefixNamespace(filter.ns) : void 0,
1984
- key: filter.key
1985
- } : void 0;
1986
- const sub = {
1987
- filter: internalFilter,
1988
- fn: event => {
1989
- const originalEvent = {
1990
- ...event,
1991
- ns: event.ns.replace(/^idooel\./, "")
1992
- };
1993
- listener(originalEvent);
1994
- }
1995
- };
1996
- this.subscribers.add(sub);
1997
- return () => {
1998
- this.subscribers.delete(sub);
1999
- };
2000
- }
2001
- createContext(init) {
2002
- const prefixedInit = init ? Object.fromEntries(Object.entries(init).map(([ns, data]) => [this.prefixNamespace(ns), data])) : void 0;
2003
- return new Context(prefixedInit);
2004
- }
2005
- enter(ctx) {
2006
- this.contextStack.push(ctx);
2007
- return {
2008
- token: Symbol(ctx.id)
2009
- };
2010
- }
2011
- exit(token) {
2012
- while (this.contextStack.length) {
2013
- const ctx = this.contextStack[this.contextStack.length - 1];
2014
- Symbol.for(ctx.id);
2015
- this.contextStack.pop();
2016
- if (token) break;
2017
- }
2018
- }
2019
- runInContext(initOrCtx, fn) {
2020
- const ctx = initOrCtx instanceof Context ? initOrCtx : this.createContext(initOrCtx);
2021
- const {
2022
- token
2023
- } = this.enter(ctx);
2024
- try {
2025
- return fn();
2026
- } finally {
2027
- this.exit({
2028
- token
2029
- });
2030
- }
2031
- }
2032
- withContext(initOrCtx) {
2033
- return fn => {
2034
- return (...args) => this.runInContext(initOrCtx, () => fn(...args));
2035
- };
2036
- }
2037
- wrapHandler(handler) {
2038
- const captured = this.currentContext();
2039
- if (!captured) return handler;
2040
- return (...args) => this.runInContext(captured, () => handler(...args));
2041
- }
2042
- snapshot(options) {
2043
- const merged = options?.merged !== false;
2044
- if (merged) {
2045
- const out = {};
2046
- for (const [ns, nsMap] of this.globalStore) {
2047
- out[ns] = Object.fromEntries(nsMap.entries());
2048
- }
2049
- for (const ctx of this.contextStack) {
2050
- for (const [ns, nsMap] of ctx.store) {
2051
- out[ns] = {
2052
- ...(out[ns] ?? {}),
2053
- ...Object.fromEntries(nsMap.entries())
2054
- };
2055
- }
2056
- }
2057
- return out;
2058
- } else {
2059
- return {
2060
- global: Object.fromEntries(Array.from(this.globalStore.entries()).map(([ns, nsMap]) => [ns, Object.fromEntries(nsMap.entries())])),
2061
- contexts: this.contextStack.map(ctx => ({
2062
- id: ctx.id,
2063
- data: Object.fromEntries(Array.from(ctx.store.entries()).map(([ns, nsMap]) => [ns, Object.fromEntries(nsMap.entries())]))
2064
- }))
2065
- };
2066
- }
2067
- }
2068
- }
2069
- function createDataPool() {
2070
- return new DataPool();
2071
- }
2072
-
2073
1843
  // 创建全局数据池实例
2074
1844
  const globalDataPool = createDataPool();
2075
1845
  const useGlobalDataPool = () => globalDataPool;
@@ -1,8 +1,8 @@
1
1
  (function (global, factory) {
2
- typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@idooel/expression'), require('moment'), require('@idooel/shared'), require('vue'), require('vue-upload-component')) :
3
- typeof define === 'function' && define.amd ? define(['exports', '@idooel/expression', 'moment', '@idooel/shared', 'vue', 'vue-upload-component'], factory) :
4
- (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.__ele__umd__components__ = {}, global["@idooel/expression"], global.moment, global["@idooel/shared"], global.Vue, global.FileUpload));
5
- })(this, (function (exports, expression, moment, shared, Vue, FileUpload) { 'use strict';
2
+ typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@idooel/expression'), require('moment'), require('@idooel/shared'), require('@idooel/runtime-context'), require('vue-upload-component')) :
3
+ typeof define === 'function' && define.amd ? define(['exports', '@idooel/expression', 'moment', '@idooel/shared', '@idooel/runtime-context', 'vue-upload-component'], factory) :
4
+ (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.__ele__umd__components__ = {}, global["@idooel/expression"], global.moment, global["@idooel/shared"], global["@idooel/runtime-context"], global.FileUpload));
5
+ })(this, (function (exports, expression, moment, shared, runtimeContext, FileUpload) { 'use strict';
6
6
 
7
7
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
8
8
 
@@ -1845,238 +1845,8 @@
1845
1845
 
1846
1846
  __vue_component__$B.install = Vue => Vue.component(__vue_component__$B.name, __vue_component__$B);
1847
1847
 
1848
- const DEFAULT_NAMESPACE_PREFIX = "idooel";
1849
- class Context {
1850
- constructor(init) {
1851
- this.id = generateId();
1852
- this.store = /* @__PURE__ */new Map();
1853
- if (init) {
1854
- for (const ns of Object.keys(init)) {
1855
- const nsMap = /* @__PURE__ */new Map();
1856
- const obj = init[ns];
1857
- if (obj && typeof obj === "object") {
1858
- for (const key of Object.keys(obj)) {
1859
- nsMap.set(key, obj[key]);
1860
- }
1861
- }
1862
- this.store.set(ns, nsMap);
1863
- }
1864
- }
1865
- }
1866
- }
1867
- function generateId() {
1868
- return `ctx_${Date.now().toString(36)}_${Math.random().toString(36).slice(2, 10)}`;
1869
- }
1870
- function matchesFilter(filter, ns, key) {
1871
- if (!filter) return true;
1872
- if (filter.ns && filter.ns !== ns) return false;
1873
- if (filter.key && filter.key !== key) return false;
1874
- return true;
1875
- }
1876
- class DataPool {
1877
- constructor() {
1878
- this.globalStore = /* @__PURE__ */new Map();
1879
- this.contextStack = [];
1880
- this.subscribers = /* @__PURE__ */new Set();
1881
- }
1882
- /**
1883
- * Add idooel prefix to namespace if not already present
1884
- */
1885
- prefixNamespace(ns) {
1886
- if (!ns && ns !== "") return `${DEFAULT_NAMESPACE_PREFIX}.undefined`;
1887
- return ns.startsWith(`${DEFAULT_NAMESPACE_PREFIX}.`) ? ns : `${DEFAULT_NAMESPACE_PREFIX}.${ns}`;
1888
- }
1889
- currentContext() {
1890
- return this.contextStack.length ? this.contextStack[this.contextStack.length - 1] : null;
1891
- }
1892
- ensureNsMap(target, ns) {
1893
- let nsMap = target.get(ns);
1894
- if (!nsMap) {
1895
- nsMap = /* @__PURE__ */new Map();
1896
- target.set(ns, nsMap);
1897
- }
1898
- return nsMap;
1899
- }
1900
- notify(event) {
1901
- for (const sub of this.subscribers) {
1902
- if (matchesFilter(sub.filter, event.ns, event.key)) {
1903
- try {
1904
- sub.fn(event);
1905
- } catch {}
1906
- }
1907
- }
1908
- }
1909
- get(ns, key, fallback) {
1910
- const prefixedNs = this.prefixNamespace(ns);
1911
- const actualKey = !key && key !== "" ? "undefined" : key;
1912
- for (let i = this.contextStack.length - 1; i >= 0; i--) {
1913
- const ctx = this.contextStack[i];
1914
- const nsMap = ctx.store.get(prefixedNs);
1915
- if (nsMap && nsMap.has(actualKey)) return nsMap.get(actualKey);
1916
- }
1917
- const globalNs = this.globalStore.get(prefixedNs);
1918
- if (globalNs && globalNs.has(actualKey)) return globalNs.get(actualKey);
1919
- return fallback;
1920
- }
1921
- set(ns, key, value, options) {
1922
- const prefixedNs = this.prefixNamespace(ns);
1923
- const actualKey = !key && key !== "" ? "undefined" : key;
1924
- const targetStore = options?.target === "global" || !this.currentContext() ? this.globalStore : this.currentContext().store;
1925
- const nsMap = this.ensureNsMap(targetStore, prefixedNs);
1926
- nsMap.set(actualKey, value);
1927
- this.notify({
1928
- ns: prefixedNs,
1929
- key: actualKey,
1930
- value,
1931
- source: targetStore === this.globalStore ? "global" : "context",
1932
- contextId: this.currentContext()?.id ?? null
1933
- });
1934
- }
1935
- delete(ns, key) {
1936
- const prefixedNs = this.prefixNamespace(ns);
1937
- const actualKey = !key && key !== "" ? "undefined" : key;
1938
- let deleted = false;
1939
- for (let i = this.contextStack.length - 1; i >= 0; i--) {
1940
- const ctx = this.contextStack[i];
1941
- const nsMap = ctx.store.get(prefixedNs);
1942
- if (nsMap && nsMap.has(actualKey)) {
1943
- nsMap.delete(actualKey);
1944
- deleted = true;
1945
- break;
1946
- }
1947
- }
1948
- if (!deleted) {
1949
- const globalNs = this.globalStore.get(prefixedNs);
1950
- if (globalNs && globalNs.has(actualKey)) {
1951
- globalNs.delete(actualKey);
1952
- deleted = true;
1953
- }
1954
- }
1955
- if (deleted) {
1956
- this.notify({
1957
- ns: prefixedNs,
1958
- key: actualKey,
1959
- value: void 0,
1960
- source: "delete",
1961
- contextId: this.currentContext()?.id ?? null
1962
- });
1963
- }
1964
- }
1965
- clear(ns) {
1966
- const prefixedNs = ns ? this.prefixNamespace(ns) : void 0;
1967
- if (prefixedNs) {
1968
- this.globalStore.delete(prefixedNs);
1969
- for (const ctx of this.contextStack) {
1970
- ctx.store.delete(prefixedNs);
1971
- }
1972
- } else {
1973
- this.globalStore.clear();
1974
- for (const ctx of this.contextStack) {
1975
- ctx.store.clear();
1976
- }
1977
- }
1978
- this.notify({
1979
- ns: prefixedNs ?? "*",
1980
- key: "*",
1981
- value: void 0,
1982
- source: "clear",
1983
- contextId: this.currentContext()?.id ?? null
1984
- });
1985
- }
1986
- subscribe(filter, listener) {
1987
- const internalFilter = filter ? {
1988
- ns: filter.ns ? this.prefixNamespace(filter.ns) : void 0,
1989
- key: filter.key
1990
- } : void 0;
1991
- const sub = {
1992
- filter: internalFilter,
1993
- fn: event => {
1994
- const originalEvent = {
1995
- ...event,
1996
- ns: event.ns.replace(/^idooel\./, "")
1997
- };
1998
- listener(originalEvent);
1999
- }
2000
- };
2001
- this.subscribers.add(sub);
2002
- return () => {
2003
- this.subscribers.delete(sub);
2004
- };
2005
- }
2006
- createContext(init) {
2007
- const prefixedInit = init ? Object.fromEntries(Object.entries(init).map(([ns, data]) => [this.prefixNamespace(ns), data])) : void 0;
2008
- return new Context(prefixedInit);
2009
- }
2010
- enter(ctx) {
2011
- this.contextStack.push(ctx);
2012
- return {
2013
- token: Symbol(ctx.id)
2014
- };
2015
- }
2016
- exit(token) {
2017
- while (this.contextStack.length) {
2018
- const ctx = this.contextStack[this.contextStack.length - 1];
2019
- Symbol.for(ctx.id);
2020
- this.contextStack.pop();
2021
- if (token) break;
2022
- }
2023
- }
2024
- runInContext(initOrCtx, fn) {
2025
- const ctx = initOrCtx instanceof Context ? initOrCtx : this.createContext(initOrCtx);
2026
- const {
2027
- token
2028
- } = this.enter(ctx);
2029
- try {
2030
- return fn();
2031
- } finally {
2032
- this.exit({
2033
- token
2034
- });
2035
- }
2036
- }
2037
- withContext(initOrCtx) {
2038
- return fn => {
2039
- return (...args) => this.runInContext(initOrCtx, () => fn(...args));
2040
- };
2041
- }
2042
- wrapHandler(handler) {
2043
- const captured = this.currentContext();
2044
- if (!captured) return handler;
2045
- return (...args) => this.runInContext(captured, () => handler(...args));
2046
- }
2047
- snapshot(options) {
2048
- const merged = options?.merged !== false;
2049
- if (merged) {
2050
- const out = {};
2051
- for (const [ns, nsMap] of this.globalStore) {
2052
- out[ns] = Object.fromEntries(nsMap.entries());
2053
- }
2054
- for (const ctx of this.contextStack) {
2055
- for (const [ns, nsMap] of ctx.store) {
2056
- out[ns] = {
2057
- ...(out[ns] ?? {}),
2058
- ...Object.fromEntries(nsMap.entries())
2059
- };
2060
- }
2061
- }
2062
- return out;
2063
- } else {
2064
- return {
2065
- global: Object.fromEntries(Array.from(this.globalStore.entries()).map(([ns, nsMap]) => [ns, Object.fromEntries(nsMap.entries())])),
2066
- contexts: this.contextStack.map(ctx => ({
2067
- id: ctx.id,
2068
- data: Object.fromEntries(Array.from(ctx.store.entries()).map(([ns, nsMap]) => [ns, Object.fromEntries(nsMap.entries())]))
2069
- }))
2070
- };
2071
- }
2072
- }
2073
- }
2074
- function createDataPool() {
2075
- return new DataPool();
2076
- }
2077
-
2078
1848
  // 创建全局数据池实例
2079
- const globalDataPool = createDataPool();
1849
+ const globalDataPool = runtimeContext.createDataPool();
2080
1850
  const useGlobalDataPool = () => globalDataPool;
2081
1851
 
2082
1852
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@idooel/components",
3
- "version": "0.0.2-beta.11",
3
+ "version": "0.0.2-beta.12",
4
4
  "description": "",
5
5
  "private": false,
6
6
  "main": "dist/@idooel/components.umd.js",
@@ -20,6 +20,7 @@
20
20
  "license": "ISC",
21
21
  "peerDependencies": {
22
22
  "@idooel/expression": "0.0.1-beta.1",
23
+ "@idooel/runtime-context": "0.0.1-beta.2",
23
24
  "@idooel/shared": "0.0.1-beta.7",
24
25
  "ant-design-vue": "1.7.8",
25
26
  "cropperjs": "1.4.1",
@@ -14,7 +14,7 @@ import { resolve } from 'path'
14
14
  /** @type { import('rollup').RollupOptions } */
15
15
  export default {
16
16
  input: 'packages/index.js',
17
- external: ['vue', '@idooel/shared', '@idooel/expression', 'vue-upload-component', 'moment'],
17
+ external: ['vue', '@idooel/runtime-context', '@idooel/shared', '@idooel/expression', 'vue-upload-component', 'moment'],
18
18
  plugins: [
19
19
  nodeResolve(),
20
20
  vue({
@@ -9,6 +9,7 @@ export default {
9
9
  format: 'umd',
10
10
  globals: {
11
11
  vue: 'Vue',
12
+ '@idooel/runtime-context': '@idooel/runtime-context',
12
13
  '@idooel/shared': '@idooel/shared',
13
14
  '@idooel/expression': '@idooel/expression'
14
15
  },