@appkit/dek-lib 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.es.js CHANGED
@@ -58008,21 +58008,6 @@ function useState(plugin) {
58008
58008
  const [state2] = useLocalStorage$1(`api:${plugin.toLowerCase()}`, "{}");
58009
58009
  return state2;
58010
58010
  }
58011
- function isJsonString(str) {
58012
- if (typeof str !== "string") {
58013
- return false;
58014
- }
58015
- if (str.length === 0) {
58016
- return false;
58017
- }
58018
- if (str[0] !== "{" && str[0] !== "[") {
58019
- return false;
58020
- }
58021
- if (str[str.length - 1] !== "}" && str[str.length - 1] !== "]") {
58022
- return false;
58023
- }
58024
- return true;
58025
- }
58026
58011
  class Api {
58027
58012
  constructor(integrationKey) {
58028
58013
  __publicField2(this, "integrationKey");
@@ -58273,9 +58258,6 @@ function usePluginState(api2, key, defaultValue) {
58273
58258
  let value;
58274
58259
  if (state2 && state2[key]) {
58275
58260
  value = state2[key];
58276
- if (isJsonString(value)) {
58277
- value = tryParseJson(value, defaultValue);
58278
- }
58279
58261
  } else {
58280
58262
  value = defaultValue;
58281
58263
  }
@@ -58285,19 +58267,36 @@ function usePluginState(api2, key, defaultValue) {
58285
58267
  if (typeof newValueOrFn === "function") {
58286
58268
  newValueOrFn = newValueOrFn(value);
58287
58269
  }
58288
- if (typeof newValueOrFn === "object") {
58289
- newValueOrFn = JSON.stringify(newValueOrFn);
58290
- }
58291
58270
  setState(integrationKey, key, newValueOrFn);
58292
58271
  }
58293
58272
  ];
58294
58273
  }
58274
+ function usePluginStateObject(api2, key, defaultValue = {}) {
58275
+ const integrationKey = api2.integrationKey;
58276
+ const state2 = useState(integrationKey);
58277
+ let value;
58278
+ if (state2 && state2[key]) {
58279
+ value = tryParseJson(state2[key], defaultValue);
58280
+ } else {
58281
+ value = defaultValue;
58282
+ }
58283
+ return [
58284
+ value,
58285
+ (newValueOrFn) => {
58286
+ if (typeof newValueOrFn === "function") {
58287
+ newValueOrFn = newValueOrFn(value);
58288
+ }
58289
+ setState(integrationKey, key, JSON.stringify(newValueOrFn));
58290
+ }
58291
+ ];
58292
+ }
58295
58293
  function __debug() {
58296
58294
  }
58297
58295
  const dekPluginModule = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
58298
58296
  __proto__: null,
58299
58297
  __debug,
58300
- usePluginState
58298
+ usePluginState,
58299
+ usePluginStateObject
58301
58300
  }, Symbol.toStringTag, { value: "Module" }));
58302
58301
  const USER_PLUGIN_AND_INTEGRATIONS_QUERY = gql(`
58303
58302
  query userPluginsAndIntegrations {
@@ -58328,7 +58327,7 @@ async function fetchUserPlugins(email, password) {
58328
58327
  result.integrations.push({
58329
58328
  key: "base",
58330
58329
  pluginName: "base",
58331
- pluginVersion: "0.13.0",
58330
+ pluginVersion: "0.15.0",
58332
58331
  pluginConfig: []
58333
58332
  });
58334
58333
  return result;
@@ -58503,14 +58502,14 @@ const Header = ({ height = 70 }) => {
58503
58502
  };
58504
58503
  const About = () => {
58505
58504
  return /* @__PURE__ */ jsxRuntimeExports.jsxs(x0, { padding: 20, direction: "vert", children: [
58506
- /* @__PURE__ */ jsxRuntimeExports.jsx(hF1, { children: `Dek ${"0.13.0"}` }),
58505
+ /* @__PURE__ */ jsxRuntimeExports.jsx(hF1, { children: `Dek ${"0.15.0"}` }),
58507
58506
  /* @__PURE__ */ jsxRuntimeExports.jsx(X4, { children: "From Appkit" })
58508
58507
  ] });
58509
58508
  };
58510
58509
  const Backgrounds = ({ api: api2 }) => {
58511
58510
  const [backgroundKey] = usePluginState(api2, "backgroundKey", "image");
58512
58511
  const propsKey = `backgroundProps-${backgroundKey}`;
58513
- const [backgroundProps] = usePluginState(api2, propsKey, {});
58512
+ const [backgroundProps] = usePluginStateObject(api2, propsKey);
58514
58513
  const [selectedKey, setSelectedKey] = useState$1(backgroundKey);
58515
58514
  const backgrounds = api2.registry.collection("backgrounds");
58516
58515
  const backgroundItems = backgrounds.items;
@@ -58674,7 +58673,7 @@ const PluginDev = ({ api: api2 }) => {
58674
58673
  };
58675
58674
  const Theme = ({ api: api2 }) => {
58676
58675
  const [selectedKey, setSelectedKey] = useState$1("tile");
58677
- const [themeState, setThemeState] = usePluginState(api2, "theme", {});
58676
+ const [themeState, setThemeState] = usePluginStateObject(api2, "theme");
58678
58677
  const handleSelection = (key) => {
58679
58678
  setSelectedKey(key);
58680
58679
  };
@@ -94026,7 +94025,7 @@ const Background = () => {
94026
94025
  const api2 = getPluginApi();
94027
94026
  const [backgroundKey] = usePluginState(api2, "backgroundKey", "image");
94028
94027
  const propsKey = `backgroundProps-${backgroundKey}`;
94029
- const [backgroundProps] = usePluginState(api2, propsKey, {});
94028
+ const [backgroundProps] = usePluginStateObject(api2, propsKey);
94030
94029
  const backgrounds = api2.registry.collection("backgrounds");
94031
94030
  if (backgrounds && backgrounds.items && backgrounds.items[backgroundKey]) {
94032
94031
  return backgrounds.items[backgroundKey].component(backgroundProps);
@@ -95209,7 +95208,7 @@ body {
95209
95208
  `;
95210
95209
  const BoardStyles = ({ transitionDelay: transitionDelay2 }) => {
95211
95210
  const api2 = getPluginApi();
95212
- const [themeState] = usePluginState(api2, "theme", {});
95211
+ const [themeState] = usePluginStateObject(api2, "theme");
95213
95212
  return /* @__PURE__ */ jsxRuntimeExports.jsxs(jsxRuntimeExports.Fragment, { children: [
95214
95213
  /* @__PURE__ */ jsxRuntimeExports.jsx(wG1, {}),
95215
95214
  /* @__PURE__ */ jsxRuntimeExports.jsx(
package/dist/index.umd.js CHANGED
@@ -58025,21 +58025,6 @@ Arguments: ` + Array.prototype.slice.call(h2).join("") + `
58025
58025
  const [state2] = useLocalStorage$1(`api:${plugin.toLowerCase()}`, "{}");
58026
58026
  return state2;
58027
58027
  }
58028
- function isJsonString(str) {
58029
- if (typeof str !== "string") {
58030
- return false;
58031
- }
58032
- if (str.length === 0) {
58033
- return false;
58034
- }
58035
- if (str[0] !== "{" && str[0] !== "[") {
58036
- return false;
58037
- }
58038
- if (str[str.length - 1] !== "}" && str[str.length - 1] !== "]") {
58039
- return false;
58040
- }
58041
- return true;
58042
- }
58043
58028
  class Api {
58044
58029
  constructor(integrationKey) {
58045
58030
  __publicField2(this, "integrationKey");
@@ -58290,9 +58275,6 @@ Arguments: ` + Array.prototype.slice.call(h2).join("") + `
58290
58275
  let value;
58291
58276
  if (state2 && state2[key]) {
58292
58277
  value = state2[key];
58293
- if (isJsonString(value)) {
58294
- value = tryParseJson(value, defaultValue);
58295
- }
58296
58278
  } else {
58297
58279
  value = defaultValue;
58298
58280
  }
@@ -58302,19 +58284,36 @@ Arguments: ` + Array.prototype.slice.call(h2).join("") + `
58302
58284
  if (typeof newValueOrFn === "function") {
58303
58285
  newValueOrFn = newValueOrFn(value);
58304
58286
  }
58305
- if (typeof newValueOrFn === "object") {
58306
- newValueOrFn = JSON.stringify(newValueOrFn);
58307
- }
58308
58287
  setState(integrationKey, key, newValueOrFn);
58309
58288
  }
58310
58289
  ];
58311
58290
  }
58291
+ function usePluginStateObject(api2, key, defaultValue = {}) {
58292
+ const integrationKey = api2.integrationKey;
58293
+ const state2 = useState(integrationKey);
58294
+ let value;
58295
+ if (state2 && state2[key]) {
58296
+ value = tryParseJson(state2[key], defaultValue);
58297
+ } else {
58298
+ value = defaultValue;
58299
+ }
58300
+ return [
58301
+ value,
58302
+ (newValueOrFn) => {
58303
+ if (typeof newValueOrFn === "function") {
58304
+ newValueOrFn = newValueOrFn(value);
58305
+ }
58306
+ setState(integrationKey, key, JSON.stringify(newValueOrFn));
58307
+ }
58308
+ ];
58309
+ }
58312
58310
  function __debug() {
58313
58311
  }
58314
58312
  const dekPluginModule = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
58315
58313
  __proto__: null,
58316
58314
  __debug,
58317
- usePluginState
58315
+ usePluginState,
58316
+ usePluginStateObject
58318
58317
  }, Symbol.toStringTag, { value: "Module" }));
58319
58318
  const USER_PLUGIN_AND_INTEGRATIONS_QUERY = gql(`
58320
58319
  query userPluginsAndIntegrations {
@@ -58345,7 +58344,7 @@ Arguments: ` + Array.prototype.slice.call(h2).join("") + `
58345
58344
  result.integrations.push({
58346
58345
  key: "base",
58347
58346
  pluginName: "base",
58348
- pluginVersion: "0.13.0",
58347
+ pluginVersion: "0.15.0",
58349
58348
  pluginConfig: []
58350
58349
  });
58351
58350
  return result;
@@ -58520,14 +58519,14 @@ Arguments: ` + Array.prototype.slice.call(h2).join("") + `
58520
58519
  };
58521
58520
  const About = () => {
58522
58521
  return /* @__PURE__ */ jsxRuntimeExports.jsxs(x0, { padding: 20, direction: "vert", children: [
58523
- /* @__PURE__ */ jsxRuntimeExports.jsx(hF1, { children: `Dek ${"0.13.0"}` }),
58522
+ /* @__PURE__ */ jsxRuntimeExports.jsx(hF1, { children: `Dek ${"0.15.0"}` }),
58524
58523
  /* @__PURE__ */ jsxRuntimeExports.jsx(X4, { children: "From Appkit" })
58525
58524
  ] });
58526
58525
  };
58527
58526
  const Backgrounds = ({ api: api2 }) => {
58528
58527
  const [backgroundKey] = usePluginState(api2, "backgroundKey", "image");
58529
58528
  const propsKey = `backgroundProps-${backgroundKey}`;
58530
- const [backgroundProps] = usePluginState(api2, propsKey, {});
58529
+ const [backgroundProps] = usePluginStateObject(api2, propsKey);
58531
58530
  const [selectedKey, setSelectedKey] = React$3.useState(backgroundKey);
58532
58531
  const backgrounds = api2.registry.collection("backgrounds");
58533
58532
  const backgroundItems = backgrounds.items;
@@ -58691,7 +58690,7 @@ Arguments: ` + Array.prototype.slice.call(h2).join("") + `
58691
58690
  };
58692
58691
  const Theme = ({ api: api2 }) => {
58693
58692
  const [selectedKey, setSelectedKey] = React$3.useState("tile");
58694
- const [themeState, setThemeState] = usePluginState(api2, "theme", {});
58693
+ const [themeState, setThemeState] = usePluginStateObject(api2, "theme");
58695
58694
  const handleSelection = (key) => {
58696
58695
  setSelectedKey(key);
58697
58696
  };
@@ -94043,7 +94042,7 @@ Arguments: ` + Array.prototype.slice.call(h2).join("") + `
94043
94042
  const api2 = getPluginApi();
94044
94043
  const [backgroundKey] = usePluginState(api2, "backgroundKey", "image");
94045
94044
  const propsKey = `backgroundProps-${backgroundKey}`;
94046
- const [backgroundProps] = usePluginState(api2, propsKey, {});
94045
+ const [backgroundProps] = usePluginStateObject(api2, propsKey);
94047
94046
  const backgrounds = api2.registry.collection("backgrounds");
94048
94047
  if (backgrounds && backgrounds.items && backgrounds.items[backgroundKey]) {
94049
94048
  return backgrounds.items[backgroundKey].component(backgroundProps);
@@ -95226,7 +95225,7 @@ body {
95226
95225
  `;
95227
95226
  const BoardStyles = ({ transitionDelay: transitionDelay2 }) => {
95228
95227
  const api2 = getPluginApi();
95229
- const [themeState] = usePluginState(api2, "theme", {});
95228
+ const [themeState] = usePluginStateObject(api2, "theme");
95230
95229
  return /* @__PURE__ */ jsxRuntimeExports.jsxs(jsxRuntimeExports.Fragment, { children: [
95231
95230
  /* @__PURE__ */ jsxRuntimeExports.jsx(wG1, {}),
95232
95231
  /* @__PURE__ */ jsxRuntimeExports.jsx(
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@appkit/dek-lib",
3
3
  "private": false,
4
- "version": "0.13.0",
4
+ "version": "0.15.0",
5
5
  "type": "module",
6
6
  "scripts": {
7
7
  "build": "tsc && vite build",