@appkit/dek-plugin 0.13.0 → 0.15.0
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
CHANGED
|
@@ -2,4 +2,5 @@ export type { DekPlugin, DekPluginBoardItem, DekPluginComponentItem, DekPluginCo
|
|
|
2
2
|
export type { DekRegistry, DekRegistryCollection, DekRegistryCollectionItem, DekRegistrySchema, DekRegistrySchemaItem, DekRegistrySchemaProps, DekRegistrySchemaPropsItem, } from './lib/registry';
|
|
3
3
|
export type { DekApi, DekApiInfo, DekApiMessage, DekApiMessageType, DekApiPlugin, DekApiState, } from './lib/api';
|
|
4
4
|
export { default as usePluginState } from './lib/hooks/usePluginState';
|
|
5
|
+
export { default as usePluginStateObject } from './lib/hooks/usePluginStateObject';
|
|
5
6
|
export declare function __debug(): void;
|
package/dist/index.es.js
CHANGED
|
@@ -166,21 +166,6 @@ function useState(plugin) {
|
|
|
166
166
|
const [state] = useLocalStorage(`api:${plugin.toLowerCase()}`, "{}");
|
|
167
167
|
return state;
|
|
168
168
|
}
|
|
169
|
-
function isJsonString(str) {
|
|
170
|
-
if (typeof str !== "string") {
|
|
171
|
-
return false;
|
|
172
|
-
}
|
|
173
|
-
if (str.length === 0) {
|
|
174
|
-
return false;
|
|
175
|
-
}
|
|
176
|
-
if (str[0] !== "{" && str[0] !== "[") {
|
|
177
|
-
return false;
|
|
178
|
-
}
|
|
179
|
-
if (str[str.length - 1] !== "}" && str[str.length - 1] !== "]") {
|
|
180
|
-
return false;
|
|
181
|
-
}
|
|
182
|
-
return true;
|
|
183
|
-
}
|
|
184
169
|
class Api {
|
|
185
170
|
constructor(integrationKey) {
|
|
186
171
|
__publicField(this, "integrationKey");
|
|
@@ -431,9 +416,6 @@ function usePluginState(api2, key, defaultValue) {
|
|
|
431
416
|
let value;
|
|
432
417
|
if (state && state[key]) {
|
|
433
418
|
value = state[key];
|
|
434
|
-
if (isJsonString(value)) {
|
|
435
|
-
value = tryParseJson(value, defaultValue);
|
|
436
|
-
}
|
|
437
419
|
} else {
|
|
438
420
|
value = defaultValue;
|
|
439
421
|
}
|
|
@@ -443,16 +425,33 @@ function usePluginState(api2, key, defaultValue) {
|
|
|
443
425
|
if (typeof newValueOrFn === "function") {
|
|
444
426
|
newValueOrFn = newValueOrFn(value);
|
|
445
427
|
}
|
|
446
|
-
if (typeof newValueOrFn === "object") {
|
|
447
|
-
newValueOrFn = JSON.stringify(newValueOrFn);
|
|
448
|
-
}
|
|
449
428
|
setState(integrationKey, key, newValueOrFn);
|
|
450
429
|
}
|
|
451
430
|
];
|
|
452
431
|
}
|
|
432
|
+
function usePluginStateObject(api2, key, defaultValue = {}) {
|
|
433
|
+
const integrationKey = api2.integrationKey;
|
|
434
|
+
const state = useState(integrationKey);
|
|
435
|
+
let value;
|
|
436
|
+
if (state && state[key]) {
|
|
437
|
+
value = tryParseJson(state[key], defaultValue);
|
|
438
|
+
} else {
|
|
439
|
+
value = defaultValue;
|
|
440
|
+
}
|
|
441
|
+
return [
|
|
442
|
+
value,
|
|
443
|
+
(newValueOrFn) => {
|
|
444
|
+
if (typeof newValueOrFn === "function") {
|
|
445
|
+
newValueOrFn = newValueOrFn(value);
|
|
446
|
+
}
|
|
447
|
+
setState(integrationKey, key, JSON.stringify(newValueOrFn));
|
|
448
|
+
}
|
|
449
|
+
];
|
|
450
|
+
}
|
|
453
451
|
function __debug() {
|
|
454
452
|
}
|
|
455
453
|
export {
|
|
456
454
|
__debug,
|
|
457
|
-
usePluginState
|
|
455
|
+
usePluginState,
|
|
456
|
+
usePluginStateObject
|
|
458
457
|
};
|
package/dist/index.umd.js
CHANGED
|
@@ -169,21 +169,6 @@ var __publicField = (obj, key, value) => {
|
|
|
169
169
|
const [state] = useLocalStorage(`api:${plugin.toLowerCase()}`, "{}");
|
|
170
170
|
return state;
|
|
171
171
|
}
|
|
172
|
-
function isJsonString(str) {
|
|
173
|
-
if (typeof str !== "string") {
|
|
174
|
-
return false;
|
|
175
|
-
}
|
|
176
|
-
if (str.length === 0) {
|
|
177
|
-
return false;
|
|
178
|
-
}
|
|
179
|
-
if (str[0] !== "{" && str[0] !== "[") {
|
|
180
|
-
return false;
|
|
181
|
-
}
|
|
182
|
-
if (str[str.length - 1] !== "}" && str[str.length - 1] !== "]") {
|
|
183
|
-
return false;
|
|
184
|
-
}
|
|
185
|
-
return true;
|
|
186
|
-
}
|
|
187
172
|
class Api {
|
|
188
173
|
constructor(integrationKey) {
|
|
189
174
|
__publicField(this, "integrationKey");
|
|
@@ -434,9 +419,6 @@ var __publicField = (obj, key, value) => {
|
|
|
434
419
|
let value;
|
|
435
420
|
if (state && state[key]) {
|
|
436
421
|
value = state[key];
|
|
437
|
-
if (isJsonString(value)) {
|
|
438
|
-
value = tryParseJson(value, defaultValue);
|
|
439
|
-
}
|
|
440
422
|
} else {
|
|
441
423
|
value = defaultValue;
|
|
442
424
|
}
|
|
@@ -446,16 +428,33 @@ var __publicField = (obj, key, value) => {
|
|
|
446
428
|
if (typeof newValueOrFn === "function") {
|
|
447
429
|
newValueOrFn = newValueOrFn(value);
|
|
448
430
|
}
|
|
449
|
-
if (typeof newValueOrFn === "object") {
|
|
450
|
-
newValueOrFn = JSON.stringify(newValueOrFn);
|
|
451
|
-
}
|
|
452
431
|
setState(integrationKey, key, newValueOrFn);
|
|
453
432
|
}
|
|
454
433
|
];
|
|
455
434
|
}
|
|
435
|
+
function usePluginStateObject(api2, key, defaultValue = {}) {
|
|
436
|
+
const integrationKey = api2.integrationKey;
|
|
437
|
+
const state = useState(integrationKey);
|
|
438
|
+
let value;
|
|
439
|
+
if (state && state[key]) {
|
|
440
|
+
value = tryParseJson(state[key], defaultValue);
|
|
441
|
+
} else {
|
|
442
|
+
value = defaultValue;
|
|
443
|
+
}
|
|
444
|
+
return [
|
|
445
|
+
value,
|
|
446
|
+
(newValueOrFn) => {
|
|
447
|
+
if (typeof newValueOrFn === "function") {
|
|
448
|
+
newValueOrFn = newValueOrFn(value);
|
|
449
|
+
}
|
|
450
|
+
setState(integrationKey, key, JSON.stringify(newValueOrFn));
|
|
451
|
+
}
|
|
452
|
+
];
|
|
453
|
+
}
|
|
456
454
|
function __debug() {
|
|
457
455
|
}
|
|
458
456
|
exports2.__debug = __debug;
|
|
459
457
|
exports2.usePluginState = usePluginState;
|
|
458
|
+
exports2.usePluginStateObject = usePluginStateObject;
|
|
460
459
|
Object.defineProperty(exports2, Symbol.toStringTag, { value: "Module" });
|
|
461
460
|
});
|
|
@@ -1,11 +1,9 @@
|
|
|
1
1
|
import { DekApi } from '../api';
|
|
2
2
|
import { DekApiStateType } from '../state';
|
|
3
|
-
export type
|
|
4
|
-
export type
|
|
5
|
-
declare function usePluginState(api: DekApi, key: string): [DekApiStateType | undefined,
|
|
6
|
-
declare function usePluginState(api: DekApi, key: string, defaultValue: string): [string,
|
|
7
|
-
declare function usePluginState(api: DekApi, key: string, defaultValue: number): [number,
|
|
8
|
-
declare function usePluginState(api: DekApi, key: string, defaultValue: boolean): [boolean,
|
|
9
|
-
declare function usePluginState(api: DekApi, key: string, defaultValue: Array<any>): [Array<any>, DekApiSetStateAction];
|
|
10
|
-
declare function usePluginState(api: DekApi, key: string, defaultValue: Record<string, any>): [Record<string, any>, DekApiSetStateAction];
|
|
3
|
+
export type DekApiStateSetFunc<T> = (value: T) => void;
|
|
4
|
+
export type DekApiStateSetter<T = DekApiStateType> = (newValueOrFn: T | DekApiStateSetFunc<T>) => void;
|
|
5
|
+
declare function usePluginState(api: DekApi, key: string): [DekApiStateType | undefined, DekApiStateSetter];
|
|
6
|
+
declare function usePluginState(api: DekApi, key: string, defaultValue: string): [string, DekApiStateSetter<string>];
|
|
7
|
+
declare function usePluginState(api: DekApi, key: string, defaultValue: number): [number, DekApiStateSetter<number>];
|
|
8
|
+
declare function usePluginState(api: DekApi, key: string, defaultValue: boolean): [boolean, DekApiStateSetter<boolean>];
|
|
11
9
|
export default usePluginState;
|
package/dist/lib/state.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export type DekApiStateType = string | number | boolean
|
|
1
|
+
export type DekApiStateType = string | number | boolean;
|
|
2
2
|
export type DekApiStateItem = Record<string, DekApiStateType>;
|
|
3
3
|
export type DekApiState = Record<string, DekApiStateItem>;
|
|
4
4
|
export declare function setState(integrationKey: string, key: string, value: DekApiStateType): void;
|