@vonaffenfels/contentful-slate-editor 1.0.34 → 1.0.41
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 +61 -36
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.41",
|
|
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.41",
|
|
93
93
|
"webpack": "5.88.2"
|
|
94
94
|
},
|
|
95
|
-
"gitHead": "
|
|
95
|
+
"gitHead": "1ad8ddd858ff27ea19e568d79f189f20a2ef0488",
|
|
96
96
|
"publishConfig": {
|
|
97
97
|
"access": "public"
|
|
98
98
|
}
|
|
@@ -13,6 +13,7 @@ import componentLoader from "@vonaffenfels/slate-editor/componentLoader";
|
|
|
13
13
|
|
|
14
14
|
let isLoadingCountGlobal = 0;
|
|
15
15
|
let loaderTimeout;
|
|
16
|
+
let isInitialLoad = true;
|
|
16
17
|
|
|
17
18
|
const EditorField = ({
|
|
18
19
|
fieldSdk,
|
|
@@ -65,6 +66,10 @@ const EditorField = ({
|
|
|
65
66
|
if (windowSdk) {
|
|
66
67
|
windowSdk.startAutoResizer();
|
|
67
68
|
}
|
|
69
|
+
|
|
70
|
+
setTimeout(() => {
|
|
71
|
+
isInitialLoad = false;
|
|
72
|
+
}, 1000);
|
|
68
73
|
}, []);
|
|
69
74
|
|
|
70
75
|
useEffect(() => {
|
|
@@ -93,6 +98,61 @@ const EditorField = ({
|
|
|
93
98
|
fakeActiveContent[field] = entrySdk.fields[field].getValue();
|
|
94
99
|
}
|
|
95
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)
|
|
118
|
+
.then(res => res.json())
|
|
119
|
+
.catch(err => {
|
|
120
|
+
console.error(err);
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
if (loaderResult) {
|
|
124
|
+
for (let key in loaderResult) {
|
|
125
|
+
attributes[key] = loaderResult[key];
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
setIsLoadingCount(--isLoadingCountGlobal);
|
|
130
|
+
} catch (e) {
|
|
131
|
+
console.error(`Error in loader for ${block}`);
|
|
132
|
+
console.error(e);
|
|
133
|
+
|
|
134
|
+
setIsLoadingCount(--isLoadingCountGlobal);
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
return loaderResult;
|
|
138
|
+
};
|
|
139
|
+
|
|
140
|
+
const getLoaderResult = async (block, attributes) => {
|
|
141
|
+
return new Promise((resolve, reject) => {
|
|
142
|
+
if (isInitialLoad) {
|
|
143
|
+
executeLoader(block, attributes).then(result => resolve(result));
|
|
144
|
+
|
|
145
|
+
return;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
clearTimeout(loaderTimeout);
|
|
149
|
+
|
|
150
|
+
loaderTimeout = setTimeout(async () => {
|
|
151
|
+
resolve(await executeLoader(block, attributes));
|
|
152
|
+
}, 1000);
|
|
153
|
+
});
|
|
154
|
+
};
|
|
155
|
+
|
|
96
156
|
return <div ref={wrapperRef} className="editor-field h-full">
|
|
97
157
|
<BlockEditor
|
|
98
158
|
onChange={onChange}
|
|
@@ -103,42 +163,7 @@ const EditorField = ({
|
|
|
103
163
|
storybookComponentLoader={componentLoader}
|
|
104
164
|
storybookStories={storybookStories}
|
|
105
165
|
isLoading={isLoadingCount !== 0}
|
|
106
|
-
storybookComponentDataLoader={async (block, attributes) =>
|
|
107
|
-
let loaderResult = {};
|
|
108
|
-
|
|
109
|
-
clearTimeout(loaderTimeout);
|
|
110
|
-
|
|
111
|
-
loaderTimeout = await setTimeout(async () => {
|
|
112
|
-
setIsLoadingCount(++isLoadingCountGlobal);
|
|
113
|
-
|
|
114
|
-
try {
|
|
115
|
-
const fetchUrl = `/api/loader/?${new URLSearchParams({
|
|
116
|
-
portal: portal,
|
|
117
|
-
block: block,
|
|
118
|
-
variables: JSON.stringify({
|
|
119
|
-
...attributes,
|
|
120
|
-
entries: null,
|
|
121
|
-
items: null,
|
|
122
|
-
}),
|
|
123
|
-
})}`;
|
|
124
|
-
|
|
125
|
-
loaderResult = await fetch(fetchUrl).then(res => res.json());
|
|
126
|
-
|
|
127
|
-
if (loaderResult) {
|
|
128
|
-
for (let key in loaderResult) {
|
|
129
|
-
attributes[key] = loaderResult[key];
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
} catch (e) {
|
|
133
|
-
console.error(`Error in loader for ${block}`);
|
|
134
|
-
console.error(e);
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
setIsLoadingCount(--isLoadingCountGlobal);
|
|
138
|
-
}, 1000);
|
|
139
|
-
|
|
140
|
-
return loaderResult;
|
|
141
|
-
}}
|
|
166
|
+
storybookComponentDataLoader={async (block, attributes) => await getLoaderResult(block, attributes)}
|
|
142
167
|
onStorybookElementClick={onStorybookElementClick}
|
|
143
168
|
/>
|
|
144
169
|
</div>;
|