@tightknitai/block-kitchen 0.9.2 → 0.9.3
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/helpers.cjs +10 -0
- package/dist/helpers.cjs.map +1 -1
- package/dist/helpers.js +10 -0
- package/dist/helpers.js.map +1 -1
- package/dist/index.cjs +23 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +23 -1
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1887,6 +1887,10 @@ function sanitizeImageSrc(value) {
|
|
|
1887
1887
|
// src/lib/sanitize-blocks.ts
|
|
1888
1888
|
var HREF_KEYS = /* @__PURE__ */ new Set(["url"]);
|
|
1889
1889
|
var IMAGE_KEYS = /* @__PURE__ */ new Set(["image_url"]);
|
|
1890
|
+
var RETRIEVAL_ONLY_KEYS = /* @__PURE__ */ new Map([
|
|
1891
|
+
// Covers both the image block and the image element — both `type: 'image'`.
|
|
1892
|
+
["image", /* @__PURE__ */ new Set(["image_width", "image_height", "image_bytes", "fallback", "is_animated"])]
|
|
1893
|
+
]);
|
|
1890
1894
|
function sanitizeValue(value) {
|
|
1891
1895
|
if (value === null || typeof value !== "object") {
|
|
1892
1896
|
return value;
|
|
@@ -1904,8 +1908,14 @@ function sanitizeValue(value) {
|
|
|
1904
1908
|
return changed ? out : value;
|
|
1905
1909
|
}
|
|
1906
1910
|
const src = value;
|
|
1911
|
+
const dropKeys = typeof src.type === "string" ? RETRIEVAL_ONLY_KEYS.get(src.type) : void 0;
|
|
1907
1912
|
let copy = null;
|
|
1908
1913
|
for (const key of Object.keys(src)) {
|
|
1914
|
+
if (dropKeys?.has(key)) {
|
|
1915
|
+
copy ??= { ...src };
|
|
1916
|
+
delete copy[key];
|
|
1917
|
+
continue;
|
|
1918
|
+
}
|
|
1909
1919
|
const original = src[key];
|
|
1910
1920
|
let next = original;
|
|
1911
1921
|
if (typeof original === "string") {
|
|
@@ -1929,6 +1939,18 @@ function sanitizeValue(value) {
|
|
|
1929
1939
|
function sanitizeBlock(block) {
|
|
1930
1940
|
return sanitizeValue(block);
|
|
1931
1941
|
}
|
|
1942
|
+
function sanitizeBlocks(blocks) {
|
|
1943
|
+
let changed = false;
|
|
1944
|
+
const out = new Array(blocks.length);
|
|
1945
|
+
for (let i = 0; i < blocks.length; i++) {
|
|
1946
|
+
const next = sanitizeBlock(blocks[i]);
|
|
1947
|
+
if (next !== blocks[i]) {
|
|
1948
|
+
changed = true;
|
|
1949
|
+
}
|
|
1950
|
+
out[i] = next;
|
|
1951
|
+
}
|
|
1952
|
+
return changed ? out : blocks;
|
|
1953
|
+
}
|
|
1932
1954
|
|
|
1933
1955
|
// src/lib/to-slack-blocks.ts
|
|
1934
1956
|
function toSlackBlocks(blocks) {
|
|
@@ -2186,7 +2208,7 @@ function useBlockKitchenState({
|
|
|
2186
2208
|
});
|
|
2187
2209
|
}, []);
|
|
2188
2210
|
const replaceAll = useCallback((newBlocks) => {
|
|
2189
|
-
setBlocks(newBlocks.map(wrap));
|
|
2211
|
+
setBlocks(sanitizeBlocks(newBlocks).map(wrap));
|
|
2190
2212
|
}, []);
|
|
2191
2213
|
return {
|
|
2192
2214
|
blocks,
|