phecda-web 1.0.1-beta.12 → 1.0.1-beta.13
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.js +8 -6
- package/dist/index.mjs +9 -7
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -46,8 +46,8 @@ var import_phecda_core = require("phecda-core");
|
|
|
46
46
|
var import_mitt = __toESM(require("mitt"));
|
|
47
47
|
var emitter = (0, import_mitt.default)();
|
|
48
48
|
function defaultWebInject() {
|
|
49
|
-
if (!(0, import_phecda_core.
|
|
50
|
-
(0, import_phecda_core.
|
|
49
|
+
if (!(0, import_phecda_core.getInject)("watcher")) {
|
|
50
|
+
(0, import_phecda_core.setInject)("watcher", ({ eventName, instance, key, options }) => {
|
|
51
51
|
const fn = typeof instance[key] === "function" ? instance[key].bind(instance) : (v) => instance[key] = v;
|
|
52
52
|
if (options?.once) {
|
|
53
53
|
const handler = /* @__PURE__ */ __name(() => {
|
|
@@ -61,10 +61,11 @@ function defaultWebInject() {
|
|
|
61
61
|
return () => emitter.off(eventName);
|
|
62
62
|
});
|
|
63
63
|
}
|
|
64
|
-
if (!(0, import_phecda_core.
|
|
65
|
-
(0, import_phecda_core.
|
|
66
|
-
if (
|
|
67
|
-
|
|
64
|
+
if (!(0, import_phecda_core.getInject)("storage")) {
|
|
65
|
+
(0, import_phecda_core.setInject)("storage", ({ tag, key, instance, toJSON, toString }) => {
|
|
66
|
+
if (key === import_phecda_core.SHARE_KEY)
|
|
67
|
+
key = "";
|
|
68
|
+
tag = `phecda:${key ? `${tag}-${key}` : tag}`;
|
|
68
69
|
const initstr = localStorage.getItem(tag);
|
|
69
70
|
if (initstr) {
|
|
70
71
|
const data = toJSON(initstr);
|
|
@@ -77,6 +78,7 @@ function defaultWebInject() {
|
|
|
77
78
|
}
|
|
78
79
|
}
|
|
79
80
|
}
|
|
81
|
+
localStorage.setItem(tag, toString(key ? instance[key] : instance));
|
|
80
82
|
globalThis.addEventListener("beforeunload", () => {
|
|
81
83
|
localStorage.setItem(tag, toString(key ? instance[key] : instance));
|
|
82
84
|
});
|
package/dist/index.mjs
CHANGED
|
@@ -5,12 +5,12 @@ var __name = (target, value) => __defProp(target, "name", { value, configurable:
|
|
|
5
5
|
export * from "phecda-core";
|
|
6
6
|
|
|
7
7
|
// src/plugin.ts
|
|
8
|
-
import {
|
|
8
|
+
import { SHARE_KEY, getInject, setInject } from "phecda-core";
|
|
9
9
|
import mitt from "mitt";
|
|
10
10
|
var emitter = mitt();
|
|
11
11
|
function defaultWebInject() {
|
|
12
|
-
if (!
|
|
13
|
-
|
|
12
|
+
if (!getInject("watcher")) {
|
|
13
|
+
setInject("watcher", ({ eventName, instance, key, options }) => {
|
|
14
14
|
const fn = typeof instance[key] === "function" ? instance[key].bind(instance) : (v) => instance[key] = v;
|
|
15
15
|
if (options?.once) {
|
|
16
16
|
const handler = /* @__PURE__ */ __name(() => {
|
|
@@ -24,10 +24,11 @@ function defaultWebInject() {
|
|
|
24
24
|
return () => emitter.off(eventName);
|
|
25
25
|
});
|
|
26
26
|
}
|
|
27
|
-
if (!
|
|
28
|
-
|
|
29
|
-
if (
|
|
30
|
-
|
|
27
|
+
if (!getInject("storage")) {
|
|
28
|
+
setInject("storage", ({ tag, key, instance, toJSON, toString }) => {
|
|
29
|
+
if (key === SHARE_KEY)
|
|
30
|
+
key = "";
|
|
31
|
+
tag = `phecda:${key ? `${tag}-${key}` : tag}`;
|
|
31
32
|
const initstr = localStorage.getItem(tag);
|
|
32
33
|
if (initstr) {
|
|
33
34
|
const data = toJSON(initstr);
|
|
@@ -40,6 +41,7 @@ function defaultWebInject() {
|
|
|
40
41
|
}
|
|
41
42
|
}
|
|
42
43
|
}
|
|
44
|
+
localStorage.setItem(tag, toString(key ? instance[key] : instance));
|
|
43
45
|
globalThis.addEventListener("beforeunload", () => {
|
|
44
46
|
localStorage.setItem(tag, toString(key ? instance[key] : instance));
|
|
45
47
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "phecda-web",
|
|
3
|
-
"version": "1.0.1-beta.
|
|
3
|
+
"version": "1.0.1-beta.13",
|
|
4
4
|
"description": "provide web function for phecda",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.mjs",
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
"license": "MIT",
|
|
14
14
|
"dependencies": {
|
|
15
15
|
"mitt": "^3.0.0",
|
|
16
|
-
"phecda-core": "3.0.0-beta.
|
|
16
|
+
"phecda-core": "3.0.0-beta.16"
|
|
17
17
|
},
|
|
18
18
|
"devDependencies": {
|
|
19
19
|
"tsup": "^6.5.0"
|