UNPKG

2.98 kBJavaScriptView Raw
1"use strict";
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6exports.settings = exports.name = void 0;
7
8var _element = require("@wordpress/element");
9
10var _autop = require("@wordpress/autop");
11
12var _i18n = require("@wordpress/i18n");
13
14var _components = require("@wordpress/components");
15
16var _blockEditor = require("@wordpress/block-editor");
17
18var _compose = require("@wordpress/compose");
19
20/**
21 * WordPress dependencies
22 */
23var name = 'core/shortcode';
24exports.name = name;
25var settings = {
26 title: (0, _i18n.__)('Shortcode'),
27 description: (0, _i18n.__)('Insert additional custom elements with a WordPress shortcode.'),
28 icon: (0, _element.createElement)(_components.SVG, {
29 viewBox: "0 0 24 24",
30 xmlns: "http://www.w3.org/2000/svg"
31 }, (0, _element.createElement)(_components.Path, {
32 d: "M8.5,21.4l1.9,0.5l5.2-19.3l-1.9-0.5L8.5,21.4z M3,19h4v-2H5V7h2V5H3V19z M17,5v2h2v10h-2v2h4V5H17z"
33 })),
34 category: 'widgets',
35 attributes: {
36 text: {
37 type: 'string',
38 source: 'html'
39 }
40 },
41 transforms: {
42 from: [{
43 type: 'shortcode',
44 // Per "Shortcode names should be all lowercase and use all
45 // letters, but numbers and underscores should work fine too.
46 // Be wary of using hyphens (dashes), you'll be better off not
47 // using them." in https://codex.wordpress.org/Shortcode_API
48 // Require that the first character be a letter. This notably
49 // prevents footnote markings ([1]) from being caught as
50 // shortcodes.
51 tag: '[a-z][a-z0-9_-]*',
52 attributes: {
53 text: {
54 type: 'string',
55 shortcode: function shortcode(attrs, _ref) {
56 var content = _ref.content;
57 return (0, _autop.removep)((0, _autop.autop)(content));
58 }
59 }
60 },
61 priority: 20
62 }]
63 },
64 supports: {
65 customClassName: false,
66 className: false,
67 html: false
68 },
69 edit: (0, _compose.withInstanceId)(function (_ref2) {
70 var attributes = _ref2.attributes,
71 setAttributes = _ref2.setAttributes,
72 instanceId = _ref2.instanceId;
73 var inputId = "blocks-shortcode-input-".concat(instanceId);
74 return (0, _element.createElement)("div", {
75 className: "wp-block-shortcode"
76 }, (0, _element.createElement)("label", {
77 htmlFor: inputId
78 }, (0, _element.createElement)(_components.Dashicon, {
79 icon: "shortcode"
80 }), (0, _i18n.__)('Shortcode')), (0, _element.createElement)(_blockEditor.PlainText, {
81 className: "input-control",
82 id: inputId,
83 value: attributes.text,
84 placeholder: (0, _i18n.__)('Write shortcode here…'),
85 onChange: function onChange(text) {
86 return setAttributes({
87 text: text
88 });
89 }
90 }));
91 }),
92 save: function save(_ref3) {
93 var attributes = _ref3.attributes;
94 return (0, _element.createElement)(_element.RawHTML, null, attributes.text);
95 }
96};
97exports.settings = settings;
98//# sourceMappingURL=index.js.map
\No newline at end of file