This commit is contained in:
48
node_modules/decap-cms-core/src/valueObjects/AssetProxy.ts
generated
vendored
Normal file
48
node_modules/decap-cms-core/src/valueObjects/AssetProxy.ts
generated
vendored
Normal file
@@ -0,0 +1,48 @@
|
||||
import type { EntryField } from '../types/redux';
|
||||
|
||||
interface AssetProxyArgs {
|
||||
path: string;
|
||||
url?: string;
|
||||
file?: File;
|
||||
field?: EntryField;
|
||||
}
|
||||
|
||||
export default class AssetProxy {
|
||||
url: string;
|
||||
fileObj?: File;
|
||||
path: string;
|
||||
field?: EntryField;
|
||||
|
||||
constructor({ url, file, path, field }: AssetProxyArgs) {
|
||||
this.url = url ? url : file ? window.URL.createObjectURL(file) : '';
|
||||
this.fileObj = file;
|
||||
this.path = path;
|
||||
this.field = field;
|
||||
}
|
||||
|
||||
toString(): string {
|
||||
return this.url;
|
||||
}
|
||||
|
||||
async toBase64(): Promise<string> {
|
||||
const blob = await fetch(this.url).then(response => response.blob());
|
||||
if (blob.size <= 0) {
|
||||
return '';
|
||||
}
|
||||
const result = await new Promise<string>(resolve => {
|
||||
const fr = new FileReader();
|
||||
fr.onload = (readerEvt): void => {
|
||||
const binaryString = readerEvt.target?.result || '';
|
||||
|
||||
resolve(binaryString.toString().split('base64,')[1]);
|
||||
};
|
||||
fr.readAsDataURL(blob);
|
||||
});
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
export function createAssetProxy({ url, file, path, field }: AssetProxyArgs): AssetProxy {
|
||||
return new AssetProxy({ url, file, path, field });
|
||||
}
|
||||
38
node_modules/decap-cms-core/src/valueObjects/EditorComponent.js
generated
vendored
Normal file
38
node_modules/decap-cms-core/src/valueObjects/EditorComponent.js
generated
vendored
Normal file
@@ -0,0 +1,38 @@
|
||||
import { fromJS } from 'immutable';
|
||||
import { isFunction } from 'lodash';
|
||||
|
||||
const catchesNothing = /.^/;
|
||||
|
||||
function bind(fn) {
|
||||
return isFunction(fn) && fn.bind(null);
|
||||
}
|
||||
|
||||
export default function createEditorComponent(config) {
|
||||
const {
|
||||
id = null,
|
||||
label = 'unnamed component',
|
||||
icon = 'exclamation-triangle',
|
||||
type = 'shortcode',
|
||||
widget = 'object',
|
||||
pattern = catchesNothing,
|
||||
fields = [],
|
||||
fromBlock,
|
||||
toBlock,
|
||||
toPreview,
|
||||
...remainingConfig
|
||||
} = config;
|
||||
|
||||
return {
|
||||
id: id || label.replace(/[^A-Z0-9]+/gi, '_'),
|
||||
label,
|
||||
type,
|
||||
icon,
|
||||
widget,
|
||||
pattern,
|
||||
fromBlock: bind(fromBlock) || (() => ({})),
|
||||
toBlock: bind(toBlock) || (() => 'Plugin'),
|
||||
toPreview: bind(toPreview) || (!widget && (bind(toBlock) || (() => 'Plugin'))),
|
||||
fields: fromJS(fields),
|
||||
...remainingConfig,
|
||||
};
|
||||
}
|
||||
63
node_modules/decap-cms-core/src/valueObjects/Entry.ts
generated
vendored
Normal file
63
node_modules/decap-cms-core/src/valueObjects/Entry.ts
generated
vendored
Normal file
@@ -0,0 +1,63 @@
|
||||
import { isBoolean } from 'lodash';
|
||||
|
||||
import type { MediaFile } from '../backend';
|
||||
|
||||
interface Options {
|
||||
partial?: boolean;
|
||||
raw?: string;
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
data?: any;
|
||||
label?: string | null;
|
||||
isModification?: boolean | null;
|
||||
mediaFiles?: MediaFile[] | null;
|
||||
author?: string;
|
||||
updatedOn?: string;
|
||||
status?: string;
|
||||
meta?: { path?: string };
|
||||
i18n?: {
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
[locale: string]: any;
|
||||
};
|
||||
}
|
||||
|
||||
export interface EntryValue {
|
||||
collection: string;
|
||||
slug: string;
|
||||
path: string;
|
||||
partial: boolean;
|
||||
raw: string;
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
data: any;
|
||||
label: string | null;
|
||||
isModification: boolean | null;
|
||||
mediaFiles: MediaFile[];
|
||||
author: string;
|
||||
updatedOn: string;
|
||||
status?: string;
|
||||
meta: { path?: string };
|
||||
i18n?: {
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
[locale: string]: any;
|
||||
};
|
||||
}
|
||||
|
||||
export function createEntry(collection: string, slug = '', path = '', options: Options = {}) {
|
||||
const returnObj: EntryValue = {
|
||||
collection,
|
||||
slug,
|
||||
path,
|
||||
partial: options.partial || false,
|
||||
raw: options.raw || '',
|
||||
data: options.data || {},
|
||||
label: options.label || null,
|
||||
isModification: isBoolean(options.isModification) ? options.isModification : null,
|
||||
mediaFiles: options.mediaFiles || [],
|
||||
author: options.author || '',
|
||||
updatedOn: options.updatedOn || '',
|
||||
status: options.status || '',
|
||||
meta: options.meta || {},
|
||||
i18n: options.i18n || {},
|
||||
};
|
||||
|
||||
return returnObj;
|
||||
}
|
||||
Reference in New Issue
Block a user