@appkit/dek-lib 0.10.0 → 0.11.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.umd.js CHANGED
@@ -720,324 +720,6 @@ var __publicField = (obj, key, value) => {
720
720
  __proto__: null,
721
721
  default: jsxRuntime
722
722
  }, [jsxRuntimeExports]);
723
- function useEventCallback$1(fn2) {
724
- const ref = React$3.useRef(() => {
725
- throw new Error("Cannot call an event handler while rendering.");
726
- });
727
- useIsomorphicLayoutEffect$2(() => {
728
- ref.current = fn2;
729
- }, [fn2]);
730
- return React$3.useCallback((...args) => ref.current(...args), [ref]);
731
- }
732
- function useEventListener$1(eventName, handler, element, options) {
733
- const savedHandler = React$3.useRef(handler);
734
- useIsomorphicLayoutEffect$2(() => {
735
- savedHandler.current = handler;
736
- }, [handler]);
737
- React$3.useEffect(() => {
738
- var _a2;
739
- const targetElement = (_a2 = element === null || element === void 0 ? void 0 : element.current) !== null && _a2 !== void 0 ? _a2 : window;
740
- if (!(targetElement && targetElement.addEventListener))
741
- return;
742
- const listener = (event) => savedHandler.current(event);
743
- targetElement.addEventListener(eventName, listener, options);
744
- return () => {
745
- targetElement.removeEventListener(eventName, listener, options);
746
- };
747
- }, [eventName, element, options]);
748
- }
749
- const useIsomorphicLayoutEffect$2 = typeof window !== "undefined" ? React$3.useLayoutEffect : React$3.useEffect;
750
- function useLocalStorage$1(key, initialValue) {
751
- const readValue = React$3.useCallback(() => {
752
- if (typeof window === "undefined") {
753
- return initialValue;
754
- }
755
- try {
756
- const item = window.localStorage.getItem(key);
757
- return item ? parseJSON$1(item) : initialValue;
758
- } catch (error2) {
759
- console.warn(`Error reading localStorage key “${key}”:`, error2);
760
- return initialValue;
761
- }
762
- }, [initialValue, key]);
763
- const [storedValue, setStoredValue] = React$3.useState(readValue);
764
- const setValue = useEventCallback$1((value) => {
765
- if (typeof window === "undefined") {
766
- console.warn(`Tried setting localStorage key “${key}” even though environment is not a client`);
767
- }
768
- try {
769
- const newValue = value instanceof Function ? value(storedValue) : value;
770
- window.localStorage.setItem(key, JSON.stringify(newValue));
771
- setStoredValue(newValue);
772
- window.dispatchEvent(new Event("local-storage"));
773
- } catch (error2) {
774
- console.warn(`Error setting localStorage key “${key}”:`, error2);
775
- }
776
- });
777
- React$3.useEffect(() => {
778
- setStoredValue(readValue());
779
- }, []);
780
- const handleStorageChange = React$3.useCallback((event) => {
781
- if ((event === null || event === void 0 ? void 0 : event.key) && event.key !== key) {
782
- return;
783
- }
784
- setStoredValue(readValue());
785
- }, [key, readValue]);
786
- useEventListener$1("storage", handleStorageChange);
787
- useEventListener$1("local-storage", handleStorageChange);
788
- return [storedValue, setValue];
789
- }
790
- function parseJSON$1(value) {
791
- try {
792
- return value === "undefined" ? void 0 : JSON.parse(value !== null && value !== void 0 ? value : "");
793
- } catch (_a2) {
794
- console.log("parsing error on", { value });
795
- return void 0;
796
- }
797
- }
798
- function extractErrorMessage$1(err) {
799
- return err instanceof Error ? err.message : JSON.stringify(err);
800
- }
801
- function setState(plugin, key, value) {
802
- const localData = getStateRoot(plugin);
803
- localData[key] = value;
804
- localStorage.setItem(
805
- `api:${plugin.toLowerCase()}`,
806
- JSON.stringify(localData)
807
- );
808
- window.dispatchEvent(new Event("local-storage"));
809
- }
810
- function getState(plugin, key) {
811
- const localData = getStateRoot(plugin);
812
- return localData[key];
813
- }
814
- function getStateRoot(plugin) {
815
- const local = localStorage.getItem(`api:${plugin.toLowerCase()}`);
816
- return tryParseJson(local || "{}");
817
- }
818
- function tryParseJson(jsonString, defaultValue = {}) {
819
- try {
820
- return JSON.parse(jsonString);
821
- } catch (err) {
822
- console.warn(`Failed parsing JSON: ${extractErrorMessage$1(err)}`);
823
- return defaultValue;
824
- }
825
- }
826
- function useState(plugin) {
827
- const [state2] = useLocalStorage$1(`api:${plugin.toLowerCase()}`, "{}");
828
- return state2;
829
- }
830
- function isJsonString(str) {
831
- if (typeof str !== "string") {
832
- return false;
833
- }
834
- if (str.length === 0) {
835
- return false;
836
- }
837
- if (str[0] !== "{" && str[0] !== "[") {
838
- return false;
839
- }
840
- if (str[str.length - 1] !== "}" && str[str.length - 1] !== "]") {
841
- return false;
842
- }
843
- return true;
844
- }
845
- class Api {
846
- trace(message, ...data) {
847
- console.log(`DEK-TRACE: ${message}`, ...data);
848
- this.globals.messages.push({
849
- type: "trace",
850
- body: message,
851
- data,
852
- at: Date.now()
853
- });
854
- }
855
- warn(message, ...data) {
856
- console.warn(`DEK-WARN: ${message}`, ...data);
857
- this.globals.messages.push({
858
- type: "error",
859
- body: message,
860
- data,
861
- at: Date.now()
862
- });
863
- }
864
- error(message, ...data) {
865
- console.error(`DEK-ERROR: ${message}`, ...data);
866
- this.globals.messages.push({
867
- type: "error",
868
- body: message,
869
- data,
870
- at: Date.now()
871
- });
872
- }
873
- messages() {
874
- return this.globals.messages;
875
- }
876
- plugin(name) {
877
- return this.createPluginWrapper(name);
878
- }
879
- get registry() {
880
- return this.globals.registry;
881
- }
882
- get boardKey() {
883
- return this.globals.navigateParams.boardKey || "#error";
884
- }
885
- get boards() {
886
- return this.globals.boards;
887
- }
888
- get board() {
889
- return this.boards.find((board) => board.key === this.boardKey) || {
890
- zones: []
891
- };
892
- }
893
- get layout() {
894
- return this.board.layout || `<Screen><Text>Missing layout</Text></Screen>`;
895
- }
896
- get commandGroups() {
897
- return this.globals.commandGroups;
898
- }
899
- navigate(path) {
900
- this.globals.setLocation(`/${this.boardKey}${path}`);
901
- }
902
- get navigateParams() {
903
- return this.globals.navigateParams;
904
- }
905
- navigateBack() {
906
- history.back();
907
- }
908
- open(boardKey) {
909
- this.globals.setLocation(`/${boardKey}`);
910
- }
911
- createPluginWrapper(integrationKey) {
912
- const plugin = this.getPluginInstance(integrationKey);
913
- const available = !!plugin;
914
- return {
915
- available,
916
- info: {
917
- components: (plugin == null ? void 0 : plugin.components) ? plugin.components.map((component) => component.key) : [],
918
- screens: (plugin == null ? void 0 : plugin.screens) ? plugin.screens.map((screen) => screen.path) : []
919
- },
920
- component: (key, props) => this.getComponent(integrationKey, key, props),
921
- componentSchema: (key) => this.getComponentSchema(integrationKey, key),
922
- screen: (path) => this.getScreen(integrationKey, path),
923
- board: (key) => this.getBoard(integrationKey, key),
924
- api: (plugin == null ? void 0 : plugin.api) || {},
925
- state: {
926
- get: (key, defaultValue) => {
927
- if (!available) {
928
- return defaultValue;
929
- }
930
- return getState(integrationKey, key) || defaultValue;
931
- },
932
- set: (key, value) => {
933
- if (!available) {
934
- return;
935
- }
936
- setState(integrationKey, key, value);
937
- }
938
- }
939
- };
940
- }
941
- get globals() {
942
- return window.__dek_globals;
943
- }
944
- get plugins() {
945
- const plugins = {};
946
- Object.keys(this.globals.pluginInstances).forEach((key) => {
947
- plugins[key] = this.createPluginWrapper(key);
948
- });
949
- return plugins;
950
- }
951
- getPluginInstance(integrationKey) {
952
- return this.globals.pluginInstances[integrationKey];
953
- }
954
- getComponent(integrationKey, componentKey, props) {
955
- const plugin = this.getPluginInstance(integrationKey);
956
- if (plugin) {
957
- const component = plugin.components && plugin.components.find(
958
- (c2) => c2.key.toLowerCase() === componentKey.toLowerCase()
959
- );
960
- if (!component) {
961
- return;
962
- }
963
- return component.element({ ...props, plugin });
964
- }
965
- }
966
- getComponentSchema(integrationKey, componentKey) {
967
- const plugin = this.getPluginInstance(integrationKey);
968
- if (plugin) {
969
- const component = plugin.components && plugin.components.find(
970
- (c2) => c2.key.toLowerCase() === componentKey.toLowerCase()
971
- );
972
- if (component) {
973
- return component.schema || {};
974
- }
975
- }
976
- return {};
977
- }
978
- getScreen(integrationKey, screenPath) {
979
- if (integrationKey) {
980
- const plugin = this.getPluginInstance(integrationKey);
981
- if (plugin) {
982
- const component = plugin.screens && plugin.screens.find(
983
- (s2) => s2.path.toLowerCase() === screenPath.toLowerCase()
984
- );
985
- if (!component) {
986
- return;
987
- }
988
- return component.element({ plugin });
989
- }
990
- }
991
- }
992
- getBoard(integrationKey, boardKey) {
993
- if (integrationKey) {
994
- const plugin = this.getPluginInstance(integrationKey);
995
- if (plugin) {
996
- const component = plugin.boards && plugin.boards.find(
997
- (c2) => c2.key.toLowerCase() === boardKey.toLowerCase()
998
- );
999
- if (!component) {
1000
- return;
1001
- }
1002
- return component.element({ plugin });
1003
- }
1004
- }
1005
- }
1006
- }
1007
- const api = new Api();
1008
- window.__dek_api = api;
1009
- function usePluginApi() {
1010
- return window.__dek_api;
1011
- }
1012
- function usePluginState(plugin, key, defaultValue) {
1013
- const state2 = useState(plugin);
1014
- let value;
1015
- if (state2 && state2[key]) {
1016
- value = state2[key];
1017
- if (isJsonString(value)) {
1018
- value = tryParseJson(value, defaultValue);
1019
- }
1020
- } else {
1021
- value = defaultValue;
1022
- }
1023
- return [
1024
- value,
1025
- (newValue) => {
1026
- if (typeof newValue === "object") {
1027
- newValue = JSON.stringify(newValue);
1028
- }
1029
- setState(plugin, key, newValue);
1030
- }
1031
- ];
1032
- }
1033
- function __debug() {
1034
- }
1035
- const dekPluginModule = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
1036
- __proto__: null,
1037
- __debug,
1038
- usePluginApi,
1039
- usePluginState
1040
- }, Symbol.toStringTag, { value: "Module" }));
1041
723
  var _8 = Object.defineProperty;
1042
724
  var P8 = (t2, r4, e4) => r4 in t2 ? _8(t2, r4, { enumerable: true, configurable: true, writable: true, value: e4 }) : t2[r4] = e4;
1043
725
  var h0 = (t2, r4, e4) => (P8(t2, typeof r4 != "symbol" ? r4 + "" : r4, e4), e4);
@@ -42122,6 +41804,9 @@ Arguments: ` + Array.prototype.slice.call(h2).join("") + `
42122
41804
  })(reactJsxParser_min);
42123
41805
  var reactJsxParser_minExports = reactJsxParser_min.exports;
42124
41806
  const JsxParser = /* @__PURE__ */ getDefaultExportFromCjs(reactJsxParser_minExports);
41807
+ function getPluginApi(integrationKey = "base") {
41808
+ return window.__dek_api_factory(integrationKey);
41809
+ }
42125
41810
  function isNumeric(str) {
42126
41811
  if (typeof str != "string") {
42127
41812
  return false;
@@ -42158,7 +41843,7 @@ Arguments: ` + Array.prototype.slice.call(h2).join("") + `
42158
41843
  return finalProps;
42159
41844
  };
42160
41845
  const Zone = (props) => {
42161
- const api2 = usePluginApi();
41846
+ const api2 = getPluginApi();
42162
41847
  let label = "";
42163
41848
  if (props.id) {
42164
41849
  label = `${props.id}`;
@@ -42251,8 +41936,7 @@ Arguments: ` + Array.prototype.slice.call(h2).join("") + `
42251
41936
  }
42252
41937
  );
42253
41938
  };
42254
- const Board = ({ layout }) => {
42255
- const api2 = usePluginApi();
41939
+ const Board = ({ api: api2, layout }) => {
42256
41940
  return /* @__PURE__ */ jsxRuntimeExports.jsx(LayoutRenderer, { layout: layout || api2.layout });
42257
41941
  };
42258
41942
  const e = Symbol(), t = Symbol(), r = "a", n = "w";
@@ -58228,6 +57912,407 @@ Arguments: ` + Array.prototype.slice.call(h2).join("") + `
58228
57912
  updateStateData(userData);
58229
57913
  updateStateLoading(false);
58230
57914
  }
57915
+ var __defProp2 = Object.defineProperty;
57916
+ var __defNormalProp2 = (obj, key, value) => key in obj ? __defProp2(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
57917
+ var __publicField2 = (obj, key, value) => {
57918
+ __defNormalProp2(obj, typeof key !== "symbol" ? key + "" : key, value);
57919
+ return value;
57920
+ };
57921
+ function useEventCallback$1(fn2) {
57922
+ const ref = React$3.useRef(() => {
57923
+ throw new Error("Cannot call an event handler while rendering.");
57924
+ });
57925
+ useIsomorphicLayoutEffect$2(() => {
57926
+ ref.current = fn2;
57927
+ }, [fn2]);
57928
+ return React$3.useCallback((...args) => ref.current(...args), [ref]);
57929
+ }
57930
+ function useEventListener$1(eventName, handler, element, options) {
57931
+ const savedHandler = React$3.useRef(handler);
57932
+ useIsomorphicLayoutEffect$2(() => {
57933
+ savedHandler.current = handler;
57934
+ }, [handler]);
57935
+ React$3.useEffect(() => {
57936
+ var _a2;
57937
+ const targetElement = (_a2 = element === null || element === void 0 ? void 0 : element.current) !== null && _a2 !== void 0 ? _a2 : window;
57938
+ if (!(targetElement && targetElement.addEventListener))
57939
+ return;
57940
+ const listener = (event) => savedHandler.current(event);
57941
+ targetElement.addEventListener(eventName, listener, options);
57942
+ return () => {
57943
+ targetElement.removeEventListener(eventName, listener, options);
57944
+ };
57945
+ }, [eventName, element, options]);
57946
+ }
57947
+ const useIsomorphicLayoutEffect$2 = typeof window !== "undefined" ? React$3.useLayoutEffect : React$3.useEffect;
57948
+ function useLocalStorage$1(key, initialValue) {
57949
+ const readValue = React$3.useCallback(() => {
57950
+ if (typeof window === "undefined") {
57951
+ return initialValue;
57952
+ }
57953
+ try {
57954
+ const item = window.localStorage.getItem(key);
57955
+ return item ? parseJSON$1(item) : initialValue;
57956
+ } catch (error2) {
57957
+ console.warn(`Error reading localStorage key “${key}”:`, error2);
57958
+ return initialValue;
57959
+ }
57960
+ }, [initialValue, key]);
57961
+ const [storedValue, setStoredValue] = React$3.useState(readValue);
57962
+ const setValue = useEventCallback$1((value) => {
57963
+ if (typeof window === "undefined") {
57964
+ console.warn(`Tried setting localStorage key “${key}” even though environment is not a client`);
57965
+ }
57966
+ try {
57967
+ const newValue = value instanceof Function ? value(storedValue) : value;
57968
+ window.localStorage.setItem(key, JSON.stringify(newValue));
57969
+ setStoredValue(newValue);
57970
+ window.dispatchEvent(new Event("local-storage"));
57971
+ } catch (error2) {
57972
+ console.warn(`Error setting localStorage key “${key}”:`, error2);
57973
+ }
57974
+ });
57975
+ React$3.useEffect(() => {
57976
+ setStoredValue(readValue());
57977
+ }, []);
57978
+ const handleStorageChange = React$3.useCallback((event) => {
57979
+ if ((event === null || event === void 0 ? void 0 : event.key) && event.key !== key) {
57980
+ return;
57981
+ }
57982
+ setStoredValue(readValue());
57983
+ }, [key, readValue]);
57984
+ useEventListener$1("storage", handleStorageChange);
57985
+ useEventListener$1("local-storage", handleStorageChange);
57986
+ return [storedValue, setValue];
57987
+ }
57988
+ function parseJSON$1(value) {
57989
+ try {
57990
+ return value === "undefined" ? void 0 : JSON.parse(value !== null && value !== void 0 ? value : "");
57991
+ } catch (_a2) {
57992
+ console.log("parsing error on", { value });
57993
+ return void 0;
57994
+ }
57995
+ }
57996
+ function extractErrorMessage$1(err) {
57997
+ return err instanceof Error ? err.message : JSON.stringify(err);
57998
+ }
57999
+ function setState(integrationKey, key, value) {
58000
+ const localData = getStateRoot(integrationKey);
58001
+ localData[key] = value;
58002
+ localStorage.setItem(
58003
+ `api:${integrationKey.toLowerCase()}`,
58004
+ JSON.stringify(localData)
58005
+ );
58006
+ window.dispatchEvent(new Event("local-storage"));
58007
+ }
58008
+ function getState(integrationKey, key) {
58009
+ const localData = getStateRoot(integrationKey);
58010
+ return localData[key];
58011
+ }
58012
+ function getStateRoot(integrationKey) {
58013
+ const local = localStorage.getItem(`api:${integrationKey.toLowerCase()}`);
58014
+ return tryParseJson(local || "{}");
58015
+ }
58016
+ function tryParseJson(jsonString, defaultValue = {}) {
58017
+ try {
58018
+ return JSON.parse(jsonString);
58019
+ } catch (err) {
58020
+ console.warn(`Failed parsing JSON: ${extractErrorMessage$1(err)}`);
58021
+ return defaultValue;
58022
+ }
58023
+ }
58024
+ function useState(plugin) {
58025
+ const [state2] = useLocalStorage$1(`api:${plugin.toLowerCase()}`, "{}");
58026
+ return state2;
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
+ class Api {
58044
+ constructor(integrationKey) {
58045
+ __publicField2(this, "integrationKey");
58046
+ this.integrationKey = integrationKey;
58047
+ }
58048
+ get internal() {
58049
+ return window.__dek_api;
58050
+ }
58051
+ trace(message, ...data) {
58052
+ this.internal.trace(this.integrationKey, message, ...data);
58053
+ }
58054
+ warn(message, ...data) {
58055
+ this.internal.warn(this.integrationKey, message, ...data);
58056
+ }
58057
+ error(message, ...data) {
58058
+ this.internal.error(this.integrationKey, message, ...data);
58059
+ }
58060
+ messages() {
58061
+ return this.internal.messages();
58062
+ }
58063
+ plugin(name) {
58064
+ return this.internal.plugin(name);
58065
+ }
58066
+ get registry() {
58067
+ return this.internal.registry;
58068
+ }
58069
+ get boardKey() {
58070
+ return this.internal.boardKey;
58071
+ }
58072
+ get boards() {
58073
+ return this.internal.boards;
58074
+ }
58075
+ get board() {
58076
+ return this.internal.board;
58077
+ }
58078
+ get layout() {
58079
+ return this.internal.layout;
58080
+ }
58081
+ get commandGroups() {
58082
+ return this.internal.commandGroups;
58083
+ }
58084
+ navigate(path) {
58085
+ this.internal.navigate(path);
58086
+ }
58087
+ get navigateParams() {
58088
+ return this.internal.navigateParams;
58089
+ }
58090
+ navigateBack() {
58091
+ this.internal.navigateBack();
58092
+ }
58093
+ open(boardKey) {
58094
+ this.internal.open(boardKey);
58095
+ }
58096
+ get plugins() {
58097
+ return this.internal.plugins;
58098
+ }
58099
+ get api() {
58100
+ return this.plugin(this.integrationKey).api;
58101
+ }
58102
+ get state() {
58103
+ return this.plugin(this.integrationKey).state;
58104
+ }
58105
+ get info() {
58106
+ return this.plugin(this.integrationKey).info;
58107
+ }
58108
+ component(key, props) {
58109
+ return this.plugin(this.integrationKey).component(key, props);
58110
+ }
58111
+ componentSchema(key) {
58112
+ return this.plugin(this.integrationKey).componentSchema(key);
58113
+ }
58114
+ screen(path) {
58115
+ return this.plugin(this.integrationKey).screen(path);
58116
+ }
58117
+ }
58118
+ class ApiInternal {
58119
+ trace(integrationKey, message, ...data) {
58120
+ console.log(`DEK-TRACE[${integrationKey}]: ${message}`, ...data);
58121
+ this.globals.messages.push({
58122
+ type: "trace",
58123
+ body: message,
58124
+ data,
58125
+ at: Date.now()
58126
+ });
58127
+ }
58128
+ warn(integrationKey, message, ...data) {
58129
+ console.warn(`DEK-WARN[${integrationKey}]: ${message}`, ...data);
58130
+ this.globals.messages.push({
58131
+ type: "error",
58132
+ body: message,
58133
+ data,
58134
+ at: Date.now()
58135
+ });
58136
+ }
58137
+ error(integrationKey, message, ...data) {
58138
+ console.error(`DEK-ERROR[${integrationKey}]: ${message}`, ...data);
58139
+ this.globals.messages.push({
58140
+ type: "error",
58141
+ body: message,
58142
+ data,
58143
+ at: Date.now()
58144
+ });
58145
+ }
58146
+ messages() {
58147
+ return this.globals.messages;
58148
+ }
58149
+ plugin(name) {
58150
+ return this.createPluginWrapper(name);
58151
+ }
58152
+ get registry() {
58153
+ return this.globals.registry;
58154
+ }
58155
+ get boardKey() {
58156
+ return this.globals.navigateParams.boardKey || "#error";
58157
+ }
58158
+ get boards() {
58159
+ return this.globals.boards;
58160
+ }
58161
+ get board() {
58162
+ return this.boards.find((board) => board.key === this.boardKey) || {
58163
+ zones: []
58164
+ };
58165
+ }
58166
+ get layout() {
58167
+ return this.board.layout || `<Screen><Text>Missing layout</Text></Screen>`;
58168
+ }
58169
+ get commandGroups() {
58170
+ return this.globals.commandGroups;
58171
+ }
58172
+ navigate(path) {
58173
+ this.globals.setLocation(`/${this.boardKey}${path}`);
58174
+ }
58175
+ get navigateParams() {
58176
+ return this.globals.navigateParams;
58177
+ }
58178
+ navigateBack() {
58179
+ history.back();
58180
+ }
58181
+ open(boardKey) {
58182
+ this.globals.setLocation(`/${boardKey}`);
58183
+ }
58184
+ createPluginWrapper(integrationKey) {
58185
+ const plugin = this.getPluginInstance(integrationKey);
58186
+ const available = !!plugin;
58187
+ return {
58188
+ available,
58189
+ info: {
58190
+ components: (plugin == null ? void 0 : plugin.components) ? plugin.components.map((component) => component.key) : [],
58191
+ screens: (plugin == null ? void 0 : plugin.screens) ? plugin.screens.map((screen) => screen.path) : []
58192
+ },
58193
+ component: (key, props) => this.getComponent(integrationKey, key, props),
58194
+ componentSchema: (key) => this.getComponentSchema(integrationKey, key),
58195
+ screen: (path) => this.getScreen(integrationKey, path),
58196
+ board: (key) => this.getBoard(integrationKey, key),
58197
+ api: (plugin == null ? void 0 : plugin.api) || {},
58198
+ state: {
58199
+ get: (key, defaultValue) => {
58200
+ if (!available) {
58201
+ return defaultValue;
58202
+ }
58203
+ return getState(integrationKey, key) || defaultValue;
58204
+ },
58205
+ set: (key, value) => {
58206
+ if (!available) {
58207
+ return;
58208
+ }
58209
+ setState(integrationKey, key, value);
58210
+ }
58211
+ }
58212
+ };
58213
+ }
58214
+ get globals() {
58215
+ return window.__dek_globals;
58216
+ }
58217
+ get plugins() {
58218
+ const plugins = {};
58219
+ Object.keys(this.globals.pluginInstances).forEach((key) => {
58220
+ plugins[key] = this.createPluginWrapper(key);
58221
+ });
58222
+ return plugins;
58223
+ }
58224
+ getPluginInstance(integrationKey) {
58225
+ return this.globals.pluginInstances[integrationKey];
58226
+ }
58227
+ getComponent(integrationKey, componentKey, props) {
58228
+ const plugin = this.getPluginInstance(integrationKey);
58229
+ if (plugin) {
58230
+ const component = plugin.components && plugin.components.find(
58231
+ (c2) => c2.key.toLowerCase() === componentKey.toLowerCase()
58232
+ );
58233
+ if (!component) {
58234
+ return;
58235
+ }
58236
+ return component.element({
58237
+ ...props,
58238
+ plugin,
58239
+ api: new Api(integrationKey)
58240
+ });
58241
+ }
58242
+ }
58243
+ getComponentSchema(integrationKey, componentKey) {
58244
+ const plugin = this.getPluginInstance(integrationKey);
58245
+ if (plugin) {
58246
+ const component = plugin.components && plugin.components.find(
58247
+ (c2) => c2.key.toLowerCase() === componentKey.toLowerCase()
58248
+ );
58249
+ if (component) {
58250
+ return component.schema || {};
58251
+ }
58252
+ }
58253
+ return {};
58254
+ }
58255
+ getScreen(integrationKey, screenPath) {
58256
+ if (integrationKey) {
58257
+ const plugin = this.getPluginInstance(integrationKey);
58258
+ if (plugin) {
58259
+ const component = plugin.screens && plugin.screens.find(
58260
+ (s2) => s2.path.toLowerCase() === screenPath.toLowerCase()
58261
+ );
58262
+ if (!component) {
58263
+ return;
58264
+ }
58265
+ return component.element({ plugin, api: new Api(integrationKey) });
58266
+ }
58267
+ }
58268
+ }
58269
+ getBoard(integrationKey, boardKey) {
58270
+ if (integrationKey) {
58271
+ const plugin = this.getPluginInstance(integrationKey);
58272
+ if (plugin) {
58273
+ const component = plugin.boards && plugin.boards.find(
58274
+ (c2) => c2.key.toLowerCase() === boardKey.toLowerCase()
58275
+ );
58276
+ if (!component) {
58277
+ return;
58278
+ }
58279
+ return component.element({ plugin, api: new Api(integrationKey) });
58280
+ }
58281
+ }
58282
+ }
58283
+ }
58284
+ const api = new ApiInternal();
58285
+ window.__dek_api = api;
58286
+ window.__dek_api_factory = (integrationKey) => new Api(integrationKey);
58287
+ function usePluginState(api2, key, defaultValue) {
58288
+ const integrationKey = api2.integrationKey;
58289
+ const state2 = useState(integrationKey);
58290
+ let value;
58291
+ if (state2 && state2[key]) {
58292
+ value = state2[key];
58293
+ if (isJsonString(value)) {
58294
+ value = tryParseJson(value, defaultValue);
58295
+ }
58296
+ } else {
58297
+ value = defaultValue;
58298
+ }
58299
+ return [
58300
+ value,
58301
+ (newValue) => {
58302
+ if (typeof newValue === "object") {
58303
+ newValue = JSON.stringify(newValue);
58304
+ }
58305
+ setState(integrationKey, key, newValue);
58306
+ }
58307
+ ];
58308
+ }
58309
+ function __debug() {
58310
+ }
58311
+ const dekPluginModule = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
58312
+ __proto__: null,
58313
+ __debug,
58314
+ usePluginState
58315
+ }, Symbol.toStringTag, { value: "Module" }));
58231
58316
  const USER_PLUGIN_AND_INTEGRATIONS_QUERY = gql(`
58232
58317
  query userPluginsAndIntegrations {
58233
58318
  currentUser {
@@ -58257,7 +58342,7 @@ Arguments: ` + Array.prototype.slice.call(h2).join("") + `
58257
58342
  result.integrations.push({
58258
58343
  key: "base",
58259
58344
  pluginName: "base",
58260
- pluginVersion: "0.10.0",
58345
+ pluginVersion: "0.11.0",
58261
58346
  pluginConfig: []
58262
58347
  });
58263
58348
  return result;
@@ -58370,7 +58455,7 @@ Arguments: ` + Array.prototype.slice.call(h2).join("") + `
58370
58455
  return /* @__PURE__ */ jsxRuntimeExports.jsx(Container$9, { "aria-label": "weather-icon", $top: info.top, $left: info.left, children: info.element });
58371
58456
  };
58372
58457
  const WeatherComponent = () => {
58373
- const api2 = usePluginApi();
58458
+ const api2 = getPluginApi();
58374
58459
  const entities = useEntities();
58375
58460
  const [weatherData, setWeatherData] = React$3.useState();
58376
58461
  const data = transformWeatherData(entities["weather.forecast_home"]);
@@ -58432,16 +58517,15 @@ Arguments: ` + Array.prototype.slice.call(h2).join("") + `
58432
58517
  };
58433
58518
  const About = () => {
58434
58519
  return /* @__PURE__ */ jsxRuntimeExports.jsxs(x0, { padding: 20, direction: "vert", children: [
58435
- /* @__PURE__ */ jsxRuntimeExports.jsx(hF1, { children: `Dek ${"0.10.0"}` }),
58520
+ /* @__PURE__ */ jsxRuntimeExports.jsx(hF1, { children: `Dek ${"0.11.0"}` }),
58436
58521
  /* @__PURE__ */ jsxRuntimeExports.jsx(X4, { children: "From Appkit" })
58437
58522
  ] });
58438
58523
  };
58439
- const Backgrounds = () => {
58440
- const [backgroundKey] = usePluginState("base", "backgroundKey", "image");
58524
+ const Backgrounds = ({ api: api2 }) => {
58525
+ const [backgroundKey] = usePluginState(api2, "backgroundKey", "image");
58441
58526
  const propsKey = `backgroundProps-${backgroundKey}`;
58442
- const [backgroundProps] = usePluginState("base", propsKey, {});
58527
+ const [backgroundProps] = usePluginState(api2, propsKey, {});
58443
58528
  const [selectedKey, setSelectedKey] = React$3.useState(backgroundKey);
58444
- const api2 = usePluginApi();
58445
58529
  const backgrounds = api2.registry.collection("backgrounds");
58446
58530
  const backgroundItems = backgrounds.items;
58447
58531
  const backgroundPropsSchema = backgroundItems[selectedKey].props;
@@ -58539,8 +58623,7 @@ Arguments: ` + Array.prototype.slice.call(h2).join("") + `
58539
58623
  }) })
58540
58624
  ] });
58541
58625
  };
58542
- const Boards = () => {
58543
- const api2 = usePluginApi();
58626
+ const Boards = ({ api: api2 }) => {
58544
58627
  const boards = api2.boards;
58545
58628
  console.log("boards", boards);
58546
58629
  const openBoard = (boardKey) => {
@@ -58558,8 +58641,7 @@ Arguments: ` + Array.prototype.slice.call(h2).join("") + `
58558
58641
  ) }, key)) })
58559
58642
  ] });
58560
58643
  };
58561
- const Messages = () => {
58562
- const api2 = usePluginApi();
58644
+ const Messages = ({ api: api2 }) => {
58563
58645
  return /* @__PURE__ */ jsxRuntimeExports.jsx(x0, { direction: "vert", vscroll: "auto", paddingTop: 20, children: api2.messages().map((msg, idx) => /* @__PURE__ */ jsxRuntimeExports.jsx(
58564
58646
  X4,
58565
58647
  {
@@ -58570,8 +58652,7 @@ Arguments: ` + Array.prototype.slice.call(h2).join("") + `
58570
58652
  idx
58571
58653
  )) });
58572
58654
  };
58573
- const PluginDev = () => {
58574
- const api2 = usePluginApi();
58655
+ const PluginDev = ({ api: api2 }) => {
58575
58656
  const plugin = api2.plugin("plugin");
58576
58657
  return /* @__PURE__ */ jsxRuntimeExports.jsxs(x0, { children: [
58577
58658
  /* @__PURE__ */ jsxRuntimeExports.jsxs(x0, { padding: 20, collapse: true, direction: "vert", children: [
@@ -58605,9 +58686,9 @@ Arguments: ` + Array.prototype.slice.call(h2).join("") + `
58605
58686
  ) })
58606
58687
  ] });
58607
58688
  };
58608
- const Theme = () => {
58689
+ const Theme = ({ api: api2 }) => {
58609
58690
  const [selectedKey, setSelectedKey] = React$3.useState("tile");
58610
- const [themeState, setThemeState] = usePluginState("base", "theme", {});
58691
+ const [themeState, setThemeState] = usePluginState(api2, "theme", {});
58611
58692
  const handleSelection = (key) => {
58612
58693
  setSelectedKey(key);
58613
58694
  };
@@ -58686,8 +58767,7 @@ Arguments: ` + Array.prototype.slice.call(h2).join("") + `
58686
58767
  ] })
58687
58768
  ] });
58688
58769
  };
58689
- const SettingsScreen = ({ isPluginDev }) => {
58690
- const api2 = usePluginApi();
58770
+ const SettingsScreen = ({ api: api2, isPluginDev }) => {
58691
58771
  const isPrivatePluginDev = !isPluginDev && api2.plugin("plugin").available;
58692
58772
  const [selectedKey, setSelectedKey] = React$3.useState(
58693
58773
  isPluginDev ? "plugin-dev" : "boards"
@@ -58736,18 +58816,18 @@ Arguments: ` + Array.prototype.slice.call(h2).join("") + `
58736
58816
  initialKey: selectedKey
58737
58817
  }
58738
58818
  ),
58739
- selectedKey === "plugin-dev" && /* @__PURE__ */ jsxRuntimeExports.jsx(PluginDev, {}),
58740
- selectedKey === "backgrounds" && /* @__PURE__ */ jsxRuntimeExports.jsx(Backgrounds, {}),
58741
- selectedKey === "theme" && /* @__PURE__ */ jsxRuntimeExports.jsx(Theme, {}),
58742
- selectedKey === "messages" && /* @__PURE__ */ jsxRuntimeExports.jsx(Messages, {}),
58819
+ selectedKey === "plugin-dev" && /* @__PURE__ */ jsxRuntimeExports.jsx(PluginDev, { api: api2 }),
58820
+ selectedKey === "backgrounds" && /* @__PURE__ */ jsxRuntimeExports.jsx(Backgrounds, { api: api2 }),
58821
+ selectedKey === "theme" && /* @__PURE__ */ jsxRuntimeExports.jsx(Theme, { api: api2 }),
58822
+ selectedKey === "messages" && /* @__PURE__ */ jsxRuntimeExports.jsx(Messages, { api: api2 }),
58743
58823
  selectedKey === "about" && /* @__PURE__ */ jsxRuntimeExports.jsx(About, {}),
58744
- selectedKey === "boards" && /* @__PURE__ */ jsxRuntimeExports.jsx(Boards, {})
58824
+ selectedKey === "boards" && /* @__PURE__ */ jsxRuntimeExports.jsx(Boards, { api: api2 })
58745
58825
  ] }),
58746
58826
  /* @__PURE__ */ jsxRuntimeExports.jsx(_G1, { title, noclose: isPluginDev })
58747
58827
  ] });
58748
58828
  };
58749
- const DevBoard = () => {
58750
- return /* @__PURE__ */ jsxRuntimeExports.jsx(SettingsScreen, { isPluginDev: true });
58829
+ const DevBoard = (props) => {
58830
+ return /* @__PURE__ */ jsxRuntimeExports.jsx(SettingsScreen, { isPluginDev: true, ...props });
58751
58831
  };
58752
58832
  const EmptyBoard = () => {
58753
58833
  return /* @__PURE__ */ jsxRuntimeExports.jsx(OG1, { overlay: true, children: /* @__PURE__ */ jsxRuntimeExports.jsx(x0, { paddingTop: 100, paddingHorz: 20, collapse: true, children: /* @__PURE__ */ jsxRuntimeExports.jsx(
@@ -58761,8 +58841,8 @@ Arguments: ` + Array.prototype.slice.call(h2).join("") + `
58761
58841
  }
58762
58842
  ) }) });
58763
58843
  };
58764
- const MainBoard = () => {
58765
- return /* @__PURE__ */ jsxRuntimeExports.jsx(Board, {});
58844
+ const MainBoard = (props) => {
58845
+ return /* @__PURE__ */ jsxRuntimeExports.jsx(Board, { ...props });
58766
58846
  };
58767
58847
  //! moment.js
58768
58848
  //! version : 2.29.4
@@ -62730,8 +62810,7 @@ Arguments: ` + Array.prototype.slice.call(h2).join("") + `
62730
62810
  "Time to rest"
62731
62811
  ]
62732
62812
  };
62733
- const Greeting = () => {
62734
- const api2 = usePluginApi();
62813
+ const Greeting = ({ api: api2 }) => {
62735
62814
  const calendarPlugin = api2.plugin("calendar");
62736
62815
  const events2 = calendarPlugin.api.useEvents();
62737
62816
  const getGreeting = () => {
@@ -63044,8 +63123,7 @@ Arguments: ` + Array.prototype.slice.call(h2).join("") + `
63044
63123
  opacity = opacity === void 0 ? background.opacity : opacity;
63045
63124
  return /* @__PURE__ */ jsxRuntimeExports.jsx(Container$3, { "aria-label": "background", $imageUrl: background.uri, children: /* @__PURE__ */ jsxRuntimeExports.jsx(Overlay, { $opacity: opacity || 0 }) });
63046
63125
  };
63047
- const AboutScreen = () => {
63048
- const api2 = usePluginApi();
63126
+ const AboutScreen = ({ api: api2 }) => {
63049
63127
  return /* @__PURE__ */ jsxRuntimeExports.jsxs(OG1, { overlay: true, children: [
63050
63128
  /* @__PURE__ */ jsxRuntimeExports.jsx(_G1, { title: "About" }),
63051
63129
  /* @__PURE__ */ jsxRuntimeExports.jsx(x0, { paddingTop: 100, paddingHorz: 20, collapse: true, children: /* @__PURE__ */ jsxRuntimeExports.jsx(
@@ -89668,9 +89746,8 @@ Arguments: ` + Array.prototype.slice.call(h2).join("") + `
89668
89746
  const AceEditorStyled = styled(_default)`
89669
89747
  background: #ffffff66;
89670
89748
  `;
89671
- const ComponentScreen = () => {
89749
+ const ComponentScreen = ({ api: api2 }) => {
89672
89750
  const params = useParams();
89673
- const api2 = usePluginApi();
89674
89751
  const [propsString, setPropsString] = useLocalStorage(
89675
89752
  "component-" + params.componentKey,
89676
89753
  ""
@@ -89965,15 +90042,15 @@ Arguments: ` + Array.prototype.slice.call(h2).join("") + `
89965
90042
  return [
89966
90043
  {
89967
90044
  path: "/settings",
89968
- element: () => /* @__PURE__ */ jsxRuntimeExports.jsx(SettingsScreen, {})
90045
+ element: (props) => /* @__PURE__ */ jsxRuntimeExports.jsx(SettingsScreen, { ...props })
89969
90046
  },
89970
90047
  {
89971
90048
  path: "/about",
89972
- element: () => /* @__PURE__ */ jsxRuntimeExports.jsx(AboutScreen, {})
90049
+ element: (props) => /* @__PURE__ */ jsxRuntimeExports.jsx(AboutScreen, { ...props })
89973
90050
  },
89974
90051
  {
89975
90052
  path: "/dev/component/:componentKey",
89976
- element: () => /* @__PURE__ */ jsxRuntimeExports.jsx(ComponentScreen, {})
90053
+ element: (props) => /* @__PURE__ */ jsxRuntimeExports.jsx(ComponentScreen, { ...props })
89977
90054
  }
89978
90055
  ];
89979
90056
  }
@@ -90005,11 +90082,11 @@ Arguments: ` + Array.prototype.slice.call(h2).join("") + `
90005
90082
  return [
90006
90083
  {
90007
90084
  key: "main",
90008
- element: () => /* @__PURE__ */ jsxRuntimeExports.jsx(MainBoard, {})
90085
+ element: (props) => /* @__PURE__ */ jsxRuntimeExports.jsx(MainBoard, { ...props })
90009
90086
  },
90010
90087
  {
90011
90088
  key: "dev",
90012
- element: () => /* @__PURE__ */ jsxRuntimeExports.jsx(DevBoard, {})
90089
+ element: (props) => /* @__PURE__ */ jsxRuntimeExports.jsx(DevBoard, { ...props })
90013
90090
  },
90014
90091
  {
90015
90092
  key: "empty",
@@ -93624,13 +93701,13 @@ Arguments: ` + Array.prototype.slice.call(h2).join("") + `
93624
93701
  styled(x0)`
93625
93702
  color: red;
93626
93703
  `;
93627
- const MediaView = ({ entityId, showLargeContent = false }) => {
93704
+ const MediaView = ({ api: api2, entityId, showLargeContent = false }) => {
93628
93705
  const entity = useEntity(entityId);
93629
93706
  const [loading, setLoading] = React$3.useState(false);
93630
93707
  const [coverArtUrl, setCoverArtUrl] = React$3.useState("");
93631
93708
  const [playingState, setPLayingState] = React$3.useState("");
93632
93709
  const [lastAlbumArt, setLastAlbumArt] = usePluginState(
93633
- "home-assistant",
93710
+ api2,
93634
93711
  "last-album-art",
93635
93712
  ""
93636
93713
  );
@@ -93816,14 +93893,14 @@ Arguments: ` + Array.prototype.slice.call(h2).join("") + `
93816
93893
  }
93817
93894
  return new plugin(pluginConfigMerged, registry);
93818
93895
  }
93819
- async function initializePluginInstance(pluginInstance) {
93896
+ async function initializePluginInstance(pluginInstance, integrationKey) {
93820
93897
  if (pluginInstance && pluginInstance.load) {
93821
- await pluginInstance.load(window.__dek_api);
93898
+ await pluginInstance.load(getPluginApi(integrationKey));
93822
93899
  }
93823
93900
  }
93824
93901
  async function initializePluginInstances() {
93825
93902
  for (const key of Object.keys(loadedDekPluginInstances)) {
93826
- await initializePluginInstance(loadedDekPluginInstances[key]);
93903
+ await initializePluginInstance(loadedDekPluginInstances[key], key);
93827
93904
  }
93828
93905
  }
93829
93906
  async function loadPlugins({
@@ -93904,9 +93981,9 @@ Arguments: ` + Array.prototype.slice.call(h2).join("") + `
93904
93981
  async function updateLocalPlugin(plugin, pluginConfig) {
93905
93982
  updateStateLoading(true);
93906
93983
  const integration = {
93907
- pluginName: "local",
93984
+ pluginName: "plugin",
93908
93985
  pluginVersion: "latest",
93909
- key: "local",
93986
+ key: "plugin",
93910
93987
  pluginConfig: []
93911
93988
  };
93912
93989
  loadedLocalPlugin = plugin;
@@ -93916,7 +93993,7 @@ Arguments: ` + Array.prototype.slice.call(h2).join("") + `
93916
93993
  pluginConfig
93917
93994
  );
93918
93995
  if (loadedLocalPluginInstance && loadedLocalPluginInstance.load) {
93919
- await loadedLocalPluginInstance.load(window.__dek_api);
93996
+ await loadedLocalPluginInstance.load(getPluginApi("plugin"));
93920
93997
  }
93921
93998
  updateStatePlugins(getAllPlugins(), getAllPluginInstances());
93922
93999
  updateStateLoading(false);
@@ -93960,10 +94037,10 @@ Arguments: ` + Array.prototype.slice.call(h2).join("") + `
93960
94037
  return userConfig;
93961
94038
  }
93962
94039
  const Background = () => {
93963
- const api2 = usePluginApi();
93964
- const [backgroundKey] = usePluginState("base", "backgroundKey", "image");
94040
+ const api2 = getPluginApi();
94041
+ const [backgroundKey] = usePluginState(api2, "backgroundKey", "image");
93965
94042
  const propsKey = `backgroundProps-${backgroundKey}`;
93966
- const [backgroundProps] = usePluginState("base", propsKey, {});
94043
+ const [backgroundProps] = usePluginState(api2, propsKey, {});
93967
94044
  const backgrounds = api2.registry.collection("backgrounds");
93968
94045
  if (backgrounds && backgrounds.items && backgrounds.items[backgroundKey]) {
93969
94046
  return backgrounds.items[backgroundKey].component(backgroundProps);
@@ -94906,7 +94983,7 @@ Arguments: ` + Array.prototype.slice.call(h2).join("") + `
94906
94983
  };
94907
94984
  const SwitchTransition$1 = SwitchTransition;
94908
94985
  const RouteResolver = ({ route }) => {
94909
- const api2 = usePluginApi();
94986
+ const api2 = getPluginApi();
94910
94987
  const resolveRouteElement = (route2) => {
94911
94988
  if (route2.type === "screen") {
94912
94989
  return api2.plugin(route2.plugin).screen(route2.path);
@@ -95145,7 +95222,8 @@ body {
95145
95222
 
95146
95223
  `;
95147
95224
  const BoardStyles = ({ transitionDelay: transitionDelay2 }) => {
95148
- const [themeState] = usePluginState("base", "theme", {});
95225
+ const api2 = getPluginApi();
95226
+ const [themeState] = usePluginState(api2, "theme", {});
95149
95227
  return /* @__PURE__ */ jsxRuntimeExports.jsxs(jsxRuntimeExports.Fragment, { children: [
95150
95228
  /* @__PURE__ */ jsxRuntimeExports.jsx(wG1, {}),
95151
95229
  /* @__PURE__ */ jsxRuntimeExports.jsx(
@@ -95179,7 +95257,7 @@ body {
95179
95257
  margin-top: 10px;
95180
95258
  `;
95181
95259
  const CommandGroup = ({ groupKey }) => {
95182
- const api2 = usePluginApi();
95260
+ const api2 = getPluginApi();
95183
95261
  const group = api2.commandGroups.find(
95184
95262
  (g) => g.key == groupKey
95185
95263
  );