Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[6.x] Code-split tiptap, codemirror, prosemirror #11469

Merged
merged 3 commits into from
Feb 28, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 21 additions & 10 deletions resources/js/bootstrap/fieldtypes.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { defineAsyncComponent } from 'vue';
import RevealerFieldtype from '../components/fieldtypes/RevealerFieldtype.vue';
import TemplateFieldtype from '../components/fieldtypes/TemplateFieldtype.vue';
import Select from '../components/inputs/Select.vue';
Expand All @@ -12,12 +13,9 @@ import ArrayFieldtype from '../components/fieldtypes/ArrayFieldtype.vue';
import AssetsFieldtype from '../components/fieldtypes/assets/AssetsFieldtype.vue';
import AssetsIndexFieldtype from '../components/fieldtypes/assets/AssetsIndexFieldtype.vue';
import AssetFolderFieldtype from '../components/fieldtypes/AssetFolderFieldtype.vue';
import BardFieldtype from '../components/fieldtypes/bard/BardFieldtype.vue';
import BardSet from '../components/fieldtypes/bard/Set.vue';
import BardButtonsSettingFieldtype from '../components/fieldtypes/bard/BardButtonsSettingFieldtype.vue';
import ButtonGroupFieldtype from '../components/fieldtypes/ButtonGroupFieldtype.vue';
import CheckboxesFieldtype from '../components/fieldtypes/CheckboxesFieldtype.vue';
import CodeFieldtype from '../components/fieldtypes/CodeFieldtype.vue';
import Routes from '../components/collections/Routes.vue';
import TitleFormats from '../components/collections/TitleFormats.vue';
import ColorFieldtype from '../components/fieldtypes/ColorFieldtype.vue';
Expand All @@ -40,7 +38,6 @@ import IntegerFieldtype from '../components/fieldtypes/IntegerFieldtype.vue';
import LinkFieldtype from '../components/fieldtypes/LinkFieldtype.vue';
import ListFieldtype from '../components/fieldtypes/ListFieldtype.vue';
import ListIndexFieldtype from '../components/fieldtypes/ListIndexFieldtype.vue';
import MarkdownFieldtype from '../components/fieldtypes/markdown/MarkdownFieldtype.vue';
import MarkdownButtonsSettingFieldtype from '../components/fieldtypes/markdown/MarkdownButtonsSettingFieldtype.vue';
import RadioFieldtype from '../components/fieldtypes/RadioFieldtype.vue';
import RangeFieldtype from '../components/fieldtypes/RangeFieldtype.vue';
Expand All @@ -61,7 +58,6 @@ import ToggleFieldtype from '../components/fieldtypes/ToggleFieldtype.vue';
import ToggleIndexFieldtype from '../components/fieldtypes/ToggleIndexFieldtype.vue';
import WidthFieldtype from '../components/fieldtypes/WidthFieldtype.vue';
import VideoFieldtype from '../components/fieldtypes/VideoFieldtype.vue';
import YamlFieldtype from '../components/fieldtypes/YamlFieldtype.vue';
import SetPicker from '../components/fieldtypes/replicator/SetPicker.vue';
import SetField from '../components/fieldtypes/replicator/Field.vue';

Expand All @@ -78,12 +74,21 @@ export default function registerFieldtypes(app) {
app.component('assets-fieldtype', AssetsFieldtype);
app.component('assets-fieldtype-index', AssetsIndexFieldtype);
app.component('asset_folder-fieldtype', AssetFolderFieldtype);
app.component('bard-fieldtype', BardFieldtype);
app.component('bard-fieldtype-set', BardSet);
app.component(
'bard-fieldtype',
defineAsyncComponent(() => import('../components/fieldtypes/bard/BardFieldtype.vue')),
);
app.component(
'bard-fieldtype-set',
defineAsyncComponent(() => import('../components/fieldtypes/bard/Set.vue')),
);
app.component('bard_buttons_setting-fieldtype', BardButtonsSettingFieldtype);
app.component('button_group-fieldtype', ButtonGroupFieldtype);
app.component('checkboxes-fieldtype', CheckboxesFieldtype);
app.component('code-fieldtype', CodeFieldtype);
app.component(
'code-fieldtype',
defineAsyncComponent(() => import('../components/fieldtypes/CodeFieldtype.vue')),
);
app.component('collection_routes-fieldtype', Routes);
app.component('collection_title_formats-fieldtype', TitleFormats);
app.component('color-fieldtype', ColorFieldtype);
Expand All @@ -106,7 +111,10 @@ export default function registerFieldtypes(app) {
app.component('link-fieldtype', LinkFieldtype);
app.component('list-fieldtype', ListFieldtype);
app.component('list-fieldtype-index', ListIndexFieldtype);
app.component('markdown-fieldtype', MarkdownFieldtype);
app.component(
'markdown-fieldtype',
defineAsyncComponent(() => import('../components/fieldtypes/markdown/MarkdownFieldtype.vue')),
);
app.component('markdown_buttons_setting-fieldtype', MarkdownButtonsSettingFieldtype);
app.component('radio-fieldtype', RadioFieldtype);
app.component('range-fieldtype', RangeFieldtype);
Expand All @@ -128,7 +136,10 @@ export default function registerFieldtypes(app) {
app.component('toggle-fieldtype-index', ToggleIndexFieldtype);
app.component('width-fieldtype', WidthFieldtype);
app.component('video-fieldtype', VideoFieldtype);
app.component('yaml-fieldtype', YamlFieldtype);
app.component(
'yaml-fieldtype',
defineAsyncComponent(() => import('../components/fieldtypes/YamlFieldtype.vue')),
);
app.component('set-picker', SetPicker);
app.component('set-field', SetField);
app.component('revealer-fieldtype', RevealerFieldtype);
Expand Down
18 changes: 0 additions & 18 deletions resources/js/components/Bard.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
import * as core from '@tiptap/core';
import * as vue3 from '@tiptap/vue-3';
import * as state from '@tiptap/pm/state';
import * as model from '@tiptap/pm/model';
import * as view from '@tiptap/pm/view';

class Bard {
constructor(instance) {
this.instance = instance;
Expand All @@ -23,18 +17,6 @@ class Bard {
buttons(callback) {
this.buttonCallbacks.push(callback);
}

get tiptap() {
return {
core,
vue2,
pm: {
state,
model,
view,
},
};
}
}

export default Bard;
8 changes: 6 additions & 2 deletions resources/js/components/fieldtypes/bard/BardFieldtype.vue
Original file line number Diff line number Diff line change
Expand Up @@ -176,8 +176,10 @@ import { availableButtons, addButtonHtml } from '../bard/buttons';
import readTimeEstimate from 'read-time-estimate';
import { common, createLowlight } from 'lowlight';
import 'highlight.js/styles/github.css';
import importTiptap from '@/util/tiptap.js';

const lowlight = createLowlight(common);
let tiptap = null;

export default {
mixins: [Fieldtype, ManagesSetMeta],
Expand Down Expand Up @@ -379,7 +381,9 @@ export default {
},
},

mounted() {
async mounted() {
tiptap = await importTiptap();

this.initToolbarButtons();
this.initEditor();

Expand Down Expand Up @@ -882,7 +886,7 @@ export default {
}

this.$bard.extensionCallbacks.forEach((callback) => {
let returned = callback({ bard: this });
let returned = callback({ bard: this, tiptap });
exts = exts.concat(Array.isArray(returned) ? returned : [returned]);
});

Expand Down
19 changes: 19 additions & 0 deletions resources/js/util/tiptap.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
export default async function () {
const [core, vue3, state, model, view] = await Promise.all([
import('@tiptap/core'),
import('@tiptap/vue-3'),
import('@tiptap/pm/state'),
import('@tiptap/pm/model'),
import('@tiptap/pm/view'),
]);

return {
core,
vue3,
pm: {
state,
model,
view,
},
};
}
Loading