MCPcopy
hub / github.com/tinymce/tinymce / addCustomElement

Function addCustomElement

modules/tinymce/src/core/main/ts/api/html/Schema.ts:207–316  ·  view source on GitHub ↗
(name: string, spec: CustomElementSpec)

Source from the content-addressed store, hash-verified

205 };
206
207 const addCustomElement = (name: string, spec: CustomElementSpec) => {
208 // Flush cached items since we are altering the default maps
209 delete mapCache.text_block_elements;
210 delete mapCache.block_elements;
211
212 const inline = spec.extends ? !isBlock(spec.extends) : false;
213 const cloneName = spec.extends;
214
215 children[name] = cloneName ? children[cloneName] : {};
216 customElementsMap[name] = cloneName ?? name;
217
218 // Treat all custom elements as being non-empty by default
219 nonEmptyElementsMap[name.toUpperCase()] = {};
220 nonEmptyElementsMap[name] = {};
221
222 // If it's not marked as inline then add it to valid block elements
223 if (!inline) {
224 blockElementsMap[name.toUpperCase()] = {};
225 blockElementsMap[name] = {};
226 }
227
228 // Add elements clone if needed
229 if (cloneName && !elements[name] && elements[cloneName]) {
230 const customRule = SchemaUtils.deepCloneElementRule(elements[cloneName]);
231
232 delete customRule.removeEmptyAttrs;
233 delete customRule.removeEmpty;
234
235 elements[name] = customRule;
236 } else {
237 elements[name] = { attributesOrder: [], attributes: { }};
238 }
239
240 // Add custom attributes
241 if (Type.isArray(spec.attributes)) {
242 const processAttrName = (name: string) => {
243 customRule.attributesOrder.push(name);
244 customRule.attributes[name] = {};
245 };
246
247 const customRule = elements[name] ?? {};
248
249 delete customRule.attributesDefault;
250 delete customRule.attributesForced;
251 delete customRule.attributePatterns;
252 delete customRule.attributesRequired;
253
254 customRule.attributesOrder = [];
255 customRule.attributes = {};
256
257 Arr.each(spec.attributes, (attrName) => {
258 const globalAttrs = GlobalAttributesSet.getGlobalAttributeSet(schemaType);
259 ValidChildrenRuleParser.parseValidChild(attrName).each(({ preset, name }) => {
260 if (preset) {
261 if (name === 'global') {
262 Arr.each(globalAttrs, processAttrName);
263 }
264 } else {

Callers 2

addCustomElementsFunction · 0.85

Calls 6

processAttrNameFunction · 0.85
processPresetFunction · 0.85
processNodeNameFunction · 0.85
extendFunction · 0.85
eachMethod · 0.80
isBlockFunction · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…