@vonaffenfels/contentful-slate-editor 1.0.33 → 1.0.35
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/package.json +3 -3
- package/src/components/EditorField.js +56 -31
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vonaffenfels/contentful-slate-editor",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.35",
|
|
4
4
|
"scripts": {
|
|
5
5
|
"prepublish": "yarn run build",
|
|
6
6
|
"dev": "yarn run start",
|
|
@@ -89,10 +89,10 @@
|
|
|
89
89
|
"webpack-dev-server": "^4.0.0-beta.2"
|
|
90
90
|
},
|
|
91
91
|
"dependencies": {
|
|
92
|
-
"@vonaffenfels/slate-editor": "^1.0.
|
|
92
|
+
"@vonaffenfels/slate-editor": "^1.0.35",
|
|
93
93
|
"webpack": "5.88.2"
|
|
94
94
|
},
|
|
95
|
-
"gitHead": "
|
|
95
|
+
"gitHead": "8531e3bdf7affdda47f286a5786cd7778044f1fc",
|
|
96
96
|
"publishConfig": {
|
|
97
97
|
"access": "public"
|
|
98
98
|
}
|
|
@@ -12,6 +12,8 @@ import storybookStories from "storybookStories";
|
|
|
12
12
|
import componentLoader from "@vonaffenfels/slate-editor/componentLoader";
|
|
13
13
|
|
|
14
14
|
let isLoadingCountGlobal = 0;
|
|
15
|
+
let loaderTimeout;
|
|
16
|
+
let isInitialLoad = true;
|
|
15
17
|
|
|
16
18
|
const EditorField = ({
|
|
17
19
|
fieldSdk,
|
|
@@ -64,6 +66,10 @@ const EditorField = ({
|
|
|
64
66
|
if (windowSdk) {
|
|
65
67
|
windowSdk.startAutoResizer();
|
|
66
68
|
}
|
|
69
|
+
|
|
70
|
+
setTimeout(() => {
|
|
71
|
+
isInitialLoad = false;
|
|
72
|
+
}, 1000);
|
|
67
73
|
}, []);
|
|
68
74
|
|
|
69
75
|
useEffect(() => {
|
|
@@ -92,6 +98,55 @@ const EditorField = ({
|
|
|
92
98
|
fakeActiveContent[field] = entrySdk.fields[field].getValue();
|
|
93
99
|
}
|
|
94
100
|
|
|
101
|
+
const executeLoader = async (block, attributes) => {
|
|
102
|
+
let loaderResult = {};
|
|
103
|
+
|
|
104
|
+
setIsLoadingCount(++isLoadingCountGlobal);
|
|
105
|
+
|
|
106
|
+
try {
|
|
107
|
+
const fetchUrl = `/api/loader/?${new URLSearchParams({
|
|
108
|
+
portal: portal,
|
|
109
|
+
block: block,
|
|
110
|
+
variables: JSON.stringify({
|
|
111
|
+
...attributes,
|
|
112
|
+
entries: null,
|
|
113
|
+
items: null,
|
|
114
|
+
}),
|
|
115
|
+
})}`;
|
|
116
|
+
|
|
117
|
+
loaderResult = await fetch(fetchUrl).then(res => res.json());
|
|
118
|
+
|
|
119
|
+
if (loaderResult) {
|
|
120
|
+
for (let key in loaderResult) {
|
|
121
|
+
attributes[key] = loaderResult[key];
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
} catch (e) {
|
|
125
|
+
console.error(`Error in loader for ${block}`);
|
|
126
|
+
console.error(e);
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
setIsLoadingCount(--isLoadingCountGlobal);
|
|
130
|
+
|
|
131
|
+
return loaderResult;
|
|
132
|
+
};
|
|
133
|
+
|
|
134
|
+
const getLoaderResult = async (block, attributes) => {
|
|
135
|
+
return new Promise((resolve, reject) => {
|
|
136
|
+
if (isInitialLoad) {
|
|
137
|
+
executeLoader(block, attributes).then(result => resolve(result));
|
|
138
|
+
|
|
139
|
+
return;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
clearTimeout(loaderTimeout);
|
|
143
|
+
|
|
144
|
+
loaderTimeout = setTimeout(async () => {
|
|
145
|
+
resolve(await executeLoader(block, attributes));
|
|
146
|
+
}, 1000);
|
|
147
|
+
});
|
|
148
|
+
};
|
|
149
|
+
|
|
95
150
|
return <div ref={wrapperRef} className="editor-field h-full">
|
|
96
151
|
<BlockEditor
|
|
97
152
|
onChange={onChange}
|
|
@@ -102,37 +157,7 @@ const EditorField = ({
|
|
|
102
157
|
storybookComponentLoader={componentLoader}
|
|
103
158
|
storybookStories={storybookStories}
|
|
104
159
|
isLoading={isLoadingCount !== 0}
|
|
105
|
-
storybookComponentDataLoader={async (block, attributes) =>
|
|
106
|
-
let loaderResult = {};
|
|
107
|
-
setIsLoadingCount(++isLoadingCountGlobal);
|
|
108
|
-
|
|
109
|
-
try {
|
|
110
|
-
const fetchUrl = `/api/loader/?${new URLSearchParams({
|
|
111
|
-
portal: portal,
|
|
112
|
-
block: block,
|
|
113
|
-
variables: JSON.stringify({
|
|
114
|
-
...attributes,
|
|
115
|
-
entries: null,
|
|
116
|
-
items: null,
|
|
117
|
-
}),
|
|
118
|
-
})}`;
|
|
119
|
-
|
|
120
|
-
loaderResult = await fetch(fetchUrl).then(res => res.json());
|
|
121
|
-
|
|
122
|
-
if (loaderResult) {
|
|
123
|
-
for (let key in loaderResult) {
|
|
124
|
-
attributes[key] = loaderResult[key];
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
} catch (e) {
|
|
128
|
-
console.error(`Error in loader for ${block}`);
|
|
129
|
-
console.error(e);
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
setIsLoadingCount(--isLoadingCountGlobal);
|
|
133
|
-
|
|
134
|
-
return loaderResult;
|
|
135
|
-
}}
|
|
160
|
+
storybookComponentDataLoader={async (block, attributes) => await getLoaderResult(block, attributes)}
|
|
136
161
|
onStorybookElementClick={onStorybookElementClick}
|
|
137
162
|
/>
|
|
138
163
|
</div>;
|